EncodePackedSInt32 writes a list of 32-bit signed 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)
| 216 | // This operation is O(n^2) because we have to traverse the list of values to calculate the total |
| 217 | // encoded size and write that size *before* the actual encoded values. |
| 218 | func (e *Encoder) EncodePackedSInt32(tag int, vs []int32) { |
| 219 | if len(vs) == 0 { |
| 220 | return |
| 221 | } |
| 222 | e.offset += EncodeTag(e.p[e.offset:], tag, WireTypeLengthDelimited) |
| 223 | sz := 0 |
| 224 | for _, v := range vs { |
| 225 | sz += SizeOfZigZag(uint64(v)) |
| 226 | } |
| 227 | e.offset += EncodeVarint(e.p[e.offset:], uint64(sz)) |
| 228 | for _, v := range vs { |
| 229 | e.offset += EncodeZigZag32(e.p[e.offset:], v) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // EncodePackedSInt64 writes a list of 64-bit signed integers to the buffer using packed encoding, |
| 234 | // preceded by the varint-encoded tag key. |