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

Function PeekValueLengthWithOffsetsAndType

pkg/util/encoding/encoding.go:2348–2406  ·  view source on GitHub ↗

PeekValueLengthWithOffsetsAndType is the same as PeekValueLength, except it expects a dataOffset and typ value from a previous call to DecodeValueTag on its input byte slice. Use this if you've already called DecodeValueTag on the input for another reason, to avoid it getting called twice.

(b []byte, dataOffset int, typ Type)

Source from the content-addressed store, hash-verified

2346// on its input byte slice. Use this if you've already called DecodeValueTag
2347// on the input for another reason, to avoid it getting called twice.
2348func PeekValueLengthWithOffsetsAndType(b []byte, dataOffset int, typ Type) (length int, err error) {
2349 b = b[dataOffset:]
2350 switch typ {
2351 case Null:
2352 return dataOffset, nil
2353 case True, False:
2354 return dataOffset, nil
2355 case Int:
2356 _, n, _, err := DecodeNonsortingStdlibVarint(b)
2357 return dataOffset + n, err
2358 case Float:
2359 return dataOffset + floatValueEncodedLength, nil
2360 case Bytes, Array, JSON:
2361 _, n, i, err := DecodeNonsortingUvarint(b)
2362 return dataOffset + n + int(i), err
2363 case BitArray:
2364 _, n, bitLen, err := DecodeNonsortingUvarint(b)
2365 if err != nil {
2366 return 0, err
2367 }
2368 numWords, _ := bitarray.SizesForBitLen(uint(bitLen))
2369 return dataOffset + n + int(numWords)*8, err
2370 case Tuple:
2371 rem, l, numTuples, err := DecodeNonsortingUvarint(b)
2372 if err != nil {
2373 return 0, errors.Wrapf(err, "cannot decode tuple header: ")
2374 }
2375 for i := 0; i < int(numTuples); i++ {
2376 _, entryLen, err := PeekValueLength(rem)
2377 if err != nil {
2378 return 0, errors.Wrapf(err, "cannot peek tuple entry %d", i)
2379 }
2380 l += entryLen
2381 rem = rem[entryLen:]
2382 }
2383 return dataOffset + l, nil
2384 case Decimal:
2385 _, n, i, err := DecodeNonsortingStdlibUvarint(b)
2386 return dataOffset + n + int(i), err
2387 case Time, TimeTZ:
2388 n, err := getMultiNonsortingVarintLen(b, 2)
2389 return dataOffset + n, err
2390 case Duration:
2391 n, err := getMultiNonsortingVarintLen(b, 3)
2392 return dataOffset + n, err
2393 case UUID:
2394 return dataOffset + uuidValueEncodedLength, err
2395 case IPAddr:
2396 family := ipaddr.IPFamily(b[0])
2397 if family == ipaddr.IPv4family {
2398 return dataOffset + ipaddr.IPv4size, err
2399 } else if family == ipaddr.IPv6family {
2400 return dataOffset + ipaddr.IPv6size, err
2401 }
2402 return 0, errors.Errorf("got invalid INET IP family: %d", family)
2403 default:
2404 return 0, errors.Errorf("unknown type %s", typ)
2405 }

Callers 1

PeekValueLengthFunction · 0.85

Calls 7

SizesForBitLenFunction · 0.92
IPFamilyTypeAlias · 0.92
DecodeNonsortingUvarintFunction · 0.85
PeekValueLengthFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…