(bz []byte, v interface{})
| 15 | } |
| 16 | |
| 17 | func decode(bz []byte, v interface{}) error { |
| 18 | if len(bz) == 0 { |
| 19 | return errors.New("cannot decode empty bytes") |
| 20 | } |
| 21 | |
| 22 | rv := reflect.ValueOf(v) |
| 23 | if rv.Kind() != reflect.Ptr { |
| 24 | return errors.New("must decode into a pointer") |
| 25 | } |
| 26 | rv = rv.Elem() |
| 27 | |
| 28 | // If this is a registered type, defer to interface decoder regardless of whether the input is |
| 29 | // an interface or a bare value. This retains Amino's behavior, but is inconsistent with |
| 30 | // behavior in structs where an interface field will get the type wrapper while a bare value |
| 31 | // field will not. |
| 32 | if typeRegistry.name(rv.Type()) != "" { |
| 33 | return decodeReflectInterface(bz, rv) |
| 34 | } |
| 35 | |
| 36 | return decodeReflect(bz, rv) |
| 37 | } |
| 38 | |
| 39 | func decodeReflect(bz []byte, rv reflect.Value) error { |
| 40 | if !rv.CanAddr() { |
no test coverage detected