File tree Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 11require "kafka/snappy_codec"
22require "kafka/gzip_codec"
3+ require "kafka/lz4_codec"
34
45module Kafka
56 module Compression
@@ -8,6 +9,7 @@ def self.find_codec(name)
89 when nil then nil
910 when :snappy then SnappyCodec . new
1011 when :gzip then GzipCodec . new
12+ when :lz4 then LZ4Codec . new
1113 else raise "Unknown compression codec #{ name } "
1214 end
1315 end
@@ -16,6 +18,7 @@ def self.find_codec_by_id(codec_id)
1618 case codec_id
1719 when 1 then GzipCodec . new
1820 when 2 then SnappyCodec . new
21+ when 3 then LZ4Codec . new
1922 else raise "Unknown codec id #{ codec_id } "
2023 end
2124 end
Original file line number Diff line number Diff line change 1+ module Kafka
2+ class LZ4Codec
3+ def initialize
4+ require "extlz4"
5+ rescue LoadError
6+ raise LoadError , "using lz4 compression requires adding a dependency on the `extlz4` gem to your Gemfile."
7+ end
8+
9+ def codec_id
10+ 3
11+ end
12+
13+ def compress ( data )
14+ LZ4 . encode ( data )
15+ end
16+
17+ def decompress ( data )
18+ LZ4 . decode ( data )
19+ end
20+ end
21+ end
Original file line number Diff line number Diff line change 11module Kafka
2- VERSION = "0.5.1 "
2+ VERSION = "0.5.2 "
33end
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
3535 spec . add_development_dependency "rspec-benchmark"
3636 spec . add_development_dependency "activesupport"
3737 spec . add_development_dependency "snappy"
38+ spec . add_development_dependency "extlz4"
3839 spec . add_development_dependency "colored"
3940 spec . add_development_dependency "rspec_junit_formatter" , "0.2.2"
4041 spec . add_development_dependency "dogstatsd-ruby" , ">= 3.0.0"
You can’t perform that action at this time.
0 commit comments