serializer

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package serializer provides serialization interfaces and implementations for converting Go values to and from byte slices. This package is designed to work with caching systems that need to store and retrieve arbitrary Go values.

The package includes a default JSON serializer implementation that uses the goccy/go-json library for efficient JSON marshaling and unmarshaling operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 (*DefaultJSONSerializer) Marshal(v any) ([]byte, error)

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

func (*DefaultJSONSerializer) Unmarshal

func (*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 using a new registry instance with default serializers. The serializerType parameter is used to select the serializer from the default serializers.

type MsgpackSerializer

type MsgpackSerializer struct{}

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

func (*MsgpackSerializer) Marshal

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

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

func (*MsgpackSerializer) Unmarshal

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

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

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages serializer constructors.

func NewEmptySerializerRegistry

func NewEmptySerializerRegistry() *Registry

NewEmptySerializerRegistry creates a new serializer registry without default serializers. This is useful for testing or when you want to register only specific serializers.

func NewSerializerRegistry

func NewSerializerRegistry() *Registry

NewSerializerRegistry creates a new serializer registry with default serializers pre-registered.

func (*Registry) New

func (r *Registry) New(serializerType string) (ISerializer, error)

New returns a new serializer based on the serializerType.

func (*Registry) Register

func (r *Registry) Register(serializerType string, createFunc func() ISerializer)

Register registers a new serializer with the given name.

Jump to

Keyboard shortcuts

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