Skip to content

Commit

Permalink
Compression codec is high three bits, not low
Browse files Browse the repository at this point in the history
And apparently none-zero values for the low three bits mean your messages are
silently dropped by the broker. I've also updated the wiki to be more clear
which bits need setting.

Fixes #32.
  • Loading branch information
eapache committed Sep 3, 2013
1 parent 0f5cff6 commit 7d6070c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions message.go
Expand Up @@ -8,7 +8,7 @@ import (
)

// CompressionCodec represents the various compression codecs recognized by Kafka in messages.
type CompressionCodec int8
type CompressionCodec uint8

const (
CompressionNone CompressionCodec = 0
Expand All @@ -33,7 +33,7 @@ func (m *Message) encode(pe packetEncoder) error {

pe.putInt8(messageFormat)

attributes := int8(m.Codec) & 0x07
attributes := int8(m.Codec << 5)
pe.putInt8(attributes)

err := pe.putBytes(m.Key)
Expand Down Expand Up @@ -95,7 +95,7 @@ func (m *Message) decode(pd packetDecoder) (err error) {
if err != nil {
return err
}
m.Codec = CompressionCodec(attribute & 0x07)
m.Codec = CompressionCodec(attribute >> 5)

m.Key, err = pd.getBytes()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions message_test.go
Expand Up @@ -11,9 +11,9 @@ var (
0xFF, 0xFF, 0xFF, 0xFF} // value

emptyGzipMessage = []byte{
97, 79, 149, 90, //CRC
0xAA, 0x27, 0x4D, 0x22, //CRC
0x00, // magic version byte
0x01, // attribute flags
0x20, // attribute flags
0xFF, 0xFF, 0xFF, 0xFF, // key
// value
0x00, 0x00, 0x00, 0x17,
Expand Down

0 comments on commit 7d6070c

Please sign in to comment.