binary

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package binary implements simple translation between numbers and byte sequences and encoding and decoding of varints.

Numbers are translated by reading and writing fixed-size values. A fixed-size value is either a fixed-size arithmetic type (bool, int8, uint8, int16, float32, complex64, ...) or an array or struct containing only fixed-size values.

Based on the encoding/binary package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendByteOrder

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

AppendByteOrder specifies how to append 16-, 32-, or 64-bit unsigned integers into a byte slice.

It is implemented by LittleEndian, BigEndian, and [NativeEndian].

type BE

type BE struct {
	// contains filtered or unexported fields
}
var BigEndian BE

BigEndian is the big-endian implementation of ByteOrder and AppendByteOrder.

func (BE) AppendUint16

func (BE) AppendUint16(b []byte, v uint16) []byte

AppendUint16 appends the bytes of v to b and returns the appended slice. Requires at least 2 bytes of spare capacity in b.

func (BE) AppendUint32

func (BE) AppendUint32(b []byte, v uint32) []byte

AppendUint32 appends the bytes of v to b and returns the appended slice. Requires at least 4 bytes of spare capacity in b.

func (BE) AppendUint64

func (BE) AppendUint64(b []byte, v uint64) []byte

AppendUint64 appends the bytes of v to b and returns the appended slice. Requires at least 8 bytes of spare capacity in b.

func (BE) PutUint16

func (BE) PutUint16(b []byte, v uint16)

PutUint16 stores v into b[0:2].

func (BE) PutUint32

func (BE) PutUint32(b []byte, v uint32)

PutUint32 stores v into b[0:4].

func (BE) PutUint64

func (BE) PutUint64(b []byte, v uint64)

PutUint64 stores v into b[0:8].

func (BE) String

func (BE) String() string

func (BE) Uint16

func (BE) Uint16(b []byte) uint16

Uint16 returns the uint16 representation of b[0:2].

func (BE) Uint32

func (BE) Uint32(b []byte) uint32

Uint32 returns the uint32 representation of b[0:4].

func (BE) Uint64

func (BE) Uint64(b []byte) uint64

Uint64 returns the uint64 representation of b[0:8].

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
}

A ByteOrder specifies how to convert byte slices into 16-, 32-, or 64-bit unsigned integers.

It is implemented by LittleEndian, BigEndian, and [NativeEndian].

type LE

type LE struct {
	// contains filtered or unexported fields
}
var LittleEndian LE

LittleEndian is the little-endian implementation of ByteOrder and AppendByteOrder.

func (LE) AppendUint16

func (LE) AppendUint16(b []byte, v uint16) []byte

AppendUint16 appends the bytes of v to b and returns the appended slice. Requires at least 2 bytes of spare capacity in b.

func (LE) AppendUint32

func (LE) AppendUint32(b []byte, v uint32) []byte

AppendUint32 appends the bytes of v to b and returns the appended slice. Requires at least 4 bytes of spare capacity in b.

func (LE) AppendUint64

func (LE) AppendUint64(b []byte, v uint64) []byte

AppendUint64 appends the bytes of v to b and returns the appended slice. Requires at least 8 bytes of spare capacity in b.

func (LE) PutUint16

func (LE) PutUint16(b []byte, v uint16)

PutUint16 stores v into b[0:2].

func (LE) PutUint32

func (LE) PutUint32(b []byte, v uint32)

PutUint32 stores v into b[0:4].

func (LE) PutUint64

func (LE) PutUint64(b []byte, v uint64)

PutUint64 stores v into b[0:8].

func (LE) String

func (LE) String() string

func (LE) Uint16

func (LE) Uint16(b []byte) uint16

Uint16 returns the uint16 representation of b[0:2].

func (LE) Uint32

func (LE) Uint32(b []byte) uint32

Uint32 returns the uint32 representation of b[0:4].

func (LE) Uint64

func (LE) Uint64(b []byte) uint64

Uint64 returns the uint64 representation of b[0:8].

Jump to

Keyboard shortcuts

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