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
- #decode_hash(*args) ⇒ Hash
-
#initialize(*models, schema_registry: nil, registry_url: nil) ⇒ MessageDecoder
constructor
A new instance of MessageDecoder.
- #model(*args) ⇒ Avromatic model class
Constructor Details
#initialize(*models, schema_registry: nil, registry_url: nil) ⇒ MessageDecoder
Returns a new instance of MessageDecoder.
45 46 47 48 49 50 51 52 |
# File 'lib/avromatic/model/message_decoder.rb', line 45 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::ConfluentSchemaRegistry.new(registry_url, logger: Avromatic.logger)) || Avromatic.build_schema_registry end |
Class Method Details
.model_key(model) ⇒ Object
34 35 36 37 |
# File 'lib/avromatic/model/message_decoder.rb', line 34 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
55 56 57 58 |
# File 'lib/avromatic/model/message_decoder.rb', line 55 def decode(*args) model, , = extract_decode_args(*args) model.(, ) end |
#decode_hash(*args) ⇒ Hash
61 62 63 64 |
# File 'lib/avromatic/model/message_decoder.rb', line 61 def decode_hash(*args) model, , = extract_decode_args(*args) model.(, ) end |