mirror of
https://github.com/smallnest/rpcx.git
synced 2025-11-02 04:12:32 +08:00
#212 implement compressor
This commit is contained in:
32
protocol/compressor.go
Normal file
32
protocol/compressor.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package protocol
|
||||
|
||||
import "github.com/smallnest/rpcx/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
|
||||
}
|
||||
Reference in New Issue
Block a user