serial

package
v0.0.0-...-e78e2ff Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2018 License: BSD-3-Clause Imports: 3 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteStore

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

ByteStore is implementing a ReadWriteSeeker storing data in memory.

func NewByteStore

func NewByteStore() *ByteStore

NewByteStore returns a new byte store instance

func NewByteStoreFromData

func NewByteStoreFromData(data []byte, onClose func([]byte)) *ByteStore

NewByteStoreFromData returns a new ByteStore instance wrapping the provided data.

func (*ByteStore) Close

func (store *ByteStore) Close() error

Close implements the Closer interface.

func (*ByteStore) Data

func (store *ByteStore) Data() []byte

Data returns the current data buffer

func (*ByteStore) Len

func (store *ByteStore) Len() int

Len returns the current length of the buffer

func (*ByteStore) Read

func (store *ByteStore) Read(p []byte) (n int, err error)

Read implements the Reader interface

func (*ByteStore) Seek

func (store *ByteStore) Seek(offset int64, whence int) (int64, error)

Seek implements the Seeker interface

func (*ByteStore) Write

func (store *ByteStore) Write(p []byte) (n int, err error)

Write implements the Writer interface

type Codable

type Codable interface {
	// Code requests to serialize the Codable via the provided Coder.
	Code(coder Coder)
}

Codable is something than can be serialized with a Coder.

type Coder

type Coder interface {
	// FirstError returns the first error this coder encountered.
	FirstError() error

	// Code serializes the given value.
	// Any error state will be provided via FirstError(). Code will do nothing
	// if the coder is already in error state.
	Code(value interface{})
}

Coder represents an Encoder/Decoder for binary data.

type Decoder

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

Decoder is for decoding from a reader.

func NewDecoder

func NewDecoder(source io.Reader) *Decoder

NewDecoder creates a new Decoder from given source.

func (*Decoder) Code

func (coder *Decoder) Code(value interface{})

Code serializes the given value in little endian format using binary.Read().

func (*Decoder) FirstError

func (coder *Decoder) FirstError() error

FirstError returns the error this Decoder encountered the first time.

func (*Decoder) Read

func (coder *Decoder) Read(data []byte) (read int, err error)

Read reads the next bytes from the underlying source.

type Encoder

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

Encoder implements the Coder interface to write to a writer. It also implements the Writer interface.

func NewEncoder

func NewEncoder(target io.Writer) *Encoder

NewEncoder creates and returns a fresh Encoder.

func (*Encoder) Code

func (coder *Encoder) Code(value interface{})

Code serializes the given value in little endian format using binary.Write().

func (*Encoder) FirstError

func (coder *Encoder) FirstError() error

FirstError returns the error this Encoder encountered the first time.

func (*Encoder) Write

func (coder *Encoder) Write(data []byte) (written int, err error)

Write serializes the given data to the contained writer. If the encoder is in the error state, the result of FirstError() is returned and nothing else is done.

type Positioner

type Positioner interface {
	// CurPos gets the current position in the data.
	CurPos() uint32
	// SetCurPos sets the current position in the data.
	SetCurPos(offset uint32)
}

Positioner specifies a type that knows about a position which can be modified.

type PositioningCoder

type PositioningCoder interface {
	Positioner
	Coder
}

PositioningCoder is a coder that also knows about positioning. Any error state regarding repositioning will be provided via FirstError(). SetCurPos will do nothing if the coder is already in error state.

type PositioningDecoder

type PositioningDecoder struct {
	Decoder
	// contains filtered or unexported fields
}

PositioningDecoder is a Decoder with positioning capabilities.

func NewPositioningDecoder

func NewPositioningDecoder(source io.ReadSeeker) *PositioningDecoder

NewPositioningDecoder creates a new PositiongingDecoder from given reader.

func (*PositioningDecoder) CurPos

func (coder *PositioningDecoder) CurPos() uint32

CurPos returns the current decoding position, in bytes.

func (*PositioningDecoder) SetCurPos

func (coder *PositioningDecoder) SetCurPos(offset uint32)

SetCurPos changes the encoding position to the specified absolute offset.

type PositioningEncoder

type PositioningEncoder struct {
	Encoder
	// contains filtered or unexported fields
}

PositioningEncoder is an Encoder with positioning capabilities.

func NewPositioningEncoder

func NewPositioningEncoder(target io.WriteSeeker) *PositioningEncoder

NewPositioningEncoder returns an Encoder that also implements the Positioner interface. The new Encoder starts with its zero position at the current position in the writer.

func (*PositioningEncoder) CurPos

func (coder *PositioningEncoder) CurPos() uint32

CurPos returns the current encoding position, in bytes.

func (*PositioningEncoder) Seek

func (coder *PositioningEncoder) Seek(offset int64, whence int) (int64, error)

Seek repositions the current encoding offset. This implementation does not support a whence value of io.SeekEnd.

func (*PositioningEncoder) SetCurPos

func (coder *PositioningEncoder) SetCurPos(offset uint32)

SetCurPos changes the encoding position to the specified absolute offset.

type SeekingReadCloser

type SeekingReadCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

SeekingReadCloser combines the interfaces of a Reader, a Seeker and a Closer.

type SeekingWriteCloser

type SeekingWriteCloser interface {
	io.Writer
	io.Seeker
	io.Closer
}

SeekingWriteCloser combines the interfaces of a Writer, a Seeker and a Closer.

Jump to

Keyboard shortcuts

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