Module: Kafka::Compression

Defined in:
lib/kafka/compression.rb

Constant Summary collapse

CODECS_BY_NAME =
{
  :gzip => GzipCodec.new,
  :snappy => SnappyCodec.new,
  :lz4 => LZ4Codec.new,
  :zstd => ZstdCodec.new,
}.freeze
CODECS_BY_ID =
CODECS_BY_NAME.each_with_object({}) do |(_, codec), hash|
  hash[codec.codec_id] = codec
end.freeze

Class Method Summary collapse

Class Method Details

.codecsObject



21
22
23
# File 'lib/kafka/compression.rb', line 21

def self.codecs
  CODECS_BY_NAME.keys
end

.find_codec(name) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/kafka/compression.rb', line 25

def self.find_codec(name)
  codec = CODECS_BY_NAME.fetch(name) do
    raise "Unknown compression codec #{name}"
  end

  codec.load

  codec
end

.find_codec_by_id(codec_id) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/kafka/compression.rb', line 35

def self.find_codec_by_id(codec_id)
  codec = CODECS_BY_ID.fetch(codec_id) do
    raise "Unknown codec id #{codec_id}"
  end

  codec.load

  codec
end