serde

package
v0.3.0-prerelease.5 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package serde contains interfaces used for serialization and deserialization throughout the eventually library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

type Bytes[Src any] interface {
	Serde[Src, []byte]
}

Bytes is a Serde implementation used to serialize a Source type to and deserialize it from a byte array.

type BytesDeserializer

type BytesDeserializer[Src any] interface {
	Deserializer[Src, []byte]
}

BytesDeserializer is a specialized Deserializer to deserialize a Source type from a byte array.

type BytesSerializer

type BytesSerializer[Src any] interface {
	Serializer[Src, []byte]
}

BytesSerializer is a specialized Serializer to serialize a Source type into a byte array.

type Chained

type Chained[Src any, Mid any, Dst any] struct {
	// contains filtered or unexported fields
}

Chained is a serde type that allows to chain two separate serdes, to map from an Src to a Dst type, using a common supporting type in the middle (Mid).

func Chain

func Chain[Src any, Mid any, Dst any](first Serde[Src, Mid], second Serde[Mid, Dst]) Chained[Src, Mid, Dst]

Chain chains together two serdes to build a new serde instance to map from Src to Dst types.

func (Chained[Src, Mid, Dst]) Deserialize

func (s Chained[Src, Mid, Dst]) Deserialize(dst Dst) (Src, error)

Deserialize implements the serde.Deserializer interface.

func (Chained[Src, Mid, Dst]) Serialize

func (s Chained[Src, Mid, Dst]) Serialize(src Src) (Dst, error)

Serialize implements the serde.Serializer interface.

type Deserializer

type Deserializer[Src any, Dst any] interface {
	Deserialize(dst Dst) (Src, error)
}

Deserializer is used to deserialize a Source type from another Destination type.

type DeserializerFunc

type DeserializerFunc[Src any, Dst any] func(dst Dst) (Src, error)

DeserializerFunc is a functional implementation of the Deserializer interface.

func AsDeserializerFunc

func AsDeserializerFunc[Src, Dst any](f func(dst Dst) (Src, error)) DeserializerFunc[Src, Dst]

AsDeserializerFunc casts the given deserialization function into a compatible Deserializer interface type.

func AsInfallibleDeserializerFunc

func AsInfallibleDeserializerFunc[Src, Dst any](f func(dst Dst) Src) DeserializerFunc[Src, Dst]

AsInfallibleDeserializerFunc casts the given infallible deserialization function into a compatible Deserializer interface type.

func NewJSONDeserializer

func NewJSONDeserializer[T any](factory func() T) DeserializerFunc[T, []byte]

NewJSONDeserializer returns a deserializer function where a byte-array is deserialized into the specified data type.

A data factory function is required for creating new instances of the type (especially if pointer semantics is used).

func NewProtoDeserializer

func NewProtoDeserializer[T proto.Message](factory func() T) DeserializerFunc[T, []byte]

NewProtoDeserializer returns a deserializer function where a byte-array is deserialized into a destination data type (T) using Protobuf.

A data factory function is required for creating new instances of type `T` (especially if pointer semantics is used).

func NewProtoJSONDeserializer

func NewProtoJSONDeserializer[T proto.Message](factory func() T) DeserializerFunc[T, []byte]

NewProtoJSONDeserializer returns a deserializer function where a byte-array is deserialized into a destination model type (T) using Protobuf JSON.

A data factory function is required for creating new instances of type `T` (especially if pointer semantics is used).

func (DeserializerFunc[Src, Dst]) Deserialize

func (fn DeserializerFunc[Src, Dst]) Deserialize(dst Dst) (Src, error)

Deserialize implements the serde.Deserializer interface.

type Fused

type Fused[Src any, Dst any] struct {
	Serializer[Src, Dst]
	Deserializer[Src, Dst]
}

Fused provides a convenient way to fuse together different implementations of a Serializer and Deserializer, and use it as a Serde.

func Fuse

func Fuse[Src, Dst any](serializer Serializer[Src, Dst], deserializer Deserializer[Src, Dst]) Fused[Src, Dst]

Fuse combines two given Serializer and Deserializer with compatible types and returns a Serde implementation through serde.Fused.

func NewJSON

func NewJSON[T any](factory func() T) Fused[T, []byte]

NewJSON returns a new serde instance where some data (`T`) gets serialized to and deserialized from JSON as byte-array.

func NewProto

func NewProto[T proto.Message](factory func() T) Fused[T, []byte]

NewProto returns a new serde instance where some data (`T`) gets serialized to and deserialized from a Protobuf byte-array.

func NewProtoJSON

func NewProtoJSON[T proto.Message](factory func() T) Fused[T, []byte]

NewProtoJSON returns a new serde instance where some data (`T`) gets serialized to and deserialized from Protobuf JSON.

type Serde

type Serde[Src any, Dst any] interface {
	Serializer[Src, Dst]
	Deserializer[Src, Dst]
}

Serde is used to serialize and deserialize from a Source to a Destination type.

type Serializer

type Serializer[Src any, Dst any] interface {
	Serialize(src Src) (Dst, error)
}

Serializer is used to serialize a Source type into another Destination type.

type SerializerFunc

type SerializerFunc[Src any, Dst any] func(src Src) (Dst, error)

SerializerFunc is a functional implementation of the Serializer interface.

func AsInfallibleSerializerFunc

func AsInfallibleSerializerFunc[Src, Dst any](f func(src Src) Dst) SerializerFunc[Src, Dst]

AsInfallibleSerializerFunc casts the given infallible serialization function into a compatible Serializer interface type.

func AsSerializerFunc

func AsSerializerFunc[Src, Dst any](f func(src Src) (Dst, error)) SerializerFunc[Src, Dst]

AsSerializerFunc casts the given serialization function into a compatible Serializer interface type.

func NewJSONSerializer

func NewJSONSerializer[T any]() SerializerFunc[T, []byte]

NewJSONSerializer returns a serializer function where the input data (Src) gets serialized to JSON byte-array data.

func NewProtoJSONSerializer

func NewProtoJSONSerializer[T proto.Message]() SerializerFunc[T, []byte]

NewProtoJSONSerializer returns a serializer function where the input data (T) gets serialized to Protobuf JSON byte-array data.

func NewProtoSerializer

func NewProtoSerializer[T proto.Message]() SerializerFunc[T, []byte]

NewProtoSerializer returns a serializer function where the input data (T) gets serialized to Protobuf byte-array.

func (SerializerFunc[Src, Dst]) Serialize

func (fn SerializerFunc[Src, Dst]) Serialize(src Src) (Dst, error)

Serialize implements the serde.Serializer interface.

Jump to

Keyboard shortcuts

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