MCPcopy Index your code
hub / github.com/CrowdStrike/csproto / DecodeInt32

Method DecodeInt32

decoder.go:255–272  ·  view source on GitHub ↗

DecodeInt32 decodes a varint-encoded 32-bit integer from the stream and returns the value. io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.

()

Source from the content-addressed store, hash-verified

253//
254// io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
255func (d *Decoder) DecodeInt32() (int32, error) {
256 if d.offset >= len(d.p) {
257 return 0, io.ErrUnexpectedEOF
258 }
259 v, n, err := DecodeVarint(d.p[d.offset:])
260 if err != nil {
261 return 0, fmt.Errorf("invalid data at byte %d: %w", d.offset, err)
262 }
263 if n == 0 {
264 return 0, fmt.Errorf("invalid data at byte %d: %w", d.offset, ErrInvalidVarintData)
265 }
266 // ensure the result is within [-math.MaxInt32, math.MaxInt32] when converted to a signed value
267 if i64 := int64(v); i64 > math.MaxInt32 || i64 < math.MinInt32 {
268 return 0, ErrValueOverflow
269 }
270 d.offset += n
271 return int32(v), nil
272}
273
274// DecodeInt64 decodes a varint-encoded 64-bit integer from the stream and returns the value.
275//

Callers 15

TestDecodeInt32Function · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95

Calls 1

DecodeVarintFunction · 0.85

Tested by 2

TestDecodeInt32Function · 0.76