MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / PeekLength

Function PeekLength

pkg/util/encoding/encoding.go:1371–1421  ·  view source on GitHub ↗

PeekLength returns the length of the encoded value at the start of b. Note: if this function succeeds, it's not a guarantee that decoding the value will succeed. PeekLength is meant to be used on key encoded data only.

(b []byte)

Source from the content-addressed store, hash-verified

1369// if this function succeeds, it's not a guarantee that decoding the value will
1370// succeed. PeekLength is meant to be used on key encoded data only.
1371func PeekLength(b []byte) (int, error) {
1372 if len(b) == 0 {
1373 return 0, errors.Errorf("empty slice")
1374 }
1375 m := b[0]
1376 switch m {
1377 case encodedNull, encodedNullDesc, encodedNotNull, encodedNotNullDesc,
1378 floatNaN, floatNaNDesc, floatZero, decimalZero, byte(True), byte(False):
1379 // interleavedSentinel also falls into this path. Since it
1380 // contains the same byte value as encodedNotNullDesc, it
1381 // cannot be included explicitly in the case statement.
1382 return 1, nil
1383 case bitArrayMarker, bitArrayDescMarker:
1384 terminator := byte(bitArrayDataTerminator)
1385 if m == bitArrayDescMarker {
1386 terminator = bitArrayDataDescTerminator
1387 }
1388 _, n, err := getBitArrayWordsLen(b[1:], terminator)
1389 if err != nil {
1390 return 1 + n, err
1391 }
1392 m, err := getVarintLen(b[n+2:])
1393 if err != nil {
1394 return 1 + n + m + 1, err
1395 }
1396 return 1 + n + m + 1, nil
1397 case bytesMarker:
1398 return getBytesLength(b, ascendingEscapes)
1399 case jsonInvertedIndex:
1400 return getJSONInvertedIndexKeyLength(b)
1401 case bytesDescMarker:
1402 return getBytesLength(b, descendingEscapes)
1403 case timeMarker, timeTZMarker:
1404 return GetMultiVarintLen(b, 2)
1405 case durationBigNegMarker, durationMarker, durationBigPosMarker:
1406 return GetMultiVarintLen(b, 3)
1407 case floatNeg, floatPos:
1408 // the marker is followed by 8 bytes
1409 if len(b) < 9 {
1410 return 0, errors.Errorf("slice too short for float (%d)", len(b))
1411 }
1412 return 9, nil
1413 }
1414 if m >= IntMin && m <= IntMax {
1415 return getVarintLen(b)
1416 }
1417 if m >= decimalNaN && m <= decimalNaNDesc {
1418 return getDecimalLen(b)
1419 }
1420 return 0, errors.Errorf("unknown tag %d", m)
1421}
1422
1423// PrettyPrintValue returns the string representation of all contiguous
1424// decodable values in the provided byte slice, separated by a provided

Callers 2

DecomposeKeyTokensFunction · 0.85

Calls 6

getBitArrayWordsLenFunction · 0.85
getVarintLenFunction · 0.85
getBytesLengthFunction · 0.85
GetMultiVarintLenFunction · 0.85
getDecimalLenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…