Class: Deimos::SchemaBackends::ProtoSchemaRegistry

Inherits:
ProtoBase
  • Object
show all
Defined in:
lib/deimos/schema_backends/proto_schema_registry.rb

Overview

Encode / decode using the Protobuf schema registry.

Constant Summary

Constants inherited from ProtoBase

Deimos::SchemaBackends::ProtoBase::SQL_MAP

Instance Attribute Summary

Attributes inherited from Base

#key_schema, #namespace, #schema

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProtoBase

#coerce, #coerce_field, #decode_key, #encode_key, #generate_key_schema, mock_backend, #proto_schema, #schema_fields, #sql_type, #validate

Methods inherited from Base

#coerce, #coerce_field, content_type, #decode, #decode_key, #encode, #encode_key, field_type, #generate_key_schema, #initialize, #load_schema, mock_backend, #schema_fields, #sql_type, #supports_class_generation?, #supports_key_schemas?, #validate

Constructor Details

This class inherits a constructor from Deimos::SchemaBackends::Base

Class Method Details

.proto_turfProtoTurf

Returns:

  • (ProtoTurf)


23
24
25
26
27
28
# File 'lib/deimos/schema_backends/proto_schema_registry.rb', line 23

def self.proto_turf
  @proto_turf ||= ProtoTurf.new(
    registry_url: Deimos.config.schema.registry_url,
    logger: Karafka.logger
  )
end

Instance Method Details

#decode_payload(payload, schema:) ⇒ Object



12
13
14
# File 'lib/deimos/schema_backends/proto_schema_registry.rb', line 12

def decode_payload(payload, schema:)
  self.class.proto_turf.decode(payload)
end

#encode_payload(payload, schema: nil, topic: nil) ⇒ Object



17
18
19
20
# File 'lib/deimos/schema_backends/proto_schema_registry.rb', line 17

def encode_payload(payload, schema: nil, topic: nil)
  msg = payload.is_a?(Hash) ? proto_schema.msgclass.new(**payload) : payload
  self.class.proto_turf.encode(msg, subject: topic)
end