binary

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package binary translates between unsigned integers and byte sequences, and encodes varints.

Index

Constants

View Source
const (
	MaxVarintLen16 = 3
	MaxVarintLen32 = 5
	MaxVarintLen64 = 10
)

Maximum encoded lengths of varints.

Variables

View Source
var BigEndian bigEndian

BigEndian is the big-endian ByteOrder and AppendByteOrder.

View Source
var LittleEndian littleEndian

LittleEndian is the little-endian ByteOrder and AppendByteOrder.

Functions

func AppendUvarint

func AppendUvarint(buf []byte, x uint64) []byte

AppendUvarint appends the varint encoding of x to buf.

func AppendVarint

func AppendVarint(buf []byte, x int64) []byte

AppendVarint appends the zig-zag varint encoding of x to buf.

func PutUvarint

func PutUvarint(buf []byte, x uint64) int

PutUvarint encodes x into buf, which must be large enough, and returns the number of bytes written.

func PutVarint

func PutVarint(buf []byte, x int64) int

PutVarint encodes x with zig-zag varint encoding into buf.

func Uvarint

func Uvarint(buf []byte) (uint64, int)

Uvarint decodes a varint from buf and returns the value and the number of bytes read. n == 0 means buf is too short; n < 0 means the value overflows 64 bits and -n bytes were read.

func Varint

func Varint(buf []byte) (int64, int)

Varint decodes a zig-zag varint from buf like Uvarint.

Types

type AppendByteOrder

type AppendByteOrder interface {
	AppendUint16([]byte, uint16) []byte
	AppendUint32([]byte, uint32) []byte
	AppendUint64([]byte, uint64) []byte
	String() string
}

AppendByteOrder appends unsigned integers in a byte order.

type ByteOrder

type ByteOrder interface {
	Uint16([]byte) uint16
	Uint32([]byte) uint32
	Uint64([]byte) uint64
	PutUint16([]byte, uint16)
	PutUint32([]byte, uint32)
	PutUint64([]byte, uint64)
	String() string
}

ByteOrder reads and writes unsigned integers in a byte order.

Jump to

Keyboard shortcuts

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