Skip to content

Commit

Permalink
Merge pull request #1182 from retailnext/zstd-build-constraints
Browse files Browse the repository at this point in the history
Fix build without cgo
  • Loading branch information
bai authored Oct 2, 2018
2 parents 1a7ecd8 + 3dd2f63 commit f1aa91b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
5 changes: 2 additions & 3 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"time"

"github.com/DataDog/zstd"
"github.com/eapache/go-xerial-snappy"
"github.com/pierrec/lz4"
)
Expand Down Expand Up @@ -116,7 +115,7 @@ func (m *Message) encode(pe packetEncoder) error {
m.compressedCache = buf.Bytes()
payload = m.compressedCache
case CompressionZSTD:
c, err := zstd.CompressLevel(nil, m.Value, m.CompressionLevel)
c, err := zstdCompressLevel(nil, m.Value, m.CompressionLevel)
if err != nil {
return err
}
Expand Down Expand Up @@ -219,7 +218,7 @@ func (m *Message) decode(pd packetDecoder) (err error) {
if m.Value == nil {
break
}
if m.Value, err = zstd.Decompress(nil, m.Value); err != nil {
if m.Value, err = zstdDecompress(nil, m.Value); err != nil {
return err
}
if err := m.decodeSet(); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions record_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"time"

"github.com/DataDog/zstd"
"github.com/eapache/go-xerial-snappy"
"github.com/pierrec/lz4"
)
Expand Down Expand Up @@ -195,7 +194,7 @@ func (b *RecordBatch) decode(pd packetDecoder) (err error) {
return err
}
case CompressionZSTD:
if recBuffer, err = zstd.Decompress(nil, recBuffer); err != nil {
if recBuffer, err = zstdDecompress(nil, recBuffer); err != nil {
return err
}
default:
Expand Down Expand Up @@ -254,7 +253,7 @@ func (b *RecordBatch) encodeRecords(pe packetEncoder) error {
}
b.compressedRecords = buf.Bytes()
case CompressionZSTD:
c, err := zstd.CompressLevel(nil, raw, b.CompressionLevel)
c, err := zstdCompressLevel(nil, raw, b.CompressionLevel)
if err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions zstd_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build cgo

package sarama

import "github.com/DataDog/zstd"

func zstdDecompress(dst, src []byte) ([]byte, error) {
return zstd.Decompress(dst, src)
}

func zstdCompressLevel(dst, src []byte, level int) ([]byte, error) {
return zstd.CompressLevel(dst, src, level)
}
17 changes: 17 additions & 0 deletions zstd_fallback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build !cgo

package sarama

import (
"errors"
)

var errZstdCgo = errors.New("zstd compression requires building with cgo enabled")

func zstdDecompress(dst, src []byte) ([]byte, error) {
return nil, errZstdCgo
}

func zstdCompressLevel(dst, src []byte, level int) ([]byte, error) {
return nil, errZstdCgo
}

0 comments on commit f1aa91b

Please sign in to comment.