MCPcopy Create free account
hub / github.com/dolthub/doltgresql / decodeJSONObject

Function decodeJSONObject

postgres/parser/json/encode.go:265–303  ·  view source on GitHub ↗
(containerHeader uint32, b []byte)

Source from the content-addressed store, hash-verified

263}
264
265func decodeJSONObject(containerHeader uint32, b []byte) ([]byte, JSON, error) {
266 length := int(containerHeader & containerHeaderLenMask)
267
268 b, jEntries, err := decodeJEntries(length*2, b)
269 if err != nil {
270 return b, nil, err
271 }
272
273 // There are `length` key entries at the start and `length` value entries at the back.
274 keyJEntries := jEntries[:length]
275 valueJEntries := jEntries[length:]
276
277 result := make(jsonObject, length)
278 // Decode the keys.
279 for i := 0; i < length; i++ {
280 var nextJSON JSON
281 b, nextJSON, err = decodeJSONValue(keyJEntries[i], b)
282 if err != nil {
283 return b, nil, err
284 }
285 if key, ok := nextJSON.(jsonString); ok {
286 result[i].k = key
287 } else {
288 return b, nil, errors.AssertionFailedf(
289 "key encoded as non-string: %T", nextJSON)
290 }
291 }
292
293 // Decode the values.
294 for i := 0; i < length; i++ {
295 var nextJSON JSON
296 b, nextJSON, err = decodeJSONValue(valueJEntries[i], b)
297 if err != nil {
298 return b, nil, err
299 }
300 result[i].v = nextJSON
301 }
302 return b, result, nil
303}
304
305func decodeJSONNumber(b []byte) ([]byte, JSON, error) {
306 b, d, err := encoding.DecodeUntaggedDecimalValue(b)

Callers 1

DecodeJSONFunction · 0.85

Calls 2

decodeJEntriesFunction · 0.85
decodeJSONValueFunction · 0.85

Tested by

no test coverage detected