Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompressedSerializer ¶
type CompressedSerializer struct {
// contains filtered or unexported fields
}
CompressedSerializer wraps another serializer and compresses the output.
func NewCompressedSerializer ¶
func NewCompressedSerializer(inner Serializer, compressor compression.Compressor) *CompressedSerializer
NewCompressedSerializer creates a new CompressSerializer.
func (*CompressedSerializer) Marshal ¶
func (s *CompressedSerializer) Marshal(v interface{}) ([]byte, error)
Marshal marshals the value using the inner serializer and then compresses it.
func (*CompressedSerializer) Name ¶
func (s *CompressedSerializer) Name() string
Name returns the name of the inner serializer combined with "compressed".
func (*CompressedSerializer) Unmarshal ¶
func (s *CompressedSerializer) Unmarshal(data []byte, v interface{}) error
Unmarshal decompresses the data and then unmarshals it using the inner serializer.
type Envelope ¶
type Envelope struct {
Type string `json:"type" msgpack:"type"`
Value interface{} `json:"value" msgpack:"value"`
}
Envelope wraps values with type information for safe deserialization. This allows the cache to store the type alongside the value.
type JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer implements the Serializer interface using JSON encoding. It provides human-readable serialization with type preservation.
func NewJSONSerializer ¶
func NewJSONSerializer() *JSONSerializer
NewJSONSerializer creates a new JSON serializer.
func (*JSONSerializer) Marshal ¶
func (s *JSONSerializer) Marshal(v interface{}) ([]byte, error)
Marshal converts a Go value to JSON bytes with type information.
func (*JSONSerializer) Name ¶
func (s *JSONSerializer) Name() string
Name returns the serializer name.
func (*JSONSerializer) Unmarshal ¶
func (s *JSONSerializer) Unmarshal(data []byte, v interface{}) error
Unmarshal converts JSON bytes back to a Go value.
type MsgpackSerializer ¶
type MsgpackSerializer struct{}
MsgpackSerializer implements the Serializer interface using MessagePack encoding. It provides faster, more compact serialization compared to JSON.
func NewMsgpackSerializer ¶
func NewMsgpackSerializer() *MsgpackSerializer
NewMsgpackSerializer creates a new msgpack serializer.
func (*MsgpackSerializer) Marshal ¶
func (s *MsgpackSerializer) Marshal(v interface{}) ([]byte, error)
Marshal converts a Go value to msgpack bytes with type information.
func (*MsgpackSerializer) Name ¶
func (s *MsgpackSerializer) Name() string
Name returns the serializer name.
func (*MsgpackSerializer) Unmarshal ¶
func (s *MsgpackSerializer) Unmarshal(data []byte, v interface{}) error
Unmarshal converts msgpack bytes back to a Go value.
type Serializer ¶
type Serializer interface {
// Marshal converts a Go value to bytes for storage.
Marshal(v interface{}) ([]byte, error)
// Unmarshal converts bytes back to a Go value.
// The result is stored in the value pointed to by v.
Unmarshal(data []byte, v interface{}) error
// Name returns the serializer name (e.g., "json", "msgpack").
Name() string
}
Serializer handles marshaling and unmarshaling of cache values. Implementations must be thread-safe.