serial

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package serial provides serialization utilities for nested serialization.

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) *ByteStore

NewByteStoreFromData returns a new ByteStore instance wrapping the provided data.

func (*ByteStore) Data

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

Data returns the current data 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) CurPos added in v1.4.0

func (coder *Decoder) CurPos() uint32

CurPos returns the current decoding position, in bytes.

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) CurPos added in v1.4.0

func (coder *Encoder) CurPos() uint32

CurPos returns the current encoding position, in bytes.

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 PositioningDecoder from given reader.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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