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

Function EncodeJSON

pkg/util/json/encode.go:161–186  ·  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

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

Callers 1

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…