Class: Kafka::SnappyCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/snappy_codec.rb

Instance Method Summary collapse

Constructor Details

#initializeSnappyCodec

Returns a new instance of SnappyCodec.


3
4
5
# File 'lib/kafka/snappy_codec.rb', line 3

def initialize
  require "snappy"
end

Instance Method Details

#codec_idObject


7
8
9
# File 'lib/kafka/snappy_codec.rb', line 7

def codec_id
  2
end

#compress(data) ⇒ Object


11
12
13
# File 'lib/kafka/snappy_codec.rb', line 11

def compress(data)
  Snappy.deflate(data)
end

#decompress(data) ⇒ Object


15
16
17
18
# File 'lib/kafka/snappy_codec.rb', line 15

def decompress(data)
  buffer = StringIO.new(data)
  Snappy::Reader.new(buffer).read
end