serdes

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package serdes provides different serialization and deserialization implementations using the serde.Serde interface found in the core module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJSON

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

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

func NewJSONDeserializer

func NewJSONDeserializer[T any](factory func() T) serde.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 NewJSONSerializer

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

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

func NewProto

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

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

func NewProtoDeserializer

func NewProtoDeserializer[T proto.Message](factory func() T) serde.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 NewProtoJSON

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

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

func NewProtoJSONDeserializer

func NewProtoJSONDeserializer[T proto.Message](factory func() T) serde.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 NewProtoJSONSerializer

func NewProtoJSONSerializer[T proto.Message]() serde.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]() serde.SerializerFunc[T, []byte]

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

Types

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.Serde[Src, Mid],
	second serde.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.

Jump to

Keyboard shortcuts

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