(arr UnmarshalerJSONArray)
| 16 | return err |
| 17 | } |
| 18 | func (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 | } |
| 69 | func (dec *Decoder) decodeArrayNull(v interface{}) (int, error) { |
| 70 | // remember last array index in case of nested arrays |
| 71 | lastArrayIndex := dec.arrayIndex |
no test coverage detected