| 16 | } |
| 17 | |
| 18 | func (dec *Decoder) decodeInterface(i *interface{}) error { |
| 19 | start, end, err := dec.getObject() |
| 20 | if err != nil { |
| 21 | dec.cursor = start |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | // if start & end are equal the object is a null, don't unmarshal |
| 26 | if start == end { |
| 27 | return nil |
| 28 | } |
| 29 | |
| 30 | object := dec.data[start:end] |
| 31 | if err = json.Unmarshal(object, i); err != nil { |
| 32 | return err |
| 33 | } |
| 34 | |
| 35 | dec.cursor = end |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | // @afiune Maybe return the type as well? |
| 40 | func (dec *Decoder) getObject() (start int, end int, err error) { |