github.com/Finschia/ostracon@v1.1.5/types/encoding_helper.go (about) 1 package types 2 3 import ( 4 gogotypes "github.com/gogo/protobuf/types" 5 6 "github.com/Finschia/ostracon/libs/bytes" 7 ) 8 9 // cdcEncode returns nil if the input is nil, otherwise returns 10 // proto.Marshal(<type>Value{Value: item}) 11 func cdcEncode(item interface{}) []byte { 12 if item != nil && !isTypedNil(item) && !isEmpty(item) { 13 switch item := item.(type) { 14 case string: 15 i := gogotypes.StringValue{ 16 Value: item, 17 } 18 bz, err := i.Marshal() 19 if err != nil { 20 return nil 21 } 22 return bz 23 case int32: 24 i := gogotypes.Int32Value{ 25 Value: item, 26 } 27 bz, err := i.Marshal() 28 if err != nil { 29 return nil 30 } 31 return bz 32 case int64: 33 i := gogotypes.Int64Value{ 34 Value: item, 35 } 36 bz, err := i.Marshal() 37 if err != nil { 38 return nil 39 } 40 return bz 41 case bytes.HexBytes: 42 i := gogotypes.BytesValue{ 43 Value: item, 44 } 45 bz, err := i.Marshal() 46 if err != nil { 47 return nil 48 } 49 return bz 50 default: 51 // REVIEW: 🏺This function has been modified in v0.34 to encode only certain primitive types. Should we panic? 52 return nil 53 } 54 } 55 56 return nil 57 }