binary

package
v0.0.0-...-4950cc4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: ISC Imports: 3 Imported by: 0

Documentation

Overview

Package binary implements little-endian translation between 9P types and byte sequences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(data []byte, v interface{}) ([]byte, int, error)

Marshal encodes the binary representation of v to data.

func PutString

func PutString(data []byte, v string) []byte

PutString encodes a 16-bit count-delimited string to data. The returned slice may be a sub-slice of data if data was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil data.

func PutUint16

func PutUint16(data []byte, v uint16) []byte

PutUint16 encodes a unsigned 16-bit integer to data. The returned slice may be a sub-slice of data if data was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil data.

func PutUint32

func PutUint32(data []byte, v uint32) []byte

PutUint32 encodes a unsigned 32-bit integer to data. The returned slice may be a sub-slice of data if data was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil data.

func PutUint64

func PutUint64(data []byte, v uint64) []byte

PutUint64 encodes a unsigned 64-bit integer to data. The returned slice may be a sub-slice of data if data was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil data.

func PutUint8

func PutUint8(data []byte, v uint8) []byte

PutUint8 encodes a unsigned 8-bit integer to data. The returned slice may be a sub-slice of data if data was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil data.

func String

func String(data []byte) string

String decodes a 16-bit count-delimited string from data and returns the unread portion of data and a success indicator.

func Uint16

func Uint16(data []byte) uint16

Uint16 decodes a unsigned 16-bit integer from data.

func Uint32

func Uint32(data []byte) uint32

Uint32 decodes a unsigned 32-bit integer from data.

func Uint64

func Uint64(data []byte) uint64

Uint64 decodes a unsigned 64-bit integer from data.

func Uint8

func Uint8(data []byte) uint8

Uint8 decodes a unsigned 8-bit integer from data.

func Unmarshal

func Unmarshal(data []byte, v interface{}) ([]byte, error)

Unmarshal decodes the binary representation of v from data.

Types

type Buffer

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

Buffer is a variable-sized buffer of bytes used to encode and decode 9P primitives and messages.

func NewBuffer

func NewBuffer(data []byte) *Buffer

NewBuffer creates and initializes a new Buffer using data as its initial contents. The new Buffer takes ownership of data, and the caller should not use data after this call. NewBuffer is intended to prepare a Buffer to read existing data. It can also be used to size the internal buffer for writing. To do that, data should have the desired capacity but a length of zero.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns a slice of length Len() holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification.

func (*Buffer) Err

func (b *Buffer) Err() error

Err returns the first error that was encountered by Buffer.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes of the unread portion of Buffer.

func (*Buffer) PutString

func (b *Buffer) PutString(v string)

PutString encodes a 16-bit count-delimited string to Buffer.

func (*Buffer) PutUint16

func (b *Buffer) PutUint16(v uint16)

PutUint16 encodes a unsigned 16-bit integer to Buffer.

func (*Buffer) PutUint32

func (b *Buffer) PutUint32(v uint32)

PutUint32 encodes a unsigned 32-bit integer to Buffer.

func (*Buffer) PutUint64

func (b *Buffer) PutUint64(v uint64)

PutUint64 encodes a unsigned 64-bit integer to Buffer.

func (*Buffer) PutUint8

func (b *Buffer) PutUint8(v uint8)

PutUint8 encodes a unsigned 8-bit integer to Buffer.

func (*Buffer) Read

func (b *Buffer) Read(r io.Reader, size int) error

Read reads exactly size bytes from r into buffer. The error is io.EOF only if no bytes were read. If an io.EOF happens after reading some but not all the bytes, Read returns io.ErrUnexpectedEOF.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the buffer to be empty, but it retains the underlying storage for use by future.

func (*Buffer) String

func (b *Buffer) String() string

String decodes a 16-bit count-delimited string from Buffer.

func (*Buffer) Uint16

func (b *Buffer) Uint16() uint16

Uint16 decodes a 16-bit integer from Buffer.

func (*Buffer) Uint32

func (b *Buffer) Uint32() uint32

Uint32 decodes a 32-bit integer from Buffer.

func (*Buffer) Uint64

func (b *Buffer) Uint64() uint64

Uint64 decodes a 64-bit integer from Buffer.

func (*Buffer) Uint8

func (b *Buffer) Uint8() uint8

Uint8 decodes a 8-bit integer from Buffer.

type Marshaler

type Marshaler interface {
	Marshal([]byte) ([]byte, int, error)
}

Marshaler is the interface implemented by an object that can marshal itself into a binary form. Marshal encodes the receiver into a binary form and returns the result.

type Unmarshaler

type Unmarshaler interface {
	Unmarshal([]byte) ([]byte, error)
}

Unmarshaler is the interface implemented by an object that can unmarshal a binary representation of itself. Unmarshal must be able to decode the form generated by Marshal. Unmarshal must copy the data if it wishes to retain the data after returning.

Jump to

Keyboard shortcuts

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