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.
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.
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.