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

Function EncodeNonsortingUvarint

pkg/util/encoding/encoding.go:1730–1753  ·  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

1728// - The most significant bit (msb) in each output byte indicates if there
1729// is a continuation byte (msb = 1).
1730func EncodeNonsortingUvarint(appendTo []byte, x uint64) []byte {
1731 switch {
1732 case x < (1 << 7):
1733 return append(appendTo, byte(x))
1734 case x < (1 << 14):
1735 return append(appendTo, 0x80|byte(x>>7), 0x7f&byte(x))
1736 case x < (1 << 21):
1737 return append(appendTo, 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
1738 case x < (1 << 28):
1739 return append(appendTo, 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
1740 case x < (1 << 35):
1741 return append(appendTo, 0x80|byte(x>>28), 0x80|byte(x>>21), 0x80|byte(x>>14), 0x80|byte(x>>7), 0x7f&byte(x))
1742 case x < (1 << 42):
1743 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))
1744 case x < (1 << 49):
1745 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))
1746 case x < (1 << 56):
1747 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))
1748 case x < (1 << 63):
1749 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))
1750 default:
1751 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))
1752 }
1753}
1754
1755// DecodeNonsortingUvarint decodes a value encoded by EncodeNonsortingUvarint. It
1756// 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…