wire

package
v0.0.0-...-9da5b0d Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRC32

func CRC32(data []byte) uint32

CRC32 computes the IEEE CRC-32 of the given data.

func ReadUint

func ReadUint(dec *Decoder, n int, little bool) (uint64, error)

ReadUint reads n bytes from the decoder and returns them as a uint64 in the given endianness. n must be between 1 and 8, and the decoder must be byte-aligned.

func WriteUint

func WriteUint(enc *Encoder, v uint64, n int, little bool) error

WriteUint writes the lowest n bytes of v to the encoder in the given endianness. n must be between 1 and 8, and the encoder must be byte-aligned.

Types

type Codec

type Codec interface {
	Encode(*Encoder) error
	Decode(*Decoder) error
}

type DecodeError

type DecodeError struct {
	Msg string
}

func (*DecodeError) Error

func (e *DecodeError) Error() string

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reads bits and bytes from an underlying buffer. Bit order within a byte is MSB-first (network order).

func NewDecoder

func NewDecoder(buf []byte) *Decoder

func (*Decoder) AlignToByte

func (d *Decoder) AlignToByte()

AlignToByte advances bitOffset to the next byte boundary (if needed), discarding any remaining bits in the current byte.

func (*Decoder) BitsRemaining

func (d *Decoder) BitsRemaining() int

BitsRemaining returns how many bits are left in the buffer.

func (*Decoder) ReadBits

func (d *Decoder) ReadBits(n int) (uint64, error)

ReadBits reads n bits (1 <= n <= 64) MSB-first and returns them as a uint64.

func (*Decoder) ReadBytes

func (d *Decoder) ReadBytes(n int) ([]byte, error)

ReadBytes reads n whole bytes from the current position. Requires the decoder to be byte-aligned.

type EncodeError

type EncodeError struct {
	Msg string
}

func (*EncodeError) Error

func (e *EncodeError) Error() string

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder writes bits and bytes into an internal buffer. Bit order within a byte is MSB-first.

func NewEncoder

func NewEncoder(initialCapacity int) *Encoder

func (*Encoder) AlignToByte

func (e *Encoder) AlignToByte()

AlignToByte pads with zero bits to reach next byte boundary.

func (*Encoder) BitsWritten

func (e *Encoder) BitsWritten() int

BitsWritten returns how many bits have been written.

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

Bytes returns the written bytes (up to the last written bit).

func (*Encoder) WriteBits

func (e *Encoder) WriteBits(v uint64, n int) error

WriteBits writes the lowest n bits of v (1 <= n <= 64) MSB-first.

func (*Encoder) WriteBytes

func (e *Encoder) WriteBytes(p []byte) error

WriteBytes writes a whole byte slice at the current byte-aligned position.

Jump to

Keyboard shortcuts

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