util

package
v0.0.0-...-b41cad7 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadRead = errors.New("bad read")

ErrBadRead is the error that occurs when reading from BadReader.

View Source
var ErrBadWrite = errors.New("bad write")

ErrBadWrite is the error that occurs when writing to BadWriter.

Functions

func AllocAndPack

func AllocAndPack(inputs ...Packable) []byte

AllocAndPack allocates a buffer and then packs the data inside it.

func Log

func Log(value interface{}, format string, args ...interface{})

Log sends a message to the Logger.

func Pack

func Pack(buffer []byte, input interface{}) uint

Pack a value into the buffer.

func PackSome

func PackSome(buffer []byte, inputs ...interface{})

PackSome packs multiple values.

func PackString

func PackString(buffer []byte, maxLen uint, input string) (uint, error)

PackString packs a string into the buffer

func Unpack

func Unpack(data []byte, output interface{}) (uint, error)

Unpack the byte slice to the given value.

func UnpackSome

func UnpackSome(data []byte, outputs ...interface{}) (uint, error)

UnpackSome unpacks multiple values.

func UnpackString

func UnpackString(buffer []byte, len uint, output *string) (uint, error)

UnpackString unpacks a string

Types

type BadReader

type BadReader struct{}

BadReader is a Reader that always fails.

func (BadReader) Read

func (BadReader) Read([]byte) (int, error)

Read implements the Reader Read method.

type BadWriter

type BadWriter struct{}

BadWriter is a Writer that always fails.

func (BadWriter) Write

func (BadWriter) Write([]byte) (int, error)

Write implements the Writer Write method.

type LogTarget

type LogTarget interface {
	Printf(format string, args ...interface{})
}

A LogTarget is used to log certain messages.

var Logger LogTarget

Logger is the log target for asynchronous and non-critical errors.

type Packable

type Packable interface {
	Size() uint
	Pack(buffer []byte)
}

Packable is implemented by types that can be packed into a byte slice.

type Unpackable

type Unpackable interface {
	Unpack(data []byte) (uint, error)
}

Unpackable is implemented by types that can be initialized by reading from a byte slice.

Jump to

Keyboard shortcuts

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