module Avromatic::Model::RawSerialization::Decode

Public Instance Methods

avro_raw_decode(value:, key: nil, key_schema: nil, value_schema: nil) click to toggle source

Create a new instance based on an encoded value and optional encoded key. If supplied then the key_schema and value_schema are used as the writer’s schema for the corresponding value. The model’s schemas are always used as the reader’s schemas.

# File lib/avromatic/model/raw_serialization.rb, line 122
def avro_raw_decode(value:, key: nil, key_schema: nil, value_schema: nil)
  key_attributes = key && decode_avro_datum(key, key_schema, :key)
  value_attributes = decode_avro_datum(value, value_schema, :value)
  value_attributes.merge!(key_attributes) if key_attributes
  new(value_attributes)
end

Private Instance Methods

custom_datum_reader(schema, key_or_value) click to toggle source
# File lib/avromatic/model/raw_serialization.rb, line 138
def custom_datum_reader(schema, key_or_value)
  datum_reader_class.new(schema, send("#{key_or_value}_avro_schema"))
end
decode_avro_datum(data, schema = nil, key_or_value = :value) click to toggle source
# File lib/avromatic/model/raw_serialization.rb, line 131
def decode_avro_datum(data, schema = nil, key_or_value = :value)
  stream = StringIO.new(data)
  decoder = Avro::IO::BinaryDecoder.new(stream)
  reader = schema ? custom_datum_reader(schema, key_or_value) : datum_reader[key_or_value]
  reader.read(decoder)
end