Skip to content

Commit 20ff614

Browse files
Move the snappy compressor into a separate go package
Currently, Snappy is downloaded and included even when users only require LZ4 compression. To streamline the driver and reduce unnecessary dependency overhead for users who don't utilize Snappy, move the Snappy compressor into its own separate package. This will allow users to include only the compression dependencies they need. Patch by Mykyta Oleksiienko; reviewed by Joao Reis CASSGO-33
1 parent c75ff5f commit 20ff614

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Changed
2020

21+
- Moved the Snappy compressor into its own separate package (CASSGO-33)
22+
2123
- Move lz4 compressor to lz4 package within the gocql module (CASSGO-32)
2224

2325
- Don't restrict server authenticator unless PasswordAuthentictor.AllowedAuthenticators is provided (CASSGO-19)

common_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"time"
3737

3838
"github.com/gocql/gocql/lz4"
39+
"github.com/gocql/gocql/snappy"
3940
)
4041

4142
var (
@@ -112,7 +113,7 @@ func createCluster(opts ...func(*ClusterConfig)) *ClusterConfig {
112113

113114
switch *flagCompressTest {
114115
case "snappy":
115-
cluster.Compressor = &SnappyCompressor{}
116+
cluster.Compressor = &snappy.SnappyCompressor{}
116117
case "lz4":
117118
cluster.Compressor = &lz4.LZ4Compressor{}
118119
case "no-compression":

compressor.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
package gocql
2626

27-
import "github.com/golang/snappy"
28-
2927
type Compressor interface {
3028
Name() string
3129

@@ -47,28 +45,3 @@ type Compressor interface {
4745
// It returns a new byte slice that is the result of the append operation.
4846
AppendDecompressed(dst, src []byte, decompressedLength uint32) ([]byte, error)
4947
}
50-
51-
// SnappyCompressor implements the Compressor interface and can be used to
52-
// compress incoming and outgoing frames. The snappy compression algorithm
53-
// aims for very high speeds and reasonable compression.
54-
type SnappyCompressor struct{}
55-
56-
func (s SnappyCompressor) Name() string {
57-
return "snappy"
58-
}
59-
60-
func (s SnappyCompressor) AppendCompressedWithLength(dst, src []byte) ([]byte, error) {
61-
return snappy.Encode(dst, src), nil
62-
}
63-
64-
func (s SnappyCompressor) AppendDecompressedWithLength(dst, src []byte) ([]byte, error) {
65-
return snappy.Decode(dst, src)
66-
}
67-
68-
func (s SnappyCompressor) AppendCompressed(dst, src []byte) ([]byte, error) {
69-
panic("SnappyCompressor.AppendCompressed is not supported")
70-
}
71-
72-
func (s SnappyCompressor) AppendDecompressed(dst, src []byte, decompressedLength uint32) ([]byte, error) {
73-
panic("SnappyCompressor.AppendDecompressed is not supported")
74-
}

snappy/compressor.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package snappy
2+
3+
import "github.com/golang/snappy"
4+
5+
// SnappyCompressor implements the Compressor interface and can be used to
6+
// compress incoming and outgoing frames. The snappy compression algorithm
7+
// aims for very high speeds and reasonable compression.
8+
type SnappyCompressor struct{}
9+
10+
func (s SnappyCompressor) Name() string {
11+
return "snappy"
12+
}
13+
14+
func (s SnappyCompressor) AppendCompressedWithLength(dst, src []byte) ([]byte, error) {
15+
return snappy.Encode(dst, src), nil
16+
}
17+
18+
func (s SnappyCompressor) AppendDecompressedWithLength(dst, src []byte) ([]byte, error) {
19+
return snappy.Decode(dst, src)
20+
}
21+
22+
func (s SnappyCompressor) AppendCompressed(dst, src []byte) ([]byte, error) {
23+
panic("SnappyCompressor.AppendCompressed is not supported")
24+
}
25+
26+
func (s SnappyCompressor) AppendDecompressed(dst, src []byte, decompressedLength uint32) ([]byte, error) {
27+
panic("SnappyCompressor.AppendDecompressed is not supported")
28+
}

compressor_test.go renamed to snappy/compressor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* See the NOTICE file distributed with this work for additional information.
2323
*/
2424

25-
package gocql
25+
package snappy
2626

2727
import (
2828
"bytes"

0 commit comments

Comments
 (0)