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

Method DecodeBytes

decoder.go:187–211  ·  view source on GitHub ↗

DecodeBytes decodes a length-delimited slice of bytes 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

185//
186// io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
187func (d *Decoder) DecodeBytes() ([]byte, error) {
188 if d.offset >= len(d.p) {
189 return nil, io.ErrUnexpectedEOF
190 }
191
192 l, n, err := DecodeVarint(d.p[d.offset:])
193 switch {
194 case err != nil:
195 return nil, fmt.Errorf("invalid data at byte %d: %w", d.offset, err)
196 case n == 0:
197 return nil, fmt.Errorf("invalid data at byte %d: %w", d.offset, ErrInvalidVarintData)
198 case l > maxFieldLen:
199 return nil, fmt.Errorf("invalid length (%d) for length-delimited field at byte %d: %w", l, d.offset, ErrLenOverflow)
200 default:
201 // length is good
202 }
203
204 nb := int(l)
205 if d.offset+n+nb > len(d.p) {
206 return nil, io.ErrUnexpectedEOF
207 }
208 b := d.p[d.offset+n : d.offset+n+nb]
209 d.offset += n + nb
210 return b, nil
211}
212
213// DecodeUInt32 decodes a varint-encoded 32-bit unsigned integer from the stream and returns the value.
214//

Callers 15

DecodeStringMethod · 0.95
TestDecodeBytesFunction · 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

TestDecodeBytesFunction · 0.76