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

Method readValue

jsonxt/stream.go:93–142  ·  view source on GitHub ↗

readValue reads a JSON value into dec.buf. It returns the length of the encoding.

()

Source from the content-addressed store, hash-verified

91// readValue reads a JSON value into dec.buf.
92// It returns the length of the encoding.
93func (dec *Decoder) readValue() (int, error) {
94 dec.scan.reset()
95
96 scanp := dec.scanp
97 var err error
98Input:
99 for {
100 // Look in the buffer for a new value.
101 for i, c := range dec.buf[scanp:] {
102 dec.scan.bytes++
103 switch dec.scan.step(&dec.scan, c) {
104 case scanEnd:
105 scanp += i
106 break Input
107 case scanEndObject, scanEndArray:
108 // scanEnd is delayed one byte.
109 // We might block trying to get that byte from src,
110 // so instead invent a space byte.
111 if stateEndValue(&dec.scan, ' ') == scanEnd {
112 scanp += i + 1
113 break Input
114 }
115 case scanError:
116 dec.err = dec.scan.err
117 return 0, dec.scan.err
118 }
119 }
120 scanp = len(dec.buf)
121
122 // Did the last read have an error?
123 // Delayed until now to allow buffer scan.
124 if err != nil {
125 if err == io.EOF {
126 if dec.scan.step(&dec.scan, ' ') == scanEnd {
127 break Input
128 }
129 if nonSpace(dec.buf) {
130 err = io.ErrUnexpectedEOF
131 }
132 }
133 dec.err = err
134 return 0, err
135 }
136
137 n := scanp - dec.scanp
138 err = dec.refill()
139 scanp = dec.scanp + n
140 }
141 return scanp - dec.scanp, nil
142}
143
144func (dec *Decoder) refill() error {
145 // Make room to read more into the buffer.

Callers 1

DecodeMethod · 0.95

Calls 4

refillMethod · 0.95
stateEndValueFunction · 0.85
nonSpaceFunction · 0.85
resetMethod · 0.80

Tested by

no test coverage detected