vlq

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func AppendEncodeFloat64(dst []byte, f float64) []byte

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

func AppendEncodeInt64(dst []byte, i int64) []byte

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

func AppendEncodeUint64(dst []byte, u uint64) []byte

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

func DecodeFloat64(src []byte) (f float64, n int, err error)

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

func DecodeInt64(src []byte) (i int64, n int, err error)

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

func DecodeUint64(src []byte) (u uint64, n int, err error)

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

func EncodeFloat64(dst []byte, f float64) int

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

func EncodeInt64(dst []byte, i int64) int

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

func EncodeUint64(dst []byte, u uint64) int

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

func Float64EncodedLen(f float64) int

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

func Int64EncodedLen(i int64) int

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

func Uint64EncodedLen(u uint64) int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL