Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v. See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
(v interface{})
| 51 | // See the documentation for Unmarshal for details about |
| 52 | // the conversion of JSON into a Go value. |
| 53 | func (dec *Decoder) Decode(v interface{}) error { |
| 54 | if dec.err != nil { |
| 55 | return dec.err |
| 56 | } |
| 57 | |
| 58 | if err := dec.tokenPrepareForDecode(); err != nil { |
| 59 | return err |
| 60 | } |
| 61 | |
| 62 | if !dec.tokenValueAllowed() { |
| 63 | return &SyntaxError{msg: "not at beginning of value", Offset: dec.offset()} |
| 64 | } |
| 65 | |
| 66 | // Read whole value into buffer. |
| 67 | n, err := dec.readValue() |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | dec.d.init(dec.buf[dec.scanp : dec.scanp+n]) |
| 72 | dec.scanp += n |
| 73 | |
| 74 | // Don't save err from unmarshal into dec.err: |
| 75 | // the connection is still usable since we read a complete JSON |
| 76 | // object from it before the error happened. |
| 77 | err = dec.d.unmarshal(v) |
| 78 | |
| 79 | // fixup token streaming state |
| 80 | dec.tokenValueEnd() |
| 81 | |
| 82 | return err |
| 83 | } |
| 84 | |
| 85 | // Buffered returns a reader of the data remaining in the Decoder's |
| 86 | // buffer. The reader is valid until the next call to Decode. |
no test coverage detected