Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uint64 typed array gen #10

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (f Field) TypeName() string {
return typeName(f.Pkg, f.Type)
}

func (f Field) ElemName() string {
return typeName(f.Pkg, f.Type.Elem())
}


type GenTypeInfo struct {
Name string
Fields []Field
Expand Down Expand Up @@ -377,7 +382,7 @@ func emitCborMarshalSliceField(w io.Writer, f Field) error {
}
case reflect.Uint64:
err := doTemplate(w, f, `
if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, v); err != nil {
if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil {
return err
}
`)
Expand Down Expand Up @@ -584,7 +589,8 @@ func emitCborUnmarshalStructField(w io.Writer, f Field) error {
}
}

func emitCborUnmarshalInt64Field(w io.Writer, f Field) error {
func
emitCborUnmarshalInt64Field(w io.Writer, f Field) error {
return doTemplate(w, f, `{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
Expand Down Expand Up @@ -839,7 +845,7 @@ func emitCborUnmarshalSliceField(w io.Writer, f Field) error {
return xerrors.Errorf("value read for array {{ .Name }} was not a uint, instead got %d", maj)
}

{{ .Name }}[{{ .IterLabel}}] = val
{{ .Name }}[{{ .IterLabel}}] = {{ .ElemName }}(val)
`)
if err != nil {
return err
Expand Down
57 changes: 51 additions & 6 deletions testing/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions testing/cbor_map_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions testing/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package testing

type NaturalNumber uint64

type SignedArray struct {
Signed []uint64
}
Expand All @@ -17,6 +19,7 @@ type SimpleTypeTwo struct {
SignedOthers []int64
Test [][]byte
Dog string
Numbers []NaturalNumber
}

type SimpleTypeTree struct {
Expand Down