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

Function getSize

msgp/read_bytes.go:1346–1381  ·  view source on GitHub ↗

returns (skip N bytes, skip M objects, error)

(b []byte)

Source from the content-addressed store, hash-verified

1344
1345// returns (skip N bytes, skip M objects, error)
1346func getSize(b []byte) (uintptr, uintptr, error) {
1347 l := len(b)
1348 if l == 0 {
1349 return 0, 0, ErrShortBytes
1350 }
1351 lead := b[0]
1352 spec := getBytespec(lead) // get type information
1353 size, mode := spec.size, spec.extra
1354 if size == 0 {
1355 return 0, 0, InvalidPrefixError(lead)
1356 }
1357 if mode >= 0 { // fixed composites
1358 return uintptr(size), uintptr(mode), nil
1359 }
1360 if l < int(size) {
1361 return 0, 0, ErrShortBytes
1362 }
1363 switch mode {
1364 case extra8:
1365 return uintptr(size) + uintptr(b[1]), 0, nil
1366 case extra16:
1367 return uintptr(size) + uintptr(big.Uint16(b[1:])), 0, nil
1368 case extra32:
1369 return uintptr(size) + uintptr(big.Uint32(b[1:])), 0, nil
1370 case map16v:
1371 return uintptr(size), 2 * uintptr(big.Uint16(b[1:])), nil
1372 case map32v:
1373 return uintptr(size), 2 * uintptr(big.Uint32(b[1:])), nil
1374 case array16v:
1375 return uintptr(size), uintptr(big.Uint16(b[1:])), nil
1376 case array32v:
1377 return uintptr(size), uintptr(big.Uint32(b[1:])), nil
1378 default:
1379 return 0, 0, fatal
1380 }
1381}
1382
1383// ReadJSONNumberBytes tries to read a number
1384// from 'b' and return the value and the remaining bytes.

Callers 2

SkipMethod · 0.85
skipDepthFunction · 0.85

Calls 2

InvalidPrefixErrorTypeAlias · 0.85
getBytespecFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…