serial

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTypes

func RegisterTypes(typeRegistrar TypeRegistrar, zeroValues ...interface{}) error

RegisterTypes is a helper to register multiple types in one call.

Types

type Deserializer

type Deserializer interface {
	Deserialize(interface{}, []byte) error
}

Deserializer takes an interface and a serialization of the underlying type and populates the interface from the data.

type Detyper

type Detyper interface {
	GetType(data []byte) (t reflect.Type, rest []byte, err error)
}

Detyper takes in serialized data and returns the type of the data and the rest of the data (minus the type information).

type InterfaceDeserializer

type InterfaceDeserializer interface {
	Deserialize(interface{}, []byte) error
}

InterfaceDeserializer is what is provided by the json and gob libraries, the ability to populate an interface from a byte slice.

type InterfaceTypePrefixer

type InterfaceTypePrefixer interface {
	PrefixInterfaceType(interface{}, []byte) ([]byte, error)
}

InterfaceTypePrefixer writes the type of the interface to slice. Generally this will end up effectivly prefixing the type.

type PrefixDeserializer

type PrefixDeserializer struct {
	Detyper
	Deserializer
}

PrefixDeserializer handles both deserializing the type and the data. This allows a byte slice to be passed in an the interface returned as opposed to the normal requirement of passing in both an interface and a slice.

func (PrefixDeserializer) DeserializeType

func (ds PrefixDeserializer) DeserializeType(data []byte) (interface{}, error)

DeserializeType gets the type from the data, creates an instance and then deserializes the data into that instance.

type PrefixSerializer

type PrefixSerializer struct {
	InterfaceTypePrefixer
	Serializer
}

PrefixSerializer combines a Prefixer and a Serializer to create a TypeSerializer.

func (PrefixSerializer) SerializeType

func (ps PrefixSerializer) SerializeType(i interface{}, b []byte) ([]byte, error)

SerializeType fulfills TypeSerializer using the underlying InterfaceTypePrefixer to prefix a type and the Serializer to serialize the data.

type ReaderDeserializer

type ReaderDeserializer func(interface{}, io.Reader) error

ReaderDeserializer serializes the provided interface to the Reader.

func (ReaderDeserializer) Deserialize

func (fn ReaderDeserializer) Deserialize(i interface{}, b []byte) error

Deserialize the interface from the byte slice.

type ReflectTypePrefixer

type ReflectTypePrefixer interface {
	PrefixReflectType(reflect.Type, []byte) ([]byte, error)
}

ReflectTypePrefixer writes a reflect.Type to slice. Generally this will end up effectivly prefixing the type.

type Serializer

type Serializer interface {
	Serialize(interface{}, []byte) ([]byte, error)
}

Serializer takes an interface and returns the serialization as a byte slice.

type TypeDeserializer

type TypeDeserializer interface {
	DeserializeType([]byte) (interface{}, error)
}

TypeDeserializer can infer the type from the message. It can take a byte slice and return an interface containing an instance to the value represented by the serialized data.

type TypePrefixer

type TypePrefixer interface {
	ReflectTypePrefixer
	InterfaceTypePrefixer
}

TypePrefixer combines both TypePrefixing techniques.

func WrapPrefixer

func WrapPrefixer(pre ReflectTypePrefixer) TypePrefixer

WrapPrefixer takes a ReflectTypePrefixer and wraps it with logic to add PrefixInterfaceType there by fulfilling TypePrefixer. This makes it easy to fulfill any type of prefixer by just fulfilling ReflectTypePrefixer.

type TypeRegistrar

type TypeRegistrar interface {
	RegisterType(zeroValue interface{}) error
}

TypeRegistrar is generally required for automatic deserialization. A zeroValue is provided (for instance a nil pointer) to register a type that can then be deserialized.

type TypeSerializer

type TypeSerializer interface {
	SerializeType(interface{}, []byte) ([]byte, error)
}

TypeSerializer takes an interface and returns the serialization as a byte slice that includes the type data.

type WriterSerializer

type WriterSerializer func(interface{}, io.Writer) error

WriterSerializer serializes the provided interface to the Writer.

func (WriterSerializer) Serialize

func (fn WriterSerializer) Serialize(i interface{}, b []byte) ([]byte, error)

Serialize the interface to the byte slice.

Directories

Path Synopsis
rye
Package rye is a helper for writing serializing and deserializing logic.
Package rye is a helper for writing serializing and deserializing logic.
wrap
gob

Jump to

Keyboard shortcuts

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