module Avromatic::Model::RawSerialization::Decode
Public Instance Methods
Source
# File lib/avromatic/model/raw_serialization.rb, line 124 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
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.
Private Instance Methods
Source
# File lib/avromatic/model/raw_serialization.rb, line 140 def custom_datum_reader(schema, key_or_value) datum_reader_class.new(schema, send("#{key_or_value}_avro_schema")) end
Source
# File lib/avromatic/model/raw_serialization.rb, line 133 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