diff --git a/CHANGELOG.md b/CHANGELOG.md index 37ae55e3e..5c75450b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Moved the Snappy compressor into its own separate package (CASSGO-33) + - Move lz4 compressor to lz4 package within the gocql module (CASSGO-32) - Don't restrict server authenticator unless PasswordAuthentictor.AllowedAuthenticators is provided (CASSGO-19) diff --git a/common_test.go b/common_test.go index e420bbf16..25f4fc640 100644 --- a/common_test.go +++ b/common_test.go @@ -36,6 +36,7 @@ import ( "time" "github.com/gocql/gocql/lz4" + "github.com/gocql/gocql/snappy" ) var ( @@ -112,7 +113,7 @@ func createCluster(opts ...func(*ClusterConfig)) *ClusterConfig { switch *flagCompressTest { case "snappy": - cluster.Compressor = &SnappyCompressor{} + cluster.Compressor = &snappy.SnappyCompressor{} case "lz4": cluster.Compressor = &lz4.LZ4Compressor{} case "no-compression": diff --git a/compressor.go b/compressor.go index c1b7b2b6f..a4c305b7e 100644 --- a/compressor.go +++ b/compressor.go @@ -24,8 +24,6 @@ package gocql -import "github.com/golang/snappy" - type Compressor interface { Name() string @@ -47,28 +45,3 @@ type Compressor interface { // It returns a new byte slice that is the result of the append operation. AppendDecompressed(dst, src []byte, decompressedLength uint32) ([]byte, error) } - -// SnappyCompressor implements the Compressor interface and can be used to -// compress incoming and outgoing frames. The snappy compression algorithm -// aims for very high speeds and reasonable compression. -type SnappyCompressor struct{} - -func (s SnappyCompressor) Name() string { - return "snappy" -} - -func (s SnappyCompressor) AppendCompressedWithLength(dst, src []byte) ([]byte, error) { - return snappy.Encode(dst, src), nil -} - -func (s SnappyCompressor) AppendDecompressedWithLength(dst, src []byte) ([]byte, error) { - return snappy.Decode(dst, src) -} - -func (s SnappyCompressor) AppendCompressed(dst, src []byte) ([]byte, error) { - panic("SnappyCompressor.AppendCompressed is not supported") -} - -func (s SnappyCompressor) AppendDecompressed(dst, src []byte, decompressedLength uint32) ([]byte, error) { - panic("SnappyCompressor.AppendDecompressed is not supported") -} diff --git a/snappy/compressor.go b/snappy/compressor.go new file mode 100644 index 000000000..faec4a722 --- /dev/null +++ b/snappy/compressor.go @@ -0,0 +1,28 @@ +package snappy + +import "github.com/golang/snappy" + +// SnappyCompressor implements the Compressor interface and can be used to +// compress incoming and outgoing frames. The snappy compression algorithm +// aims for very high speeds and reasonable compression. +type SnappyCompressor struct{} + +func (s SnappyCompressor) Name() string { + return "snappy" +} + +func (s SnappyCompressor) AppendCompressedWithLength(dst, src []byte) ([]byte, error) { + return snappy.Encode(dst, src), nil +} + +func (s SnappyCompressor) AppendDecompressedWithLength(dst, src []byte) ([]byte, error) { + return snappy.Decode(dst, src) +} + +func (s SnappyCompressor) AppendCompressed(dst, src []byte) ([]byte, error) { + panic("SnappyCompressor.AppendCompressed is not supported") +} + +func (s SnappyCompressor) AppendDecompressed(dst, src []byte, decompressedLength uint32) ([]byte, error) { + panic("SnappyCompressor.AppendDecompressed is not supported") +} diff --git a/compressor_test.go b/snappy/compressor_test.go similarity index 99% rename from compressor_test.go rename to snappy/compressor_test.go index d2d2de040..3efe3fa70 100644 --- a/compressor_test.go +++ b/snappy/compressor_test.go @@ -22,7 +22,7 @@ * See the NOTICE file distributed with this work for additional information. */ -package gocql +package snappy import ( "bytes"