Skip to content

Commit

Permalink
Add workaround for an empty zstd message
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrik committed Oct 1, 2018
1 parent 6a3393f commit 0f30d97
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ 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)
if err != nil {
return err
if len(m.Value) == 0 {
// Hardcoded empty ZSTD frame, see: https://github.com/DataDog/zstd/issues/41
m.compressedCache = []byte{0x28, 0xb5, 0x2f, 0xfd, 0x24, 0x00, 0x01, 0x00, 0x00, 0x99, 0xe9, 0xd8, 0x51}
} else {
c, err := zstd.CompressLevel(nil, m.Value, m.CompressionLevel)
if err != nil {
return err
}
m.compressedCache = c
}
m.compressedCache = c
payload = m.compressedCache
default:
return PacketEncodingError{fmt.Sprintf("unsupported compression codec (%d)", m.Codec)}
Expand Down

0 comments on commit 0f30d97

Please sign in to comment.