MCPcopy
hub / github.com/tinylib/msgp / ReadBytesHeader

Function ReadBytesHeader

msgp/read_bytes.go:273–306  ·  view source on GitHub ↗

ReadBytesHeader reads the 'bin' header size off of 'b' and returns the size and remaining bytes. Possible errors: - [ErrShortBytes] (too few bytes) - [TypeError] (not a bin object)

(b []byte)

Source from the content-addressed store, hash-verified

271// - [ErrShortBytes] (too few bytes)
272// - [TypeError] (not a bin object)
273func ReadBytesHeader(b []byte) (sz uint32, o []byte, err error) {
274 if len(b) < 1 {
275 return 0, nil, ErrShortBytes
276 }
277 switch b[0] {
278 case mbin8:
279 if len(b) < 2 {
280 err = ErrShortBytes
281 return
282 }
283 sz = uint32(b[1])
284 o = b[2:]
285 return
286 case mbin16:
287 if len(b) < 3 {
288 err = ErrShortBytes
289 return
290 }
291 sz = uint32(big.Uint16(b[1:]))
292 o = b[3:]
293 return
294 case mbin32:
295 if len(b) < 5 {
296 err = ErrShortBytes
297 return
298 }
299 sz = big.Uint32(b[1:])
300 o = b[5:]
301 return
302 default:
303 err = badPrefix(BinType, b[0])
304 return
305 }
306}
307
308// ReadNilBytes tries to read a "nil" byte
309// off of 'b' and return the remaining bytes.

Callers 2

TestReadBytesHeaderFunction · 0.85

Calls 1

badPrefixFunction · 0.85

Tested by 2

TestReadBytesHeaderFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…