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

Function newEncodedFromRoot

pkg/util/json/encoded.go:61–85  ·  view source on GitHub ↗

newEncodedFromRoot returns a jsonEncoded from a fully-encoded JSON document.

(v []byte)

Source from the content-addressed store, hash-verified

59
60// newEncodedFromRoot returns a jsonEncoded from a fully-encoded JSON document.
61func newEncodedFromRoot(v []byte) (*jsonEncoded, error) {
62 v, typ, err := jsonTypeFromRootBuffer(v)
63 if err != nil {
64 return nil, err
65 }
66
67 containerLen := -1
68 if typ == ArrayJSONType || typ == ObjectJSONType {
69 containerHeader, err := getUint32At(v, 0)
70 if err != nil {
71 return nil, err
72 }
73 containerLen = int(containerHeader & containerHeaderLenMask)
74 }
75
76 return &jsonEncoded{
77 typ: typ,
78 containerLen: containerLen,
79 // Manually set the capacity of the new slice to its length, so we properly
80 // report the memory size of this encoded json object. The original slice
81 // capacity is very large, since it probably points to the backing byte
82 // slice of a kv batch.
83 value: v[:len(v):len(v)],
84 }, nil
85}
86
87func jsonTypeFromRootBuffer(v []byte) ([]byte, Type, error) {
88 // Root buffers always have a container header.

Callers 2

doRandomJSONFunction · 0.85
FromEncodingFunction · 0.85

Calls 2

jsonTypeFromRootBufferFunction · 0.85
getUint32AtFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…