MCPcopy
hub / github.com/openai/openai-go / Decode

Method Decode

internal/encoding/json/stream.go:48–78  ·  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 any)

Source from the content-addressed store, hash-verified

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

Callers 4

TokenMethod · 0.95
GetTokenMethod · 0.80
literalStoreMethod · 0.80
ExecuteMethod · 0.80

Implementers 1

eventStreamDecoderpackages/ssestream/ssestream.go

Calls 7

tokenPrepareForDecodeMethod · 0.95
tokenValueAllowedMethod · 0.95
InputOffsetMethod · 0.95
readValueMethod · 0.95
tokenValueEndMethod · 0.95
initMethod · 0.80
unmarshalMethod · 0.45

Tested by

no test coverage detected