wrappers

package
v1.10.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: BSD-3-Clause Imports: 6 Imported by: 338

Documentation

Index

Constants

View Source
const (
	MaxStringLen = math.MaxUint16

	// ByteLen is the number of bytes per byte...
	ByteLen = 1
	// ShortLen is the number of bytes per short
	ShortLen = 2
	// IntLen is the number of bytes per int
	IntLen = 4
	// LongLen is the number of bytes per long
	LongLen = 8
	// BoolLen is the number of bytes per bool
	BoolLen = 1
	// IPLen is the number of bytes per IP
	IPLen = 16 + ShortLen
)

Variables

View Source
var (
	ErrInsufficientLength = errors.New("packer has insufficient length for input")
)

Functions

func NewAggregate added in v1.7.10

func NewAggregate(errs []error) error

NewAggregate returns an aggregate error from a list of errors

func StringLen added in v1.9.5

func StringLen(str string) int

Types

type Closer added in v1.4.5

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

Closer is a nice utility for closing a group of objects while reporting an error if one occurs.

func (*Closer) Add added in v1.4.5

func (c *Closer) Add(closer io.Closer)

Add a new object to be closed.

func (*Closer) Close added in v1.4.5

func (c *Closer) Close() error

Close closes each of the closers add to [c] and returns the first error that occurs or nil if no error occurs.

type Errs

type Errs struct{ Err error }

func (*Errs) Add

func (errs *Errs) Add(errors ...error)

func (*Errs) Errored

func (errs *Errs) Errored() bool

type Packer

type Packer struct {
	Errs

	// The largest allowed size of expanding the byte array
	MaxSize int
	// The current byte array
	Bytes []byte
	// The offset that is being written to in the byte array
	Offset int
}

Packer packs and unpacks a byte array from/to standard values

func (*Packer) PackBool

func (p *Packer) PackBool(b bool)

PackBool packs a bool into the byte array

func (*Packer) PackByte

func (p *Packer) PackByte(val byte)

PackByte append a byte to the byte array

func (*Packer) PackBytes

func (p *Packer) PackBytes(bytes []byte)

PackBytes append a byte slice to the byte array

func (*Packer) PackFixedBytes

func (p *Packer) PackFixedBytes(bytes []byte)

PackFixedBytes append a byte slice, with no length descriptor to the byte array

func (*Packer) PackInt

func (p *Packer) PackInt(val uint32)

PackInt append an int to the byte array

func (*Packer) PackLong

func (p *Packer) PackLong(val uint64)

PackLong append a long to the byte array

func (*Packer) PackShort

func (p *Packer) PackShort(val uint16)

PackShort append a short to the byte array

func (*Packer) PackStr

func (p *Packer) PackStr(str string)

PackStr append a string to the byte array

func (*Packer) UnpackBool

func (p *Packer) UnpackBool() bool

UnpackBool unpacks a bool from the byte array

func (*Packer) UnpackByte

func (p *Packer) UnpackByte() byte

UnpackByte unpack a byte from the byte array

func (*Packer) UnpackBytes

func (p *Packer) UnpackBytes() []byte

UnpackBytes unpack a byte slice from the byte array

func (*Packer) UnpackFixedBytes

func (p *Packer) UnpackFixedBytes(size int) []byte

UnpackFixedBytes unpack a byte slice, with no length descriptor from the byte array

func (*Packer) UnpackInt

func (p *Packer) UnpackInt() uint32

UnpackInt unpack an int from the byte array

func (*Packer) UnpackLimitedBytes added in v1.9.5

func (p *Packer) UnpackLimitedBytes(limit uint32) []byte

UnpackLimitedBytes unpacks a byte slice. If the size of the slice is greater than [limit], adds [errOversized] to the packer and returns nil.

func (*Packer) UnpackLimitedStr added in v1.9.5

func (p *Packer) UnpackLimitedStr(limit uint16) string

UnpackLimitedStr unpacks a string. If the size of the string is greater than [limit], adds [errOversized] to the packer and returns the empty string.

func (*Packer) UnpackLong

func (p *Packer) UnpackLong() uint64

UnpackLong unpack a long from the byte array

func (*Packer) UnpackShort

func (p *Packer) UnpackShort() uint16

UnpackShort unpack a short from the byte array

func (*Packer) UnpackStr

func (p *Packer) UnpackStr() string

UnpackStr unpacks a string from the byte array

Jump to

Keyboard shortcuts

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