Files
rpcx/protocol/compressor.go
2020-08-06 17:25:11 +08:00

35 lines
666 B
Go

package protocol
import (
"github.com/smallnest/rpcx/v5/util"
)
// Compressor defines a common compression interface.
type Compressor interface {
Zip([]byte) ([]byte, error)
Unzip([]byte) ([]byte, error)
}
// GzipCompressor implements gzip compressor.
type GzipCompressor struct {
}
func (c GzipCompressor) Zip(data []byte) ([]byte, error) {
return util.Zip(data)
}
func (c GzipCompressor) Unzip(data []byte) ([]byte, error) {
return util.Unzip(data)
}
type RawDataCompressor struct {
}
func (c RawDataCompressor) Zip(data []byte) ([]byte, error) {
return data, nil
}
func (c RawDataCompressor) Unzip(data []byte) ([]byte, error) {
return data, nil
}