MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / decodeJSONObject

Function decodeJSONObject

pkg/util/json/encode.go:245–280  ·  view source on GitHub ↗
(containerHeader uint32, b []byte)

Source from the content-addressed store, hash-verified

243}
244
245func decodeJSONObject(containerHeader uint32, b []byte) ([]byte, JSON, error) {
246 length := int(containerHeader & containerHeaderLenMask)
247
248 b, jEntries, err := decodeJEntries(length*2, b)
249 if err != nil {
250 return b, nil, err
251 }
252
253 // There are `length` key entries at the start and `length` value entries at the back.
254 keyJEntries := jEntries[:length]
255 valueJEntries := jEntries[length:]
256
257 result := make(jsonObject, length)
258 // Decode the keys.
259 for i := 0; i < length; i++ {
260 e := keyJEntries[i]
261 if e.typCode != stringTag {
262 return b, nil, errors.AssertionFailedf(
263 "key encoded as non-string: %d", errors.Safe(e.typCode))
264 }
265 // Inline string decoding from decodeJSONValue. This avoids the cost to pass
266 // through a JSON interface.
267 b, result[i].k = b[e.length:], jsonString(b[:e.length])
268 }
269
270 // Decode the values.
271 for i := 0; i < length; i++ {
272 var nextJSON JSON
273 b, nextJSON, err = decodeJSONValue(valueJEntries[i], b)
274 if err != nil {
275 return b, nil, err
276 }
277 result[i].v = nextJSON
278 }
279 return b, result, nil
280}
281
282func decodeJSONNumber(b []byte) ([]byte, jsonNumber, error) {
283 b, d, err := encoding.DecodeUntaggedDecimalValue(b)

Callers 1

DecodeJSONFunction · 0.85

Calls 3

decodeJEntriesFunction · 0.85
jsonStringTypeAlias · 0.85
decodeJSONValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…