serializer

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterSerializer

func RegisterSerializer(serializerType string, createFunc func() ISerializer)

RegisterSerializer registers a new serializer with the given name.

Types

type DefaultJSONSerializer

type DefaultJSONSerializer struct {
}

DefaultJSONSerializer leverages the default `json` to serialize the items before storing them in the cache

func (*DefaultJSONSerializer) Marshal

func (d *DefaultJSONSerializer) Marshal(v any) ([]byte, error)

Marshal serializes the given value into a byte slice. @param v

func (*DefaultJSONSerializer) Unmarshal

func (d *DefaultJSONSerializer) Unmarshal(data []byte, v any) error

Unmarshal deserializes the given byte slice into the given value. @param data @param v

type ISerializer

type ISerializer interface {
	// Marshal serializes the given value into a byte slice.
	Marshal(v any) ([]byte, error)
	// Unmarshal deserializes the given byte slice into the given value.
	Unmarshal(data []byte, v any) error
}

ISerializer is the interface that wraps the basic serializer methods.

func New

func New(serializerType string) (ISerializer, error)

New returns a new serializer based on the serializerType.

type MsgpackSerializer

type MsgpackSerializer struct {
}

MsgpackSerializer leverages `msgpack` to serialize the items before storing them in the cache

func (*MsgpackSerializer) Marshal

func (d *MsgpackSerializer) Marshal(v any) ([]byte, error)

Marshal serializes the given value into a byte slice. @param v

func (*MsgpackSerializer) Unmarshal

func (d *MsgpackSerializer) Unmarshal(data []byte, v any) error

Unmarshal deserializes the given byte slice into the given value. @param data @param v

Jump to

Keyboard shortcuts

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