Class: Avromatic::Model::MessageDecoder
- Inherits:
-
Object
- Object
- Avromatic::Model::MessageDecoder
- Defined in:
- lib/avromatic/model/message_decoder.rb
Overview
This class is used to decode messages encoded using Avro to their corresponding models.
Defined Under Namespace
Classes: DuplicateKeyError, MagicByteError, UnexpectedKeyError
Constant Summary collapse
- MAGIC_BYTE =
[0].pack('C').freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#decode(*args) ⇒ Avromatic model
If two arguments are specified then the first is interpreted as the message key and the second is the message value.
-
#initialize(*models, schema_registry: nil, registry_url: nil) ⇒ MessageDecoder
constructor
A new instance of MessageDecoder.
Constructor Details
#initialize(*models, schema_registry: nil, registry_url: nil) ⇒ MessageDecoder
Returns a new instance of MessageDecoder.
41 42 43 44 45 46 47 48 |
# File 'lib/avromatic/model/message_decoder.rb', line 41 def initialize(*models, schema_registry: nil, registry_url: nil) @model_map = build_model_map(models) @schema_names_by_id = {} @schema_registry = schema_registry || Avromatic.schema_registry || (registry_url && AvroTurf::SchemaRegistry.new(registry_url, logger: Avromatic.logger)) || Avromatic.build_schema_registry end |
Class Method Details
.model_key(model) ⇒ Object
30 31 32 33 |
# File 'lib/avromatic/model/message_decoder.rb', line 30 def self.model_key(model) [model.key_avro_schema && model.key_avro_schema.fullname, model.value_avro_schema.fullname] end |
Instance Method Details
#decode(*args) ⇒ Avromatic model
If two arguments are specified then the first is interpreted as the message key and the second is the message value. If there is only one arg then it is used as the message value.
54 55 56 57 58 59 |
# File 'lib/avromatic/model/message_decoder.rb', line 54 def decode(*args) , = args.size > 1 ? args : [nil, args.first] value_schema_name = schema_name_for_data() key_schema_name = schema_name_for_data() if deserialize([key_schema_name, value_schema_name], , ) end |