#212 implement compressor

This commit is contained in:
smallnest
2018-04-25 20:21:59 +08:00
parent 83ff6b6b47
commit f1c003a1e0
5 changed files with 97 additions and 9 deletions

32
protocol/compressor.go Normal file
View 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
}