binary

package
v0.0.0-...-2b55090 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0, MIT Imports: 4 Imported by: 7

Documentation

Overview

Package binary translates between select fixed-sized types and a binary representation.

Index

Constants

This section is empty.

Variables

View Source
var BigEndian = binary.BigEndian

BigEndian is the same as encoding/binary.BigEndian.

It is included here as a convenience.

View Source
var LittleEndian = binary.LittleEndian

LittleEndian is the same as encoding/binary.LittleEndian.

It is included here as a convenience.

Functions

func AlignDown

func AlignDown(length int, align uint) int

AlignDown rounds a length down to an alignment. align must be a power of 2.

func AlignUp

func AlignUp(length int, align uint) int

AlignUp rounds a length up to an alignment. align must be a power of 2.

func AppendUint16

func AppendUint16(buf []byte, order binary.ByteOrder, num uint16) []byte

AppendUint16 appends the binary representation of a uint16 to buf.

func AppendUint32

func AppendUint32(buf []byte, order binary.ByteOrder, num uint32) []byte

AppendUint32 appends the binary representation of a uint32 to buf.

func AppendUint64

func AppendUint64(buf []byte, order binary.ByteOrder, num uint64) []byte

AppendUint64 appends the binary representation of a uint64 to buf.

func Marshal

func Marshal(buf []byte, order binary.ByteOrder, data any) []byte

Marshal appends a binary representation of data to buf.

data must only contain fixed-length signed and unsigned ints, arrays, slices, structs and compositions of said types. data may be a pointer, but cannot contain pointers.

func ReadUint16

func ReadUint16(r io.Reader, order binary.ByteOrder) (uint16, error)

ReadUint16 reads a uint16 from r.

func ReadUint32

func ReadUint32(r io.Reader, order binary.ByteOrder) (uint32, error)

ReadUint32 reads a uint32 from r.

func ReadUint64

func ReadUint64(r io.Reader, order binary.ByteOrder) (uint64, error)

ReadUint64 reads a uint64 from r.

func Size

func Size(v any) uintptr

Size calculates the buffer sized needed by Marshal or Unmarshal.

Size only support the types supported by Marshal.

func Unmarshal

func Unmarshal(buf []byte, order binary.ByteOrder, data any)

Unmarshal unpacks buf into data.

data must be a slice or a pointer and buf must have a length of exactly Size(data). data must only contain fixed-length signed and unsigned ints, arrays, slices, structs and compositions of said types.

func WriteUint16

func WriteUint16(w io.Writer, order binary.ByteOrder, num uint16) error

WriteUint16 writes a uint16 to w.

func WriteUint32

func WriteUint32(w io.Writer, order binary.ByteOrder, num uint32) error

WriteUint32 writes a uint32 to w.

func WriteUint64

func WriteUint64(w io.Writer, order binary.ByteOrder, num uint64) error

WriteUint64 writes a uint64 to w.

Types

This section is empty.

Jump to

Keyboard shortcuts

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