perunio

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Overview

Package perunio contains functionality for the serialization of standard Go types.

Index

Constants

View Source
const MaxBigIntLength = 128

MaxBigIntLength defines the maximum length of a big integer. 1024bit -> 128 bytes.

Variables

This section is empty.

Functions

func Decode

func Decode(reader io.Reader, values ...interface{}) (err error)

Decode decodes multiple primitive values from a reader. All passed values must be references, not copies.

func Encode

func Encode(writer io.Writer, values ...interface{}) (err error)

Encode encodes multiple primitive values into a writer. All passed values must be copies, not references.

func EqualBinary

func EqualBinary(a, b encoding.BinaryMarshaler) (bool, error)

EqualBinary returns whether the binary representation of the two values `a` and `b` are equal. It returns an error when marshalling fails.

func EqualEncoding

func EqualEncoding(a, b Encoder) (bool, error)

EqualEncoding returns whether the two Encoders `a` and `b` encode to the same byteslice or an error when the encoding failed.

Types

type BigInt

type BigInt struct {
	*big.Int
}

BigInt is a serializer big integer.

func (*BigInt) Decode

func (b *BigInt) Decode(reader io.Reader) error

Decode reads a big.Int from the given stream.

func (BigInt) Encode

func (b BigInt) Encode(writer io.Writer) error

Encode writes a big.Int to the stream.

type ByteSlice

type ByteSlice []byte

ByteSlice is a serializer byte slice.

func (*ByteSlice) Decode

func (b *ByteSlice) Decode(r io.Reader) error

Decode reads a byte slice from the given stream. Decode reads exactly len(b) bytes. This means the caller has to specify how many bytes he wants to read.

func (ByteSlice) Encode

func (b ByteSlice) Encode(w io.Writer) error

Encode writes len(b) bytes to the stream. Note that the length itself is not written to the stream.

type Decoder

type Decoder interface {
	// Decode reads an object from a stream.
	// If the stream fails, the underlying error is returned.
	Decode(io.Reader) error
}

A Decoder can decode itself from a stream.

type Encoder

type Encoder interface {
	// Encode writes itself to a stream.
	// If the stream fails, the underlying error is returned.
	Encode(io.Writer) error
}

An Encoder can encode itself into a stream.

type Serializer

type Serializer interface {
	Encoder
	Decoder
}

Serializer objects can be serialized into and from streams.

Directories

Path Synopsis
Package serializer implements the wire serializer interface using the perunio encoding format.
Package serializer implements the wire serializer interface using the perunio encoding format.
Package test contains test helper functions for running generic tests for types implementing perunio serializer.
Package test contains test helper functions for running generic tests for types implementing perunio serializer.

Jump to

Keyboard shortcuts

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