Sha256: bd6e8903d4fe26560edf512169ffa3c596086096e5c4b212130a27b48db75860

Contents?: true

Size: 985 Bytes

Versions: 5

Compression:

Stored size: 985 Bytes

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 message [String] the binary blob to deserialize
      # @return [Hash{Symbol => Mixed}] the deserialized Apache Avro message
      def call(message)
        # 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(message.payload)
          .yield_self { |data| Sparsify(data, sparse_array: true) }
          .yield_self { |data| data.transform_keys { |key| key.delete('\\') } }
          .yield_self { |data| Unsparsify(data, sparse_array: true) }
          .deep_symbolize_keys
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rimless-1.0.4 lib/rimless/karafka/avro_deserializer.rb
rimless-1.0.3 lib/rimless/karafka/avro_deserializer.rb
rimless-1.0.2 lib/rimless/karafka/avro_deserializer.rb
rimless-1.0.1 lib/rimless/karafka/avro_deserializer.rb
rimless-1.0.0 lib/rimless/karafka/avro_deserializer.rb