(w io.Writer, v interface{})
| 43 | } |
| 44 | |
| 45 | func encode(w io.Writer, v interface{}) error { |
| 46 | // Bare nil values can't be reflected, so we must handle them here. |
| 47 | if v == nil { |
| 48 | return writeStr(w, "null") |
| 49 | } |
| 50 | rv := reflect.ValueOf(v) |
| 51 | |
| 52 | // If this is a registered type, defer to interface encoder regardless of whether the input is |
| 53 | // an interface or a bare value. This retains Amino's behavior, but is inconsistent with |
| 54 | // behavior in structs where an interface field will get the type wrapper while a bare value |
| 55 | // field will not. |
| 56 | if typeRegistry.name(rv.Type()) != "" { |
| 57 | return encodeReflectInterface(w, rv) |
| 58 | } |
| 59 | |
| 60 | return encodeReflect(w, rv) |
| 61 | } |
| 62 | |
| 63 | func encodeReflect(w io.Writer, rv reflect.Value) error { |
| 64 | if !rv.IsValid() { |
no test coverage detected