(v interface{})
| 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 |
| 72 | dec.arrayIndex = 0 |
| 73 | defer func() { |
| 74 | dec.arrayIndex = lastArrayIndex |
| 75 | }() |
| 76 | vv := reflect.ValueOf(v) |
| 77 | vvt := vv.Type() |
| 78 | if vvt.Kind() != reflect.Ptr || vvt.Elem().Kind() != reflect.Ptr { |
| 79 | dec.err = ErrUnmarshalPtrExpected |
| 80 | return 0, dec.err |
| 81 | } |
| 82 | // not an array not an error, but do not know what to do |
| 83 | // do not check syntax |
| 84 | for ; dec.cursor < dec.length || dec.read(); dec.cursor++ { |
| 85 | switch dec.data[dec.cursor] { |
| 86 | case ' ', '\n', '\t', '\r', ',': |
| 87 | continue |
| 88 | case '[': |
| 89 | dec.cursor = dec.cursor + 1 |
| 90 | // create our new type |
| 91 | elt := vv.Elem() |
| 92 | n := reflect.New(elt.Type().Elem()) |
| 93 | var arr UnmarshalerJSONArray |
| 94 | var ok bool |
| 95 | if arr, ok = n.Interface().(UnmarshalerJSONArray); !ok { |
| 96 | dec.err = dec.makeInvalidUnmarshalErr((UnmarshalerJSONArray)(nil)) |
| 97 | return 0, dec.err |
| 98 | } |
| 99 | // array is open, char is not space start readings |
| 100 | for dec.nextChar() != 0 { |
| 101 | // closing array |
| 102 | if dec.data[dec.cursor] == ']' { |
| 103 | elt.Set(n) |
| 104 | dec.cursor = dec.cursor + 1 |
| 105 | return dec.cursor, nil |
| 106 | } |
| 107 | // calling unmarshall function for each element of the slice |
| 108 | err := arr.UnmarshalJSONArray(dec) |
| 109 | if err != nil { |
| 110 | return 0, err |
| 111 | } |
| 112 | dec.arrayIndex++ |
| 113 | } |
| 114 | return 0, dec.raiseInvalidJSONErr(dec.cursor) |
| 115 | case 'n': |
| 116 | // is null |
| 117 | dec.cursor++ |
| 118 | err := dec.assertNull() |
| 119 | if err != nil { |
| 120 | return 0, err |
| 121 | } |
| 122 | return dec.cursor, nil |
| 123 | case '{', '"', 'f', 't', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': |
| 124 | // can't unmarshall to struct |
| 125 | // we skip array and set Error |
| 126 | dec.err = dec.makeInvalidUnmarshalErr((UnmarshalerJSONArray)(nil)) |
no test coverage detected