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

Method shallowDecode

postgres/parser/json/encoded.go:470–521  ·  view source on GitHub ↗

shallowDecode decodes only the keys of an object, and doesn't decode any elements of an array. It can be used to save a decode-encode cycle for certain operations (say, key deletion).

()

Source from the content-addressed store, hash-verified

468// elements of an array. It can be used to save a decode-encode cycle for
469// certain operations (say, key deletion).
470func (j *jsonEncoded) shallowDecode() (JSON, error) {
471 if dec := j.alreadyDecoded(); dec != nil {
472 return dec, nil
473 }
474
475 switch j.typ {
476 case NumberJSONType, StringJSONType, TrueJSONType, FalseJSONType, NullJSONType:
477 return j.decode()
478 case ArrayJSONType:
479 iter := j.iterArrayValues()
480 result := make(jsonArray, j.containerLen)
481 for i := 0; i < j.containerLen; i++ {
482 entry, next, _, err := iter.nextEncoded()
483 if err != nil {
484 return nil, err
485 }
486 result[i], err = newEncoded(entry, next)
487 if err != nil {
488 return nil, err
489 }
490 }
491 return result, nil
492 case ObjectJSONType:
493 iter, err := j.iterObject()
494 if err != nil {
495 return nil, err
496 }
497 result := make(jsonObject, j.containerLen)
498 for i := 0; i < j.containerLen; i++ {
499 nextKey, entry, nextValue, _, err := iter.nextEncoded()
500 if err != nil {
501 return nil, err
502 }
503 v, err := newEncoded(entry, nextValue)
504 if err != nil {
505 return nil, err
506 }
507 result[i] = jsonKeyValuePair{
508 k: jsonString(nextKey),
509 v: v,
510 }
511 }
512 j.mu.Lock()
513 defer j.mu.Unlock()
514 if j.mu.cachedDecoded == nil {
515 j.mu.cachedDecoded = result
516 }
517 return result, nil
518 default:
519 return nil, errors.AssertionFailedf("unknown json type: %v", errors.Safe(j.typ))
520 }
521}
522
523func (j *jsonEncoded) mustDecode() JSON {
524 decoded, err := j.shallowDecode()

Callers 15

StripNullsMethod · 0.95
ObjectIterMethod · 0.95
mustDecodeMethod · 0.95
CompareMethod · 0.95
RemoveIndexMethod · 0.95
ConcatMethod · 0.95
RemoveStringMethod · 0.95
RemovePathMethod · 0.95
doRemovePathMethod · 0.95
toGoReprMethod · 0.95
tryDecodeMethod · 0.95
setValKeyOrIdxFunction · 0.80

Calls 9

alreadyDecodedMethod · 0.95
decodeMethod · 0.95
iterArrayValuesMethod · 0.95
iterObjectMethod · 0.95
newEncodedFunction · 0.85
jsonStringTypeAlias · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
nextEncodedMethod · 0.45

Tested by

no test coverage detected