Skip to content

Commit

Permalink
Merge pull request #8 from Shopify/compress-once-only
Browse files Browse the repository at this point in the history
Only compress a message once
  • Loading branch information
eapache committed Aug 13, 2013
2 parents d0f774f + 4797fe2 commit 0d0b110
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ func (m *Message) encode(pe packetEncoder) error {
return err
}

var body []byte
switch m.Codec {
case COMPRESSION_NONE:
body = m.Value
case COMPRESSION_GZIP:
if m.Value != nil {
var buf bytes.Buffer
writer := gzip.NewWriter(&buf)
writer.Write(m.Value)
writer.Close()
body = buf.Bytes()
m.Value = buf.Bytes()
m.Codec = COMPRESSION_NONE
}
case COMPRESSION_SNAPPY:
body, err = snappy.Encode(nil, m.Value)
tmp, err := snappy.Encode(nil, m.Value)
if err != nil {
return err
}
m.Value = tmp
m.Codec = COMPRESSION_NONE
}
err = pe.putBytes(body)
err = pe.putBytes(m.Value)
if err != nil {
return err
}
Expand Down

0 comments on commit 0d0b110

Please sign in to comment.