Skip to content

Commit

Permalink
Merge pull request #12 from whyrusleeping/feat/supporrt-i64-map
Browse files Browse the repository at this point in the history
int64 support in map encoders
  • Loading branch information
whyrusleeping authored Feb 22, 2020
2 parents 03c9665 + 80352c7 commit a0cf070
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
12 changes: 9 additions & 3 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (f Field) ElemName() string {
return typeName(f.Pkg, f.Type.Elem())
}


type GenTypeInfo struct {
Name string
Fields []Field
Expand Down Expand Up @@ -592,8 +591,7 @@ 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 @@ -1010,6 +1008,10 @@ func emitCborMarshalStructMap(w io.Writer, gti *GenTypeInfo) error {
if err := emitCborMarshalUint64Field(w, f); err != nil {
return err
}
case reflect.Int64:
if err := emitCborMarshalInt64Field(w, f); err != nil {
return err
}
case reflect.Uint8:
if err := emitCborMarshalUint8Field(w, f); err != nil {
return err
Expand Down Expand Up @@ -1097,6 +1099,10 @@ func (t *{{ .Name}}) UnmarshalCBOR(r io.Reader) error {
if err := emitCborUnmarshalUint64Field(w, f); err != nil {
return err
}
case reflect.Int64:
if err := emitCborUnmarshalInt64Field(w, f); err != nil {
return err
}
case reflect.Uint8:
if err := emitCborUnmarshalUint8Field(w, f); err != nil {
return err
Expand Down
50 changes: 49 additions & 1 deletion testing/cbor_map_gen.go

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

11 changes: 6 additions & 5 deletions testing/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type SimpleTypeTwo struct {
}

type SimpleTypeTree struct {
Stuff *SimpleTypeTree
Stufff *SimpleTypeTwo
Others []uint64
Test [][]byte
Dog string
Stuff *SimpleTypeTree
Stufff *SimpleTypeTwo
Others []uint64
Test [][]byte
SixtyThreeBitIntegerWithASignBit int64
Dog string
}

0 comments on commit a0cf070

Please sign in to comment.