(e jEntry, v []byte)
| 118 | } |
| 119 | |
| 120 | func newEncoded(e jEntry, v []byte) (JSON, error) { |
| 121 | var typ Type |
| 122 | var containerLen int |
| 123 | switch e.typCode { |
| 124 | case stringTag: |
| 125 | typ = StringJSONType |
| 126 | case numberTag: |
| 127 | typ = NumberJSONType |
| 128 | case nullTag: // Don't bother with returning a jsonEncoded for the singleton types. |
| 129 | return NullJSONValue, nil |
| 130 | case falseTag: |
| 131 | return FalseJSONValue, nil |
| 132 | case trueTag: |
| 133 | return TrueJSONValue, nil |
| 134 | case containerTag: |
| 135 | // Every container is prefixed with its uint32 container header. |
| 136 | containerHeader, err := getUint32At(v, 0) |
| 137 | if err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | switch containerHeader & containerHeaderTypeMask { |
| 141 | case arrayContainerTag: |
| 142 | typ = ArrayJSONType |
| 143 | case objectContainerTag: |
| 144 | typ = ObjectJSONType |
| 145 | } |
| 146 | containerLen = int(containerHeader & containerHeaderLenMask) |
| 147 | } |
| 148 | |
| 149 | return &jsonEncoded{ |
| 150 | typ: typ, |
| 151 | containerLen: containerLen, |
| 152 | value: v, |
| 153 | }, nil |
| 154 | } |
| 155 | |
| 156 | func getUint32At(v []byte, idx int) (uint32, error) { |
| 157 | if idx+4 > len(v) { |
no test coverage detected
searching dependent graphs…