@@ -32,16 +32,16 @@ func init() {
3232 }
3333}
3434
35- func MarshalBinary (o interface {}) ([]byte , error ) {
36- return gcdc .MarshalBinary (o )
35+ func MarshalBinaryLengthPrefixed (o interface {}) ([]byte , error ) {
36+ return gcdc .MarshalBinaryLengthPrefixed (o )
3737}
3838
39- func MarshalBinaryWriter (w io.Writer , o interface {}) (n int64 , err error ) {
40- return gcdc .MarshalBinaryWriter (w , o )
39+ func MarshalBinaryLengthPrefixedWriter (w io.Writer , o interface {}) (n int64 , err error ) {
40+ return gcdc .MarshalBinaryLengthPrefixedWriter (w , o )
4141}
4242
43- func MustMarshalBinary (o interface {}) []byte {
44- return gcdc .MustMarshalBinary (o )
43+ func MustMarshalBinaryLengthPrefixed (o interface {}) []byte {
44+ return gcdc .MustMarshalBinaryLengthPrefixed (o )
4545}
4646
4747func MarshalBinaryBare (o interface {}) ([]byte , error ) {
@@ -52,16 +52,16 @@ func MustMarshalBinaryBare(o interface{}) []byte {
5252 return gcdc .MustMarshalBinaryBare (o )
5353}
5454
55- func UnmarshalBinary (bz []byte , ptr interface {}) error {
56- return gcdc .UnmarshalBinary (bz , ptr )
55+ func UnmarshalBinaryLengthPrefixed (bz []byte , ptr interface {}) error {
56+ return gcdc .UnmarshalBinaryLengthPrefixedBinary (bz , ptr )
5757}
5858
59- func UnmarshalBinaryReader (r io.Reader , ptr interface {}, maxSize int64 ) (n int64 , err error ) {
60- return gcdc .UnmarshalBinaryReader (r , ptr , maxSize )
59+ func UnmarshalBinaryLengthPrefixedReader (r io.Reader , ptr interface {}, maxSize int64 ) (n int64 , err error ) {
60+ return gcdc .UnmarshalBinaryLengthPrefixedReader (r , ptr , maxSize )
6161}
6262
63- func MustUnmarshalBinary (bz []byte , ptr interface {}) {
64- gcdc .MustUnmarshalBinary (bz , ptr )
63+ func MustUnmarshalBinaryLengthPrefixed (bz []byte , ptr interface {}) {
64+ gcdc .MustUnmarshalBinaryLengthPrefixed (bz , ptr )
6565}
6666
6767func UnmarshalBinaryBare (bz []byte , ptr interface {}) error {
@@ -127,14 +127,14 @@ func (typ Typ3) String() string {
127127//----------------------------------------
128128// *Codec methods
129129
130- // MarshalBinary encodes the object o according to the Amino spec,
130+ // MarshalBinaryLengthPrefixed encodes the object o according to the Amino spec,
131131// but prefixed by a uvarint encoding of the object to encode.
132132// Use MarshalBinaryBare if you don't want byte-length prefixing.
133133//
134- // For consistency, MarshalBinary will first dereference pointers
135- // before encoding. MarshalBinary will panic if o is a nil-pointer,
134+ // For consistency, MarshalBinaryLengthPrefixed will first dereference pointers
135+ // before encoding. MarshalBinaryLengthPrefixed will panic if o is a nil-pointer,
136136// or if o is invalid.
137- func (cdc * Codec ) MarshalBinary (o interface {}) ([]byte , error ) {
137+ func (cdc * Codec ) MarshalBinaryLengthPrefixed (o interface {}) ([]byte , error ) {
138138
139139 // Write the bytes here.
140140 var buf = new (bytes.Buffer )
@@ -160,11 +160,11 @@ func (cdc *Codec) MarshalBinary(o interface{}) ([]byte, error) {
160160 return buf .Bytes (), nil
161161}
162162
163- // MarshalBinaryWriter writes the bytes as would be returned from
164- // MarshalBinary to the writer w.
165- func (cdc * Codec ) MarshalBinaryWriter (w io.Writer , o interface {}) (n int64 , err error ) {
163+ // MarshalBinaryLengthPrefixedWriter writes the bytes as would be returned from
164+ // MarshalBinaryLengthPrefixed to the writer w.
165+ func (cdc * Codec ) MarshalBinaryLengthPrefixedWriter (w io.Writer , o interface {}) (n int64 , err error ) {
166166 var bz , _n = []byte (nil ), int (0 )
167- bz , err = cdc .MarshalBinary (o )
167+ bz , err = cdc .MarshalBinaryLengthPrefixed (o )
168168 if err != nil {
169169 return 0 , err
170170 }
@@ -174,8 +174,8 @@ func (cdc *Codec) MarshalBinaryWriter(w io.Writer, o interface{}) (n int64, err
174174}
175175
176176// Panics if error.
177- func (cdc * Codec ) MustMarshalBinary (o interface {}) []byte {
178- bz , err := cdc .MarshalBinary (o )
177+ func (cdc * Codec ) MustMarshalBinaryLengthPrefixed (o interface {}) []byte {
178+ bz , err := cdc .MarshalBinaryLengthPrefixed (o )
179179 if err != nil {
180180 panic (err )
181181 }
@@ -191,8 +191,8 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) {
191191 var rv , _ , isNilPtr = derefPointers (reflect .ValueOf (o ))
192192 if isNilPtr {
193193 // NOTE: You can still do so by calling
194- // `.MarshalBinary (struct{ *SomeType })` or so on.
195- panic ("MarshalBinary cannot marshal a nil pointer directly. Try wrapping in a struct?" )
194+ // `.MarshalBinaryLengthPrefixed (struct{ *SomeType })` or so on.
195+ panic ("MarshalBinaryBare cannot marshal a nil pointer directly. Try wrapping in a struct?" )
196196 }
197197
198198 // Encode Amino:binary bytes.
@@ -228,11 +228,11 @@ func (cdc *Codec) MustMarshalBinaryBare(o interface{}) []byte {
228228}
229229
230230// Like UnmarshalBinaryBare, but will first decode the byte-length prefix.
231- // UnmarshalBinary will panic if ptr is a nil-pointer.
231+ // UnmarshalBinaryLengthPrefixedBinary will panic if ptr is a nil-pointer.
232232// Returns an error if not all of bz is consumed.
233- func (cdc * Codec ) UnmarshalBinary (bz []byte , ptr interface {}) error {
233+ func (cdc * Codec ) UnmarshalBinaryLengthPrefixedBinary (bz []byte , ptr interface {}) error {
234234 if len (bz ) == 0 {
235- return errors .New ("UnmarshalBinary cannot decode empty bytes" )
235+ return errors .New ("UnmarshalBinaryLengthPrefixedBinary cannot decode empty bytes" )
236236 }
237237
238238 // Read byte-length prefix.
@@ -241,10 +241,10 @@ func (cdc *Codec) UnmarshalBinary(bz []byte, ptr interface{}) error {
241241 return fmt .Errorf ("Error reading msg byte-length prefix: got code %v" , n )
242242 }
243243 if u64 > uint64 (len (bz )- n ) {
244- return fmt .Errorf ("Not enough bytes to read in UnmarshalBinary , want %v more bytes but only have %v" ,
244+ return fmt .Errorf ("Not enough bytes to read in UnmarshalBinaryLengthPrefixedBinary , want %v more bytes but only have %v" ,
245245 u64 , len (bz )- n )
246246 } else if u64 < uint64 (len (bz )- n ) {
247- return fmt .Errorf ("Bytes left over in UnmarshalBinary , should read %v more bytes but have %v" ,
247+ return fmt .Errorf ("Bytes left over in UnmarshalBinaryLengthPrefixedBinary , should read %v more bytes but have %v" ,
248248 u64 , len (bz )- n )
249249 }
250250 bz = bz [n :]
@@ -254,9 +254,9 @@ func (cdc *Codec) UnmarshalBinary(bz []byte, ptr interface{}) error {
254254}
255255
256256// Like UnmarshalBinaryBare, but will first read the byte-length prefix.
257- // UnmarshalBinaryReader will panic if ptr is a nil-pointer.
257+ // UnmarshalBinaryLengthPrefixedReader will panic if ptr is a nil-pointer.
258258// If maxSize is 0, there is no limit (not recommended).
259- func (cdc * Codec ) UnmarshalBinaryReader (r io.Reader , ptr interface {}, maxSize int64 ) (n int64 , err error ) {
259+ func (cdc * Codec ) UnmarshalBinaryLengthPrefixedReader (r io.Reader , ptr interface {}, maxSize int64 ) (n int64 , err error ) {
260260 if maxSize < 0 {
261261 panic ("maxSize cannot be negative." )
262262 }
@@ -310,8 +310,8 @@ func (cdc *Codec) UnmarshalBinaryReader(r io.Reader, ptr interface{}, maxSize in
310310}
311311
312312// Panics if error.
313- func (cdc * Codec ) MustUnmarshalBinary (bz []byte , ptr interface {}) {
314- err := cdc .UnmarshalBinary (bz , ptr )
313+ func (cdc * Codec ) MustUnmarshalBinaryLengthPrefixed (bz []byte , ptr interface {}) {
314+ err := cdc .UnmarshalBinaryLengthPrefixedBinary (bz , ptr )
315315 if err != nil {
316316 panic (err )
317317 }
@@ -399,6 +399,15 @@ func (cdc *Codec) MarshalJSON(o interface{}) ([]byte, error) {
399399 return w .Bytes (), nil
400400}
401401
402+ // MustMarshalJSON panics if an error occurs. Besides tha behaves exactly like MarshalJSON.
403+ func (cdc * Codec ) MustMarshalJSON (o interface {}) []byte {
404+ bz , err := cdc .MarshalJSON (o )
405+ if err != nil {
406+ panic (err )
407+ }
408+ return bz
409+ }
410+
402411func (cdc * Codec ) UnmarshalJSON (bz []byte , ptr interface {}) error {
403412 if len (bz ) == 0 {
404413 return errors .New ("UnmarshalJSON cannot decode empty bytes" )
@@ -430,6 +439,13 @@ func (cdc *Codec) UnmarshalJSON(bz []byte, ptr interface{}) error {
430439 return cdc .decodeReflectJSON (bz , info , rv , FieldOptions {})
431440}
432441
442+ // MustUnmarshalJSON panics if an error occurs. Besides tha behaves exactly like UnmarshalJSON.
443+ func (cdc * Codec ) MustUnmarshalJSON (bz []byte , ptr interface {}) {
444+ if err := cdc .UnmarshalJSON (bz , ptr ); err != nil {
445+ panic (err )
446+ }
447+ }
448+
433449// MarshalJSONIndent calls json.Indent on the output of cdc.MarshalJSON
434450// using the given prefix and indent string.
435451func (cdc * Codec ) MarshalJSONIndent (o interface {}, prefix , indent string ) ([]byte , error ) {
0 commit comments