MCPcopy Create free account
hub / github.com/francoispqt/gojay / decodeArray

Method decodeArray

decode_array.go:18–68  ·  view source on GitHub ↗
(arr UnmarshalerJSONArray)

Source from the content-addressed store, hash-verified

16 return err
17}
18func (dec *Decoder) decodeArray(arr UnmarshalerJSONArray) (int, error) {
19 // remember last array index in case of nested arrays
20 lastArrayIndex := dec.arrayIndex
21 dec.arrayIndex = 0
22 defer func() {
23 dec.arrayIndex = lastArrayIndex
24 }()
25 for ; dec.cursor < dec.length || dec.read(); dec.cursor++ {
26 switch dec.data[dec.cursor] {
27 case ' ', '\n', '\t', '\r', ',':
28 continue
29 case '[':
30 dec.cursor = dec.cursor + 1
31 // array is open, char is not space start readings
32 for dec.nextChar() != 0 {
33 // closing array
34 if dec.data[dec.cursor] == ']' {
35 dec.cursor = dec.cursor + 1
36 return dec.cursor, nil
37 }
38 // calling unmarshall function for each element of the slice
39 err := arr.UnmarshalJSONArray(dec)
40 if err != nil {
41 return 0, err
42 }
43 dec.arrayIndex++
44 }
45 return 0, dec.raiseInvalidJSONErr(dec.cursor)
46 case 'n':
47 // is null
48 dec.cursor++
49 err := dec.assertNull()
50 if err != nil {
51 return 0, err
52 }
53 return dec.cursor, nil
54 case '{', '"', 'f', 't', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
55 // can't unmarshall to struct
56 // we skip array and set Error
57 dec.err = dec.makeInvalidUnmarshalErr(arr)
58 err := dec.skipData()
59 if err != nil {
60 return 0, err
61 }
62 return dec.cursor, nil
63 default:
64 return 0, dec.raiseInvalidJSONErr(dec.cursor)
65 }
66 }
67 return 0, dec.raiseInvalidJSONErr(dec.cursor)
68}
69func (dec *Decoder) decodeArrayNull(v interface{}) (int, error) {
70 // remember last array index in case of nested arrays
71 lastArrayIndex := dec.arrayIndex

Callers 7

DecodeArrayMethod · 0.95
ArrayMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalFunction · 0.95
DecodeMethod · 0.95
UnmarshalJSONArrayMethod · 0.80
UnmarshalJSONArrayFunction · 0.80

Calls 7

readMethod · 0.95
nextCharMethod · 0.95
raiseInvalidJSONErrMethod · 0.95
assertNullMethod · 0.95
skipDataMethod · 0.95
UnmarshalJSONArrayMethod · 0.65

Tested by

no test coverage detected