Skip to content

Commit 8913cd5

Browse files
authored
Merge pull request #1477 from klauspost/use-pure-go-zstd
Remove cgo zstd package
2 parents 5c9d4b0 + 2fbc232 commit 8913cd5

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

compress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func compress(cc CompressionCodec, level int, data []byte) ([]byte, error) {
6868
}
6969
return buf.Bytes(), nil
7070
case CompressionZSTD:
71-
return zstdCompressLevel(nil, data, level)
71+
return zstdCompress(nil, data)
7272
default:
7373
return nil, PacketEncodingError{fmt.Sprintf("unsupported compression codec (%d)", cc)}
7474
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/Shopify/sarama
33
go 1.13
44

55
require (
6-
github.com/DataDog/zstd v1.4.0
76
github.com/Shopify/toxiproxy v2.1.4+incompatible
87
github.com/davecgh/go-spew v1.1.1
98
github.com/eapache/go-resiliency v1.1.0
@@ -14,6 +13,7 @@ require (
1413
github.com/golang/snappy v0.0.1 // indirect
1514
github.com/hashicorp/go-uuid v1.0.1 // indirect
1615
github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03 // indirect
16+
github.com/klauspost/compress v1.8.2
1717
github.com/pierrec/lz4 v2.2.6+incompatible
1818
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a
1919
github.com/stretchr/testify v1.3.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1
2323
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
2424
github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03 h1:FUwcHNlEqkqLjLBdCp5PRlCFijNjvcYANOZXzCfXwCM=
2525
github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
26+
github.com/klauspost/compress v1.8.1 h1:oygt2ychZFHOB6M9gUgajzgKrwRgHbGC77NwA4COVgI=
27+
github.com/klauspost/compress v1.8.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
28+
github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
29+
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
2630
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
2731
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
2832
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=

zstd.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package sarama
2+
3+
import (
4+
"github.com/klauspost/compress/zstd"
5+
"sync"
6+
)
7+
8+
var (
9+
zstdDec *zstd.Decoder
10+
zstdEnc *zstd.Encoder
11+
12+
zstdEncOnce, zstdDecOnce sync.Once
13+
)
14+
15+
func zstdDecompress(dst, src []byte) ([]byte, error) {
16+
zstdDecOnce.Do(func() {
17+
zstdDec, _ = zstd.NewReader(nil)
18+
})
19+
return zstdDec.DecodeAll(src, dst)
20+
}
21+
22+
func zstdCompress(dst, src []byte) ([]byte, error) {
23+
zstdEncOnce.Do(func() {
24+
zstdEnc, _ = zstd.NewWriter(nil, zstd.WithZeroFrames(true))
25+
})
26+
return zstdEnc.EncodeAll(src, dst), nil
27+
}

zstd_cgo.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

zstd_fallback.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)