Skip to content

Commit

Permalink
some minor touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Nov 11, 2019
1 parent c66f728 commit 1b3315e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
12 changes: 7 additions & 5 deletions amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,15 @@ func (cdc *Codec) MarshalBinaryLengthPrefixed(o interface{}) ([]byte, error) {
// MarshalBinaryLengthPrefixedWriter writes the bytes as would be returned from
// MarshalBinaryLengthPrefixed to the writer w.
func (cdc *Codec) MarshalBinaryLengthPrefixedWriter(w io.Writer, o interface{}) (n int64, err error) {
// var bz, _n = []byte(nil), int(0)
bz, err := cdc.MarshalBinaryLengthPrefixed(o)
var (
bz []byte
_n int
)
bz, err = cdc.MarshalBinaryLengthPrefixed(o)
if err != nil {
return 0, err
}
_n, err := w.Write(bz) // TODO: handle overflow in 32-bit systems.
_n, err = w.Write(bz) // TODO: handle overflow in 32-bit systems.
n = int64(_n)
return
}
Expand Down Expand Up @@ -419,7 +422,6 @@ func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error {

// Decode contents into rv.
n, err := cdc.decodeReflectBinary(bz, info, rv, FieldOptions{BinFieldNum: 1}, bare)
fmt.Println("I am here")
if err != nil {
return fmt.Errorf(
"unmarshal to %v failed after %d bytes (%v): %X",
Expand Down Expand Up @@ -462,7 +464,7 @@ func isPointerToStructOrToRepeatedStruct(rv reflect.Value, rt reflect.Type) bool
}

if isPtr && isNil {
rt = derefType(rt)
rt := derefType(rt)
if rt.Kind() == reflect.Struct {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions binary-decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const (
func (cdc *Codec) decodeReflectBinary(bz []byte, info *TypeInfo,
rv reflect.Value, fopts FieldOptions, bare bool) (n int, err error) {

fmt.Println(bz, "bz")
if !rv.CanAddr() {
fmt.Println(bz, "bz")
panic("rv not addressable")
}
if info.Type.Kind() == reflect.Interface && rv.Kind() == reflect.Ptr {
Expand Down Expand Up @@ -62,7 +62,7 @@ func (cdc *Codec) decodeReflectBinary(bz []byte, info *TypeInfo,
// Handle override if a pointer to rv implements UnmarshalAmino.
if info.IsAminoUnmarshaler {
// First, decode repr instance from bytes.
rrv := reflect.New(info.AminoUnmarshalReprType)
rrv := reflect.New(info.AminoUnmarshalReprType).Elem()
var rinfo *TypeInfo
rinfo, err = cdc.getTypeInfoWlock(info.AminoUnmarshalReprType)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ func decodeSeconds(bz *[]byte) (int64, int, error) {
switch {
case fieldNum == 1 && typ == Typ3Varint:
slide(bz, &n, _n)
// var _n int
sec, _n, err := DecodeUvarint(*bz)
if slide(bz, &n, _n) && err != nil {
return 0, n, err
Expand Down Expand Up @@ -263,7 +262,6 @@ func decodeNanos(bz *[]byte, n *int) (int32, error) {
}
if fieldNum == 2 && typ == Typ3Varint {
slide(bz, n, _n)
// var _n int
nsec, _n, err := DecodeUvarint(*bz)
if slide(bz, n, _n) && err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion json-decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (cdc *Codec) decodeReflectJSON(bz []byte, info *TypeInfo, rv reflect.Value,
// Handle override if a pointer to rv implements UnmarshalAmino.
if info.IsAminoUnmarshaler {
// First, decode repr instance from bytes.
rrv := reflect.New(info.AminoUnmarshalReprType)
rrv := reflect.New(info.AminoUnmarshalReprType).Elem()
var rinfo *TypeInfo
rinfo, err = cdc.getTypeInfoWlock(info.AminoUnmarshalReprType)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions repr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ func TestMarshalAminoBinary(t *testing.T) {
t.Logf("bz %#v", bz)

var f2 Foo
fmt.Println(bz)
err = cdc.UnmarshalBinaryLengthPrefixed(bz, &f2)
fmt.Println(f2, "me me")
assert.NoError(t, err)

assert.Equal(t, f, f2)
Expand All @@ -82,7 +80,7 @@ func TestMarshalAminoJSON(t *testing.T) {
cdc.RegisterConcrete(([]*Foo)(nil), "[]*Foo", nil)

var f = Foo{
A: "K",
a: "K",
b: 2,
c: []*Foo{nil, nil, nil},
D: "J",
Expand Down

0 comments on commit 1b3315e

Please sign in to comment.