binp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Len

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

Type for handling length fields.

type Parser

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

Parser type. Don't touch the internals.

func NewParser

func NewParser(b []byte) *Parser

Create a new parser with the given buffer. Panics on error.

func (*Parser) Align

func (p *Parser) Align(n int) *Parser

Ensure the input is aligned possibly skipping bytes.

func (*Parser) AtEnd

func (p *Parser) AtEnd() bool

Check that we are at the end of input.

func (*Parser) B16

func (p *Parser) B16(d *uint16) *Parser

Parse 2 bigendian bytes from the buffer.

func (*Parser) B16String

func (p *Parser) B16String(d *string) *Parser

Parse a string with a 2 byte bigendian length prefix to a string pointer.

func (*Parser) B32

func (p *Parser) B32(d *uint32) *Parser

Parse 4 bigendian bytes from the buffer.

func (*Parser) B32Bytes

func (p *Parser) B32Bytes(d *[]byte) *Parser

Parse a string with a 4 byte bigendian length prefix to a []byte pointer.

func (*Parser) B32String

func (p *Parser) B32String(d *string) *Parser

Parse a string with a 4 byte bigendian length prefix to a string pointer.

func (*Parser) B64

func (p *Parser) B64(d *uint64) *Parser

Parse 8 bigendian bytes from the buffer.

func (*Parser) B8

func (p *Parser) B8(d *byte) *Parser

Parse a byte from the buffer, synonym for .Byte.

func (*Parser) B8String

func (p *Parser) B8String(d *string) *Parser

Parse a string with a 1 byte length prefix to a string pointer.

func (*Parser) Byte

func (p *Parser) Byte(d *byte) *Parser

Parse a byte from the buffer.

func (*Parser) Bytes

func (p *Parser) Bytes(n int, d *[]byte) *Parser

Parse n bytes from the buffer and copy to a []byte pointer that is allocated.

func (*Parser) BytesCopy

func (p *Parser) BytesCopy(n int, d []byte) *Parser

Parse n bytes from the buffer and copy to the supplied []byte.

func (*Parser) BytesPeek

func (p *Parser) BytesPeek(n int, d *[]byte) *Parser

Parse n bytes from the buffer to a []byte pointer that refers to the parser internal buffer.

func (*Parser) End

func (p *Parser) End() error

Check that we are at the end of input.

func (*Parser) PeekRest

func (p *Parser) PeekRest(d *[]byte) *Parser

Peek the rest of input as raw bytes.

func (*Parser) Skip

func (p *Parser) Skip(n int) *Parser

Skip bytes.

func (*Parser) String

func (p *Parser) String(n int, d *string) *Parser

Parse n bytes from the buffer to a string pointer.

func (*Parser) String0

func (p *Parser) String0(d *string) *Parser

Parse a null terminated string.

type Printer

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

Printer type. Don't touch the internals.

func Out

func Out() *Printer

Create a new printer with empty output.

func OutCap

func OutCap(initialcap int) *Printer

Create a new printer with an empty slice with the capacity given below.

func OutWith

func OutWith(b []byte) *Printer

Create a new printer with output prefixed with the given byte slice.

func (*Printer) Align

func (p *Printer) Align(n int) *Printer

Align to boundary

func (*Printer) B16

func (p *Printer) B16(d uint16) *Printer

Output 2 bigendian bytes.

func (*Printer) B16String

func (p *Printer) B16String(d string) *Printer

Output a string with a 2 byte bigendian length prefix and no trailing null.

func (*Printer) B32

func (p *Printer) B32(d uint32) *Printer

Output 4 bigendian bytes.

func (*Printer) B32Bytes

func (p *Printer) B32Bytes(d []byte) *Printer

Output bytes with a 4 byte bigendian length prefix and no trailing null.

func (*Printer) B32String

func (p *Printer) B32String(d string) *Printer

Output a string with a 4 byte bigendian length prefix and no trailing null.

func (*Printer) B64

func (p *Printer) B64(d uint64) *Printer

Output 4 bigendian bytes.

func (*Printer) B8

func (p *Printer) B8(d byte) *Printer

Output a byte, synonym for .Byte.

func (*Printer) B8String

func (p *Printer) B8String(d string) *Printer

Output a string with a 1 byte bigendian length prefix and no trailing null.

func (*Printer) Byte

func (p *Printer) Byte(d byte) *Printer

Output a byte.

func (*Printer) Bytes

func (p *Printer) Bytes(d []byte) *Printer

Output a raw byte slice with no length prefix.

func (*Printer) LenB16

func (p *Printer) LenB16(l *Len) *Printer

Add a 16 bit field at the current location that will be filled with the length.

func (*Printer) LenB32

func (p *Printer) LenB32(l *Len) *Printer

Add a 32 bit field at the current location that will be filled with the length.

func (*Printer) LenDone

func (p *Printer) LenDone(l *Len) *Printer

Fill fields associated with this length with the current offset.

func (*Printer) LenStart

func (p *Printer) LenStart(l *Len) *Printer

Start counting bytes for the length field in question.

func (*Printer) LensDone

func (p *Printer) LensDone(ls ...*Len) *Printer

Call LenDone for all the arguments

func (*Printer) Out

func (p *Printer) Out() []byte

Get the output as a byte slice.

func (*Printer) Skip

func (p *Printer) Skip(n int) *Printer

Skip (zero-fill) some bytes.

func (*Printer) String

func (p *Printer) String(d string) *Printer

Output a raw string with no length prefix.

func (*Printer) String0

func (p *Printer) String0(d string) *Printer

Output a string terminated by a null-byte

Jump to

Keyboard shortcuts

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