Sha256: ad8ab9bda43d2fc2eb6ac12b11ecc2194e9e12d30c8b2fc9899fe781d5b73b5d

Contents?: true

Size: 772 Bytes

Versions: 2

Compression:

Stored size: 772 Bytes

Contents

module Avrocado
  class Deserializer
    attr_reader :schema

    def initialize(schema)
      @schema = schema
    end

    def self.deserialize(message, schema)
      new(schema).deserialize(message)
    end

    def deserialize(message)
      Avrocado::Decoder.new(message, schema).decoded
    end
  end

  class Decoder
    attr_reader :message, :schema

    def initialize(message, schema)
      @message = message
      @schema  = schema
    end

    def decoded
      JSON.parse reader.read(nil, decoder).to_s
    end

    private

    def reader
      @reader ||= Java::Avro::GenericDatumReader.new(schema)
    end

    def decoder
      @decoder ||= Avrocado::DecoderFactory
        .default_factory
        .create_binary_decoder(message, nil)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
avrocado-0.2.1 lib/avrocado/deserializer.rb
avrocado-0.2.0 lib/avrocado/deserializer.rb