MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeJSON

Function EncodeJSON

pkg/util/json/encode.go:155–180  ·  view source on GitHub ↗

EncodeJSON encodes a JSON value as a sequence of bytes.

(appendTo []byte, j JSON)

Source from the content-addressed store, hash-verified

153
154// EncodeJSON encodes a JSON value as a sequence of bytes.
155func EncodeJSON(appendTo []byte, j JSON) ([]byte, error) {
156 switch j.Type() {
157 case ArrayJSONType, ObjectJSONType:
158 // We just discard the JEntry in these cases.
159 var err error
160 _, appendTo, err = j.encode(appendTo)
161 if err != nil {
162 return appendTo, err
163 }
164 return appendTo, nil
165 default: // j is a scalar, so we must construct a scalar container for it at the top level.
166 // Scalar container header.
167 appendTo = encoding.EncodeUint32Ascending(appendTo, scalarContainerTag)
168 // Reserve space for scalar jEntry.
169 jEntryIdx := len(appendTo)
170 appendTo = encoding.EncodeUint32Ascending(appendTo, 0)
171 var entry jEntry
172 var err error
173 entry, appendTo, err = j.encode(appendTo)
174 if err != nil {
175 return appendTo, err
176 }
177 appendTo = encoding.PutUint32Ascending(appendTo, entry.encoded(lengthMode), jEntryIdx)
178 return appendTo, nil
179 }
180}
181
182// DecodeJSON decodes a value encoded with EncodeJSON.
183func DecodeJSON(b []byte) ([]byte, JSON, error) {

Callers 2

SetMethod · 0.92
doRandomJSONFunction · 0.85

Calls 5

encodedMethod · 0.95
EncodeUint32AscendingFunction · 0.92
PutUint32AscendingFunction · 0.92
TypeMethod · 0.65
encodeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…