(e jEntry, v []byte)
| 132 | } |
| 133 | |
| 134 | func newEncoded(e jEntry, v []byte) (JSON, error) { |
| 135 | var typ Type |
| 136 | var containerLen int |
| 137 | switch e.typCode { |
| 138 | case stringTag: |
| 139 | typ = StringJSONType |
| 140 | case numberTag: |
| 141 | typ = NumberJSONType |
| 142 | case nullTag: // Don't bother with returning a jsonEncoded for the singleton types. |
| 143 | return NullJSONValue, nil |
| 144 | case falseTag: |
| 145 | return FalseJSONValue, nil |
| 146 | case trueTag: |
| 147 | return TrueJSONValue, nil |
| 148 | case containerTag: |
| 149 | // Every container is prefixed with its uint32 container header. |
| 150 | containerHeader, err := getUint32At(v, 0) |
| 151 | if err != nil { |
| 152 | return nil, err |
| 153 | } |
| 154 | switch containerHeader & containerHeaderTypeMask { |
| 155 | case arrayContainerTag: |
| 156 | typ = ArrayJSONType |
| 157 | case objectContainerTag: |
| 158 | typ = ObjectJSONType |
| 159 | } |
| 160 | containerLen = int(containerHeader & containerHeaderLenMask) |
| 161 | } |
| 162 | |
| 163 | return &jsonEncoded{ |
| 164 | typ: typ, |
| 165 | containerLen: containerLen, |
| 166 | value: v, |
| 167 | }, nil |
| 168 | } |
| 169 | |
| 170 | func getUint32At(v []byte, idx int) (uint32, error) { |
| 171 | if idx+4 > len(v) { |
no test coverage detected