Skip to content

Commit

Permalink
Remove cgo zstd package
Browse files Browse the repository at this point in the history
Switch from cgo package to pure Go implementation. This will (when fixed) work even if no cgo is present.

https://github.com/klauspost/compress/tree/master/zstd#zstd

Compression level is removed. It could be made so the first request determines the compression level. But since there is currently only two levels (fast and default) I am not sure it is worth it.

This does NOT fix IBM#1252 - only updates the code used for compression/decompression.
  • Loading branch information
klauspost committed Sep 3, 2019
1 parent d6c39e5 commit c65bddd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func compress(cc CompressionCodec, level int, data []byte) ([]byte, error) {
}
return buf.Bytes(), nil
case CompressionZSTD:
return zstdCompressLevel(nil, data, level)
return zstdCompress(nil, data)
default:
return nil, PacketEncodingError{fmt.Sprintf("unsupported compression codec (%d)", cc)}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module github.com/Shopify/sarama

require (
github.com/DataDog/zstd v1.4.0
github.com/Shopify/toxiproxy v2.1.4+incompatible
github.com/davecgh/go-spew v1.1.1
github.com/eapache/go-resiliency v1.1.0
Expand All @@ -12,6 +11,7 @@ require (
github.com/golang/snappy v0.0.1 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03 // indirect
github.com/klauspost/compress v1.8.1
github.com/pierrec/lz4 v2.2.6+incompatible
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a
github.com/stretchr/testify v1.3.0
Expand Down
28 changes: 28 additions & 0 deletions zstd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sarama

import (
"github.com/klauspost/compress/zstd"
"sync"
)

var (
zstdDec *zstd.Decoder
zstdEnc *zstd.Encoder

zstdEncOnce, zstdDecOnce sync.Once
)


func zstdDecompress(dst, src []byte) ([]byte, error) {
zstdDecOnce.Do(func() {
zstdDec, _ = zstd.NewReader(nil)
})
return zstdDec.DecodeAll(src, dst)
}

func zstdCompress(dst, src []byte) ([]byte, error) {
zstdEncOnce.Do(func() {
zstdEnc, _ = zstd.NewWriter(nil)
})
return zstdEnc.EncodeAll(src, dst), nil
}
13 changes: 0 additions & 13 deletions zstd_cgo.go

This file was deleted.

17 changes: 0 additions & 17 deletions zstd_fallback.go

This file was deleted.

0 comments on commit c65bddd

Please sign in to comment.