Documentation ¶
Overview ¶
Package vlq provides variable-length encoding for numbers (including integers and floating-point numbers) based on the variable-length quantity (VLQ), with additional offsets to eliminate redundancy.
For better performance, all functions in this package are unsafe for concurrency unless otherwise specified.
Index ¶
- Variables
- func AppendEncodeFloat64(dst []byte, f float64) []byte
- func AppendEncodeInt64(dst []byte, i int64) []byte
- func AppendEncodeUint64(dst []byte, u uint64) []byte
- func DecodeFloat64(src []byte) (f float64, n int, err error)
- func DecodeInt64(src []byte) (i int64, n int, err error)
- func DecodeUint64(src []byte) (u uint64, n int, err error)
- func EncodeFloat64(dst []byte, f float64) int
- func EncodeInt64(dst []byte, i int64) int
- func EncodeUint64(dst []byte, u uint64) int
- func Float64EncodedLen(f float64) int
- func Int64EncodedLen(i int64) int
- func Uint64EncodedLen(u uint64) int
Constants ¶
This section is empty.
Variables ¶
var ErrSrcIncomplete = errors.AutoNewCustom( "src is incomplete", errors.PrependFullPkgName, 0, )
ErrSrcIncomplete is an error indicating that the source bytes src is incomplete to be decoded with the variable-length quantity (VLQ) style encoding.
The client should use errors.Is to test whether an error is ErrSrcIncomplete.
var ErrSrcTooLarge = errors.AutoNewCustom( "src is too large to be decoded into a 64-bit number", errors.PrependFullPkgName, 0, )
ErrSrcTooLarge is an error indicating that the source bytes src is too large to be decoded into a 64-bit number with the variable-length quantity (VLQ) style encoding.
The client should use errors.Is to test whether an error is ErrSrcTooLarge.
Functions ¶
func AppendEncodeFloat64 ¶ added in v0.12.2
AppendEncodeFloat64 appends the variable-length quantity (VLQ) style encoding of the 64-bit floating-point number f to dst and returns the extended byte slice. It converts f to a 64-bit unsigned integer. The integer is then byte-reversed and encoded as a regular unsigned integer.
func AppendEncodeInt64 ¶ added in v0.12.2
AppendEncodeInt64 appends the variable-length quantity (VLQ) style encoding of the 64-bit signed integer i with zigzag encoding to dst and returns the extended byte slice.
func AppendEncodeUint64 ¶ added in v0.12.2
AppendEncodeUint64 appends the variable-length quantity (VLQ) style encoding of the 64-bit unsigned integer u to dst and returns the extended byte slice.
func DecodeFloat64 ¶
DecodeFloat64 decodes src into a 64-bit floating-point number with variable-length quantity (VLQ) style encoding. It first decodes src into a 64-bit unsigned integer. The integer is then byte-reversed and converted to a 64-bit floating-point number.
If src is nil or empty, it reports ErrSrcIncomplete.
The decoding stops when obtaining a 64-bit floating-point number. Subsequent content in src (if any) is ignored.
It also returns the number of bytes read from src (n). If err is nil, n is exactly Float64EncodedLen(f). If err is not nil, n is 0.
func DecodeInt64 ¶
DecodeInt64 decodes src into a 64-bit signed integer with variable-length quantity (VLQ) style encoding and zigzag encoding.
If src is nil or empty, it reports ErrSrcIncomplete.
The decoding stops when obtaining a 64-bit signed integer. Subsequent content in src (if any) is ignored.
It also returns the number of bytes read from src (n). If err is nil, n is exactly Int64EncodedLen(i). If err is not nil, n is 0.
func DecodeUint64 ¶
DecodeUint64 decodes src into a 64-bit unsigned integer with variable-length quantity (VLQ) style encoding.
If src is nil or empty, it reports ErrSrcIncomplete.
The decoding stops when obtaining a 64-bit unsigned integer. Subsequent content in src (if any) is ignored.
It also returns the number of bytes read from src (n). If err is nil, n is exactly Uint64EncodedLen(u). If err is not nil, n is 0.
func EncodeFloat64 ¶
EncodeFloat64 encodes the 64-bit floating-point number f in variable-length quantity (VLQ) style encoding. It converts f to a 64-bit unsigned integer. The integer is then byte-reversed and encoded as a regular unsigned integer.
It panics if dst doesn't have enough space to hold the encoding result. The client should guarantee that len(dst) >= Float64EncodedLen(i).
It returns the number of bytes written into dst, exactly Float64EncodedLen(i).
func EncodeInt64 ¶
EncodeInt64 encodes the 64-bit signed integer i in variable-length quantity (VLQ) style encoding with zigzag encoding to dst.
It panics if dst doesn't have enough space to hold the encoding result. The client should guarantee that len(dst) >= Int64EncodedLen(i).
It returns the number of bytes written into dst, exactly Int64EncodedLen(i).
func EncodeUint64 ¶
EncodeUint64 encodes the 64-bit unsigned integer u in variable-length quantity (VLQ) style encoding to dst.
It panics if dst doesn't have enough space to hold the encoding result. The client should guarantee that len(dst) >= Uint64EncodedLen(u).
It returns the number of bytes written into dst, exactly Uint64EncodedLen(u).
func Float64EncodedLen ¶
Float64EncodedLen returns the length of variable-length quantity (VLQ) style encoding of the corresponding byte-reversed 64-bit unsigned integer of the 64-bit floating-point number f.
It is at most 10.
func Int64EncodedLen ¶
Int64EncodedLen returns the length of variable-length quantity (VLQ) style encoding with zigzag encoding of the 64-bit signed integer i.
It is at most 10.
func Uint64EncodedLen ¶
Uint64EncodedLen returns the length of variable-length quantity (VLQ) style encoding of the 64-bit unsigned integer u.
It is at most 10.
Types ¶
This section is empty.