EncodePackedInt32 writes a list of 32-bit integers to the buffer using packed encoding, preceded by the varint-encoded tag key. This operation is O(n^2) because we have to traverse the list of values to calculate the total encoded size and write that size *before* the actual encoded values.
(tag int, vs []int32)
| 136 | // This operation is O(n^2) because we have to traverse the list of values to calculate the total |
| 137 | // encoded size and write that size *before* the actual encoded values. |
| 138 | func (e *Encoder) EncodePackedInt32(tag int, vs []int32) { |
| 139 | if len(vs) == 0 { |
| 140 | return |
| 141 | } |
| 142 | e.offset += EncodeTag(e.p[e.offset:], tag, WireTypeLengthDelimited) |
| 143 | sz := 0 |
| 144 | for _, v := range vs { |
| 145 | sz += SizeOfVarint(uint64(v)) |
| 146 | } |
| 147 | e.offset += EncodeVarint(e.p[e.offset:], uint64(sz)) |
| 148 | for _, v := range vs { |
| 149 | e.offset += EncodeVarint(e.p[e.offset:], uint64(v)) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // EncodePackedInt64 writes a list of 64-bit integers to the buffer using packed encoding, preceded by |
| 154 | // the varint-encoded tag key. |