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

Method encode

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

Source from the content-addressed store, hash-verified

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