packetmaker

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MIT Imports: 2 Imported by: 0

README

packetmaker

A low allocation, lightweight way to generate packets in the Go programming language. This exists because doing standard byte array slicing is complex and very error-prone, and I wanted a simple way to write packets efficiently (the other way I was using was append, but this sucks for other memory management reasons).

API usage

The API is documented on GoDoc here and should contain everything you need to make packets (if there is anything missing you need, feel free to make an issue/PR!). These functions are designed to be chained, for example packetmaker.New().String("abc").Uint64(12, true).Make().

Note on Big Endian systems

This library is heavily unit tested to ensure its reliability on little endian systems (most systems you would use come under this, like x86_64/arm64), although the Int functions (not the unsigned ones) are unknown if they work on big endian since they use unsafe. Feel free to make an issue if you get weird results with this (or if it works, I'd love to know!), you will not ever get unsafe results back, but there is a slight chance they might be incorrect.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Maker

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

Maker is used to define the packet maker.

func New

func New() *Maker

New is used to create a new packet maker.

func (*Maker) Byte

func (m *Maker) Byte(b uint8) *Maker

Byte is used to add a single byte to the packet.

func (*Maker) Bytes

func (m *Maker) Bytes(b []byte) *Maker

Bytes is used to add the specified byte slice to the packet. Note the length of the slice CANNOT change after this is set. Doing so will result in undefined behaviour.

func (*Maker) Int16

func (m *Maker) Int16(v int16, littleEndian bool) *Maker

Int16 is used to add an 16-bit signed integer.

func (*Maker) Int32

func (m *Maker) Int32(v int32, littleEndian bool) *Maker

Int32 is used to add an 32-bit signed integer.

func (*Maker) Int64

func (m *Maker) Int64(v int64, littleEndian bool) *Maker

Int64 is used to add an 64-bit signed integer.

func (*Maker) Make

func (m *Maker) Make() []byte

Make is used to make the packet.

func (*Maker) String

func (m *Maker) String(s string) *Maker

String is used to add a string to the packet.

func (*Maker) Uint16

func (m *Maker) Uint16(v uint16, littleEndian bool) *Maker

Uint16 is used to add an 16-bit unsigned integer.

func (*Maker) Uint32

func (m *Maker) Uint32(v uint32, littleEndian bool) *Maker

Uint32 is used to add an 32-bit unsigned integer.

func (*Maker) Uint64

func (m *Maker) Uint64(v uint64, littleEndian bool) *Maker

Uint64 is used to add an 64-bit unsigned integer.

Jump to

Keyboard shortcuts

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