Sha256: 805a82beabf13458e6eb9e11a4135d4a2ac7eb39691c8a8c44095505fb2b1727

Contents?: true

Size: 1.15 KB

Versions: 17

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Rimless
  module Karafka
    # A custom Apache Avro compatible message deserializer.
    class AvroDeserializer
      # Deserialize an Apache Avro encoded Apache Kafka message.
      #
      # @param params [Karafka::Params::Params] the Karafka message parameters
      # @return [Hash{Symbol => Mixed}] the deserialized Apache Avro message
      def call(params)
        # When the Kafka message does not have a payload, we won't fail.
        # This is for Kafka users which use log compaction with a nil payload.
        return if params.raw_payload.nil?

        # We use sparsed hashes inside of Apache Avro messages for schema-less
        # blobs of data, such as loosely structured metadata blobs.  Thats a
        # somewhat bad idea on strictly typed and defined messages, but their
        # occurence should be rare.
        Rimless
          .decode(params.raw_payload)
          .then { |data| Sparsify(data, sparse_array: true) }
          .then { |data| data.transform_keys { |key| key.delete('\\') } }
          .then { |data| Unsparsify(data, sparse_array: true) }
          .deep_symbolize_keys
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rimless-1.10.2 lib/rimless/karafka/avro_deserializer.rb
rimless-1.10.1 lib/rimless/karafka/avro_deserializer.rb
rimless-1.10.0 lib/rimless/karafka/avro_deserializer.rb
rimless-1.9.0 lib/rimless/karafka/avro_deserializer.rb
rimless-1.8.0 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.7 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.6 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.5 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.4 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.3 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.2 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.1 lib/rimless/karafka/avro_deserializer.rb
rimless-1.7.0 lib/rimless/karafka/avro_deserializer.rb
rimless-1.6.0 lib/rimless/karafka/avro_deserializer.rb
rimless-1.4.1 lib/rimless/karafka/avro_deserializer.rb
rimless-1.4.0 lib/rimless/karafka/avro_deserializer.rb
rimless-1.3.0 lib/rimless/karafka/avro_deserializer.rb