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

Method encode

pkg/util/json/encode.go:81–108  ·  view source on GitHub ↗
(appendTo []byte)

Source from the content-addressed store, hash-verified

79}
80
81func (j jsonArray) encode(appendTo []byte) (e jEntry, b []byte, err error) {
82 encodingStartPosition := len(appendTo)
83 // Array container header.
84 appendTo = encoding.EncodeUint32Ascending(appendTo, arrayContainerTag|uint32(len(j)))
85 // Reserve space for the JEntries and store where they start so we can fill them in later.
86 jEntryIdx := len(appendTo)
87 for i := 0; i < len(j); i++ {
88 appendTo = append(appendTo, 0, 0, 0, 0)
89 }
90 offset := uint32(0)
91 for i := 0; i < len(j); i++ {
92 var nextJEntry jEntry
93 nextJEntry, appendTo, err = j[i].encode(appendTo)
94 if err != nil {
95 return jEntry{}, appendTo, err
96 }
97
98 length := nextJEntry.length
99 offset += length
100
101 appendTo = encoding.PutUint32Ascending(appendTo, nextJEntry.encoded(encodingModeForIdx(i, offset)), jEntryIdx+i*4)
102 }
103 lengthInBytes := len(appendTo) - encodingStartPosition
104 if err := checkLength(lengthInBytes); err != nil {
105 return jEntry{}, b, err
106 }
107 return makeContainerJEntry(lengthInBytes), appendTo, nil
108}
109
110func (j jsonObject) encode(appendTo []byte) (e jEntry, b []byte, err error) {
111 encodingStartPosition := len(appendTo)

Callers

nothing calls this directly

Calls 7

encodedMethod · 0.95
EncodeUint32AscendingFunction · 0.92
PutUint32AscendingFunction · 0.92
encodingModeForIdxFunction · 0.85
checkLengthFunction · 0.85
makeContainerJEntryFunction · 0.85
encodeMethod · 0.65

Tested by

no test coverage detected