(appendTo []byte)
| 99 | } |
| 100 | |
| 101 | func (j jsonArray) encode(appendTo []byte) (e jEntry, b []byte, err error) { |
| 102 | encodingStartPosition := len(appendTo) |
| 103 | // Array container header. |
| 104 | appendTo = encoding.EncodeUint32Ascending(appendTo, arrayContainerTag|uint32(len(j))) |
| 105 | // Reserve space for the JEntries and store where they start so we can fill them in later. |
| 106 | jEntryIdx := len(appendTo) |
| 107 | for i := 0; i < len(j); i++ { |
| 108 | appendTo = append(appendTo, 0, 0, 0, 0) |
| 109 | } |
| 110 | offset := uint32(0) |
| 111 | for i := 0; i < len(j); i++ { |
| 112 | var nextJEntry jEntry |
| 113 | nextJEntry, appendTo, err = j[i].encode(appendTo) |
| 114 | if err != nil { |
| 115 | return jEntry{}, appendTo, err |
| 116 | } |
| 117 | |
| 118 | length := nextJEntry.length |
| 119 | offset += length |
| 120 | |
| 121 | appendTo = encoding.PutUint32Ascending(appendTo, nextJEntry.encoded(encodingModeForIdx(i, offset)), jEntryIdx+i*4) |
| 122 | } |
| 123 | lengthInBytes := len(appendTo) - encodingStartPosition |
| 124 | if err := checkLength(lengthInBytes); err != nil { |
| 125 | return jEntry{}, b, err |
| 126 | } |
| 127 | return makeContainerJEntry(lengthInBytes), appendTo, nil |
| 128 | } |
| 129 | |
| 130 | func (j jsonObject) encode(appendTo []byte) (e jEntry, b []byte, err error) { |
| 131 | encodingStartPosition := len(appendTo) |
nothing calls this directly
no test coverage detected