class Deimos::SchemaBackends::AvroBase
Encode / decode using Avro, either locally or via schema registry.
Attributes
schema_store[RW]
Public Class Methods
new(schema:, namespace:)
click to toggle source
@override
Calls superclass method
# File lib/deimos/schema_backends/avro_base.rb, line 16 def initialize(schema:, namespace:) super(schema: schema, namespace: namespace) @schema_store = AvroTurf::MutableSchemaStore.new(path: Deimos.config.schema.path) end
Public Instance Methods
decode_key(payload, key_id)
click to toggle source
@override
# File lib/deimos/schema_backends/avro_base.rb, line 30 def decode_key(payload, key_id) @key_schema ||= _generate_key_schema(key_id) field_name = _field_name_from_schema(@key_schema) decode(payload, schema: @key_schema['name'])[field_name] end
encode_key(key_id, key, topic: nil)
click to toggle source
@override
# File lib/deimos/schema_backends/avro_base.rb, line 22 def encode_key(key_id, key, topic: nil) @key_schema ||= _generate_key_schema(key_id) field_name = _field_name_from_schema(@key_schema) payload = { field_name => key } encode(payload, schema: @key_schema['name'], topic: topic) end