Documentation ¶
Overview ¶
Package serde contains interfaces used for serialization and deserialization throughout the eventually library.
Index ¶
- type Bytes
- type BytesDeserializer
- type BytesSerializer
- type Chained
- type Deserializer
- type DeserializerFunc
- func AsDeserializerFunc[Src, Dst any](f func(dst Dst) (Src, error)) DeserializerFunc[Src, Dst]
- func AsInfallibleDeserializerFunc[Src, Dst any](f func(dst Dst) Src) DeserializerFunc[Src, Dst]
- func NewJSONDeserializer[T any](factory func() T) DeserializerFunc[T, []byte]
- func NewProtoDeserializer[T proto.Message](factory func() T) DeserializerFunc[T, []byte]
- func NewProtoJSONDeserializer[T proto.Message](factory func() T) DeserializerFunc[T, []byte]
- type Fused
- func Fuse[Src, Dst any](serializer Serializer[Src, Dst], deserializer Deserializer[Src, Dst]) Fused[Src, Dst]
- func NewJSON[T any](factory func() T) Fused[T, []byte]
- func NewProto[T proto.Message](factory func() T) Fused[T, []byte]
- func NewProtoJSON[T proto.Message](factory func() T) Fused[T, []byte]
- type Serde
- type Serializer
- type SerializerFunc
- func AsInfallibleSerializerFunc[Src, Dst any](f func(src Src) Dst) SerializerFunc[Src, Dst]
- func AsSerializerFunc[Src, Dst any](f func(src Src) (Dst, error)) SerializerFunc[Src, Dst]
- func NewJSONSerializer[T any]() SerializerFunc[T, []byte]
- func NewProtoJSONSerializer[T proto.Message]() SerializerFunc[T, []byte]
- func NewProtoSerializer[T proto.Message]() SerializerFunc[T, []byte]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bytes ¶
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 ¶
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 ¶
Deserialize implements the serde.Deserializer interface.
type Deserializer ¶
Deserializer is used to deserialize a Source type from another Destination type.
type DeserializerFunc ¶
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 ¶
NewJSON returns a new serde instance where some data (`T`) gets serialized to and deserialized from JSON as byte-array.
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 ¶
Serializer is used to serialize a Source type into another Destination type.
type SerializerFunc ¶
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.