Skip to content

Commit f5fe483

Browse files
OleksiienkoMykytajoao-r-reis
authored andcommitted
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 f9a0f63 commit f5fe483

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
@@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
### Changed
2525

26+
- Moved the Snappy compressor into its own separate package (CASSGO-33)
27+
2628
- Move lz4 compressor to lz4 package within the gocql module (CASSGO-32)
2729
- Don't restrict server authenticator unless PasswordAuthentictor.AllowedAuthenticators is provided (CASSGO-19)
2830
- Cleanup of deprecated elements (CASSGO-12)

common_test.go

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

3939
"github.com/gocql/gocql/lz4"
40+
"github.com/gocql/gocql/snappy"
4041
)
4142

4243
var (
@@ -117,7 +118,7 @@ func createCluster(opts ...func(*ClusterConfig)) *ClusterConfig {
117118

118119
switch *flagCompressTest {
119120
case "snappy":
120-
cluster.Compressor = &SnappyCompressor{}
121+
cluster.Compressor = &snappy.SnappyCompressor{}
121122
case "lz4":
122123
cluster.Compressor = &lz4.LZ4Compressor{}
123124
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)