Documentation
¶
Index ¶
- func DecompressAndDeserialize(data []byte, isCompressed bool, compressor Compressor, target any) error
- func SerializeAndCompress(value any, compressor Compressor, minSize int) ([]byte, bool, error)
- type Compressor
- type CompressorType
- type Config
- type DeflateCompressor
- type GzipCompressor
- type NoOpCompressor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecompressAndDeserialize ¶
func DecompressAndDeserialize(data []byte, isCompressed bool, compressor Compressor, target any) error
DecompressAndDeserialize decompresses and deserializes data back to a value
func SerializeAndCompress ¶
SerializeAndCompress converts a value to bytes and compresses it if it meets size threshold
Types ¶
type Compressor ¶
type Compressor interface {
// Compress compresses the given data and returns compressed bytes
Compress(data []byte) ([]byte, error)
// Decompress decompresses the given compressed bytes
Decompress(compressed []byte) ([]byte, error)
// Name returns the name/identifier of the compressor
Name() string
}
Compressor defines the interface for cache value compression
func NewCompressor ¶
func NewCompressor(config *Config) (Compressor, error)
NewCompressor creates a new compressor based on the configuration
type CompressorType ¶
type CompressorType string
CompressorType represents different compression algorithms
const ( CompressorNone CompressorType = "none" CompressorGzip CompressorType = "gzip" CompressorDeflate CompressorType = "deflate" )
type Config ¶
type Config struct {
// Enabled determines whether compression is enabled
Enabled bool
// Algorithm specifies which compression algorithm to use
Algorithm CompressorType
// MinSize is the minimum size in bytes before compression is applied
// Values smaller than this will not be compressed to avoid overhead
MinSize int
// Level is the compression level (1-9 for gzip/deflate, -1 for default)
Level int
}
Config holds compression configuration
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig creates a default compression configuration
func (*Config) WithAlgorithm ¶
func (c *Config) WithAlgorithm(algorithm CompressorType) *Config
WithAlgorithm sets the compression algorithm
func (*Config) WithEnabled ¶
WithEnabled sets whether compression is enabled
func (*Config) WithMinSize ¶
WithMinSize sets the minimum size threshold for compression
type DeflateCompressor ¶
type DeflateCompressor struct {
// contains filtered or unexported fields
}
DeflateCompressor implements compression using zlib/deflate
func NewDeflateCompressor ¶
func NewDeflateCompressor(level int) *DeflateCompressor
NewDeflateCompressor creates a new deflate compressor with the specified level
func (*DeflateCompressor) Compress ¶
func (d *DeflateCompressor) Compress(data []byte) ([]byte, error)
Compress compresses data using deflate
func (*DeflateCompressor) Decompress ¶
func (d *DeflateCompressor) Decompress(compressed []byte) ([]byte, error)
Decompress decompresses deflate data
func (*DeflateCompressor) Name ¶
func (d *DeflateCompressor) Name() string
Name returns the compressor name
type GzipCompressor ¶
type GzipCompressor struct {
// contains filtered or unexported fields
}
GzipCompressor implements compression using gzip
func NewGzipCompressor ¶
func NewGzipCompressor(level int) *GzipCompressor
NewGzipCompressor creates a new gzip compressor with the specified level
func (*GzipCompressor) Compress ¶
func (g *GzipCompressor) Compress(data []byte) ([]byte, error)
Compress compresses data using gzip
func (*GzipCompressor) Decompress ¶
func (g *GzipCompressor) Decompress(compressed []byte) ([]byte, error)
Decompress decompresses gzip data
func (*GzipCompressor) Name ¶
func (g *GzipCompressor) Name() string
Name returns the compressor name
type NoOpCompressor ¶
type NoOpCompressor struct{}
NoOpCompressor provides a no-op implementation that doesn't compress
func NewNoOpCompressor ¶
func NewNoOpCompressor() *NoOpCompressor
NewNoOpCompressor creates a new no-op compressor
func (*NoOpCompressor) Compress ¶
func (n *NoOpCompressor) Compress(data []byte) ([]byte, error)
Compress returns the data unchanged
func (*NoOpCompressor) Decompress ¶
func (n *NoOpCompressor) Decompress(compressed []byte) ([]byte, error)
Decompress returns the data unchanged
func (*NoOpCompressor) Name ¶
func (n *NoOpCompressor) Name() string
Name returns the compressor name