MCPcopy Create free account
hub / github.com/blues/note / Decode

Method Decode

jsonxt/stream.go:53–83  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

51// See the documentation for Unmarshal for details about
52// the conversion of JSON into a Go value.
53func (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.

Callers 3

TokenMethod · 0.95
eventBulkFunction · 0.45
literalStoreMethod · 0.45

Calls 7

tokenPrepareForDecodeMethod · 0.95
tokenValueAllowedMethod · 0.95
offsetMethod · 0.95
readValueMethod · 0.95
tokenValueEndMethod · 0.95
initMethod · 0.80
unmarshalMethod · 0.80

Tested by

no test coverage detected