MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeNonsortingUvarint

Function EncodeNonsortingUvarint

pkg/util/encoding/encoding.go:2486–2509  ·  view source on GitHub ↗

EncodeNonsortingUvarint encodes a uint64, appends it to the supplied buffer, and returns the final buffer. The encoding used is similar to encoding/binary, but with the most significant bits first: - Unsigned integers are serialized 7 bits at a time, starting with the most significant bits. - The mo

(appendTo []byte, x uint64)

Source from the content-addressed store, hash-verified

2484// - The most significant bit (msb) in each output byte indicates if there
2485// is a continuation byte (msb = 1).
2486func EncodeNonsortingUvarint(appendTo []byte, x uint64) []byte {
2487 switch {
2488 case x < (1 << 7):
2489 return append(appendTo, byte(x))
2490 case x < (1 << 14):
2491 return append(appendTo, 0x80|byte(x>>7), 0x7f&byte(x))
2492 case x < (1 << 21):
2493 return append(appendTo, 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2494 case x < (1 << 28):
2495 return append(appendTo, 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2496 case x < (1 << 35):
2497 return append(appendTo, 0x80|byte(x>>28), 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2498 case x < (1 << 42):
2499 return append(appendTo, 0x80|byte(x>>35), 0x80|byte(x>>28), 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2500 case x < (1 << 49):
2501 return append(appendTo, 0x80|byte(x>>42), 0x80|byte(x>>35), 0x80|byte(x>>28), 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2502 case x < (1 << 56):
2503 return append(appendTo, 0x80|byte(x>>49), 0x80|byte(x>>42), 0x80|byte(x>>35), 0x80|byte(x>>28), 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2504 case x < (1 << 63):
2505 return append(appendTo, 0x80|byte(x>>56), 0x80|byte(x>>49), 0x80|byte(x>>42), 0x80|byte(x>>35), 0x80|byte(x>>28), 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2506 default:
2507 return append(appendTo, 0x80|byte(x>>63), 0x80|byte(x>>56), 0x80|byte(x>>49), 0x80|byte(x>>42), 0x80|byte(x>>35), 0x80|byte(x>>28), 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
2508 }
2509}
2510
2511// DecodeNonsortingUvarint decodes a value encoded by EncodeNonsortingUvarint. It
2512// returns the length of the encoded varint and value.

Callers 3

EncodeValueTagFunction · 0.85
EncodeUntaggedBytesValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…