Class: Deimos::AvroDataDecoder

Inherits:
AvroDataCoder show all
Defined in:
lib/deimos/avro_data_decoder.rb

Overview

Service Object to decode avro messages

Instance Attribute Summary

Attributes inherited from AvroDataCoder

#config, #namespace, #schema, #schema_store

Instance Method Summary collapse

Methods inherited from AvroDataCoder

#avro_schema, #initialize

Constructor Details

This class inherits a constructor from Deimos::AvroDataCoder

Instance Method Details

#decode(payload, schema: nil) ⇒ Hash

Decode some data.

Parameters:

  • payload (Hash|String)
  • schema (String) (defaults to: nil)

Returns:

  • (Hash)


13
14
15
16
# File 'lib/deimos/avro_data_decoder.rb', line 13

def decode(payload, schema: nil)
  schema ||= @schema
  avro_turf_messaging.decode(payload, schema_name: schema)
end

#decode_key(payload, key_id) ⇒ Object

Returns the decoded key (int/long/string).

Parameters:

  • payload (String)

    the encoded key.

  • key_id (String|Symbol)

Returns:

  • (Object)

    the decoded key (int/long/string).



30
31
32
33
34
# File 'lib/deimos/avro_data_decoder.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

#decode_local(payload, schema: nil) ⇒ Hash

Decode against a local schema.

Parameters:

  • payload (Hash)
  • schema (String) (defaults to: nil)

Returns:

  • (Hash)


22
23
24
25
# File 'lib/deimos/avro_data_decoder.rb', line 22

def decode_local(payload, schema: nil)
  schema ||= @schema
  avro_turf.decode(payload, schema_name: schema, namespace: @namespace)
end