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

Function newEncodedFromRoot

postgres/parser/json/encoded.go:75–99  ·  view source on GitHub ↗

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

(v []byte)

Source from the content-addressed store, hash-verified

73
74// newEncodedFromRoot returns a jsonEncoded from a fully-encoded JSON document.
75func newEncodedFromRoot(v []byte) (*jsonEncoded, error) {
76 v, typ, err := jsonTypeFromRootBuffer(v)
77 if err != nil {
78 return nil, err
79 }
80
81 containerLen := -1
82 if typ == ArrayJSONType || typ == ObjectJSONType {
83 containerHeader, err := getUint32At(v, 0)
84 if err != nil {
85 return nil, err
86 }
87 containerLen = int(containerHeader & containerHeaderLenMask)
88 }
89
90 return &jsonEncoded{
91 typ: typ,
92 containerLen: containerLen,
93 // Manually set the capacity of the new slice to its length, so we properly
94 // report the memory size of this encoded json object. The original slice
95 // capacity is very large, since it probably points to the backing byte
96 // slice of a kv batch.
97 value: v[:len(v):len(v)],
98 }, nil
99}
100
101func jsonTypeFromRootBuffer(v []byte) ([]byte, Type, error) {
102 // 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