Skip to content

Commit d373fb6

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 5ca5382 commit d373fb6

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This release is the first after the donation of gocql to the Apache Software Fou
2121
driver as an ASF driver. This should clearly distinguish this release (and future gocql-cassandra-driver
2222
releases) from prior versions. (#1824)
2323
- Supported Go versions updated to 1.23 and 1.22 to conform to gocql's sunset model. (#1825)
24+
- Moved the Snappy compressor into its own separate package.
25+
This allows users to include only the compression dependencies they need. (CASSGO-33)
2426

2527
## [1.6.0] - 2023-08-28
2628

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 "":

compressor.go

Lines changed: 0 additions & 22 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

@@ -52,23 +50,3 @@ type Compressor interface {
5250
// compress incoming and outgoing frames. The snappy compression algorithm
5351
// aims for very high speeds and reasonable compression.
5452
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-
}

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"

snappy/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+
}

0 commit comments

Comments
 (0)