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

Method Int32Values

lazyproto/fielddata.go:236–256  ·  view source on GitHub ↗

Int32Values converts the lazily-decoded field data into a []int32. Use this method to retrieve values that are defined as int32 in the Protobuf message. Fields that are defined as sint32 (and so use the [Protobuf ZigZag encoding]) should be retrieved using SInt32Values() instead. See the [FieldDat

()

Source from the content-addressed store, hash-verified

234//
235// [Protobuf ZigZag encoding]: https://developers.google.com/protocol-buffers/docs/encoding#signed-ints
236func (fd *FieldData) Int32Values() ([]int32, error) {
237 if fd == nil || len(fd.data) == 0 {
238 return nil, ErrTagNotFound
239 }
240 s, err := sliceValue(fd, csproto.WireTypeVarint, fd.int32Slice, func(data []byte) (int32, int, error) {
241 value, n, err := csproto.DecodeVarint(data)
242 if err != nil {
243 return 0, 0, err
244 }
245 // ensure the result is within [-math.MaxInt32, math.MaxInt32] when converted to a signed value
246 if i64 := int64(value); i64 > math.MaxInt32 || i64 < math.MinInt32 {
247 return 0, 0, csproto.ErrValueOverflow
248 }
249 return int32(value), n, nil
250 })
251 if fd.unsafe {
252 fd.maxCap = max(fd.maxCap, cap(s))
253 fd.int32Slice = s
254 }
255 return s, err
256}
257
258// SInt32Value converts the lazily-decoded field data into an int32.
259//

Callers 2

FuzzNumbersFunction · 0.45
TestInt32FieldDataFunction · 0.45

Calls 2

DecodeVarintFunction · 0.92
sliceValueFunction · 0.85

Tested by 2

FuzzNumbersFunction · 0.36
TestInt32FieldDataFunction · 0.36