MCPcopy Create free account
hub / github.com/CrowdStrike/csproto / EncodePackedInt32

Method EncodePackedInt32

encoder.go:138–151  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
138func (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.

Callers 13

TestEncodePackedInt32Function · 0.95
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80

Calls 3

EncodeTagFunction · 0.85
SizeOfVarintFunction · 0.85
EncodeVarintFunction · 0.85

Tested by 1

TestEncodePackedInt32Function · 0.76