MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / shallowDecode

Method shallowDecode

pkg/util/json/encoded.go:456–507  ·  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

454// elements of an array. It can be used to save a decode-encode cycle for
455// certain operations (say, key deletion).
456func (j *jsonEncoded) shallowDecode() (JSON, error) {
457 if dec := j.alreadyDecoded(); dec != nil {
458 return dec, nil
459 }
460
461 switch j.typ {
462 case NumberJSONType, StringJSONType, TrueJSONType, FalseJSONType, NullJSONType:
463 return j.decode()
464 case ArrayJSONType:
465 iter := j.iterArrayValues()
466 result := make(jsonArray, j.containerLen)
467 for i := 0; i < j.containerLen; i++ {
468 entry, next, _, err := iter.nextEncoded()
469 if err != nil {
470 return nil, err
471 }
472 result[i], err = newEncoded(entry, next)
473 if err != nil {
474 return nil, err
475 }
476 }
477 return result, nil
478 case ObjectJSONType:
479 iter, err := j.iterObject()
480 if err != nil {
481 return nil, err
482 }
483 result := make(jsonObject, j.containerLen)
484 for i := 0; i < j.containerLen; i++ {
485 nextKey, entry, nextValue, _, err := iter.nextEncoded()
486 if err != nil {
487 return nil, err
488 }
489 v, err := newEncoded(entry, nextValue)
490 if err != nil {
491 return nil, err
492 }
493 result[i] = jsonKeyValuePair{
494 k: jsonString(nextKey),
495 v: v,
496 }
497 }
498 j.mu.Lock()
499 defer j.mu.Unlock()
500 if j.mu.cachedDecoded == nil {
501 j.mu.cachedDecoded = result
502 }
503 return result, nil
504 default:
505 return nil, errors.AssertionFailedf("unknown json type: %v", errors.Safe(j.typ))
506 }
507}
508
509func (j *jsonEncoded) mustDecode() JSON {
510 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