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

Method EncodePackedUInt32

encoder.go:178–191  ·  view source on GitHub ↗

EncodePackedUInt32 writes a list of 32-bit unsigned 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 value

(tag int, vs []uint32)

Source from the content-addressed store, hash-verified

176// This operation is O(n^2) because we have to traverse the list of values to calculate the total
177// encoded size and write that size *before* the actual encoded values.
178func (e *Encoder) EncodePackedUInt32(tag int, vs []uint32) {
179 if len(vs) == 0 {
180 return
181 }
182 e.offset += EncodeTag(e.p[e.offset:], tag, WireTypeLengthDelimited)
183 sz := 0
184 for _, v := range vs {
185 sz += SizeOfVarint(uint64(v))
186 }
187 e.offset += EncodeVarint(e.p[e.offset:], uint64(sz))
188 for _, v := range vs {
189 e.offset += EncodeVarint(e.p[e.offset:], uint64(v))
190 }
191}
192
193// EncodePackedUInt64 writes a list of 64-bit unsigned integers to the buffer using packed encoding,
194// preceded by the varint-encoded tag key.

Callers 7

TestEncodePackedUInt32Function · 0.95
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

TestEncodePackedUInt32Function · 0.76