binp

package module
v0.0.0-...-983014b Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2016 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

The binp package provides parsing and printing of binary values. It is particularly suitable for parsing irregular data structures provided by e.g. kernel.

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 Native

type Native struct{}
var NativeEndian Native

func (Native) PutUint16

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

func (Native) PutUint32

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

func (Native) PutUint64

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

func (Native) Uint16

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

func (Native) Uint32

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

func (Native) Uint64

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

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) 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) 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) Byte

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

Parse a byte from the buffer.

func (*Parser) End

func (p *Parser) End() error

Check that we are at the end of input.

func (*Parser) N8

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

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

func (*Parser) N8String

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

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

func (*Parser) N16

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

Parse 2 native endian bytes from the buffer.

func (*Parser) N16String

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

Parse a string with a 2 byte native endian length prefix to a string pointer.

func (*Parser) N32

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

Parse 4 native endian bytes from the buffer.

func (*Parser) N32Bytes

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

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

func (*Parser) N32String

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

Parse a string with a 4 byte native endian length prefix to a string pointer.

func (*Parser) N64

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

Parse 8 native endian bytes from the buffer.

func (*Parser) NBytes

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

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

func (*Parser) NBytesCopy

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

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

func (*Parser) NBytesPeek

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

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

func (*Parser) NString

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

Parse n bytes from the buffer to a string pointer.

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) 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) 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) 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) 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) LenN16

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

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

func (*Printer) LenN32

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

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

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) N8

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

Output a byte, synonym for .Byte.

func (*Printer) N8String

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

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

func (*Printer) N16

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

Output 2 native endian bytes.

func (*Printer) N16String

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

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

func (*Printer) N32

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

Output 4 native endian bytes.

func (*Printer) N32Bytes

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

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

func (*Printer) N32String

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

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

func (*Printer) N64

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

Output 4 native endian bytes.

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