Class: EvilEvents::Core::Events::Serializers::MessagePack::Engines::Mpacker Private
- Inherits:
-
Base::AbstractEngine
- Object
- Base::AbstractEngine
- EvilEvents::Core::Events::Serializers::MessagePack::Engines::Mpacker
- Defined in:
- lib/evil_events/plugins/mpacker_engine/mpacker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #factory ⇒ ::MessagePack::Factory readonly private private
Instance Method Summary collapse
- #dump(serialization_state) ⇒ String private
-
#initialize(config) ⇒ Mpacker
constructor
private
A new instance of Mpacker.
- #load(message) ⇒ EventSerializationState private
- #packer ⇒ ::MessagePack::Packer private private
- #unpacker ⇒ ::MessagePack::Unpacker private private
Methods inherited from Base::AbstractEngine
Constructor Details
#initialize(config) ⇒ Mpacker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Mpacker.
12 13 14 15 16 |
# File 'lib/evil_events/plugins/mpacker_engine/mpacker.rb', line 12 def initialize(config) configurator = config.settings.[:mpacker][:configurator] raise EvilEvents::SerializationEngineError unless configurator.is_a?(Proc) @factory = ::MessagePack::Factory.new.tap { |factory| configurator.call(factory) } end |
Instance Attribute Details
#factory ⇒ ::MessagePack::Factory (readonly, private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 |
# File 'lib/evil_events/plugins/mpacker_engine/mpacker.rb', line 60 def factory @factory end |
Instance Method Details
#dump(serialization_state) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 28 29 30 |
# File 'lib/evil_events/plugins/mpacker_engine/mpacker.rb', line 23 def dump(serialization_state) packer.pack( id: serialization_state.id, type: serialization_state.type, payload: serialization_state.payload, metadata: serialization_state. ).to_str end |
#load(message) ⇒ EventSerializationState
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/evil_events/plugins/mpacker_engine/mpacker.rb', line 38 def load() begin event_data = unpacker.feed().unpack raise EvilEvents::SerializationEngineError unless event_data.is_a?(::Hash) rescue ::MessagePack::UnpackError, ArgumentError, TypeError raise EvilEvents::SerializationEngineError end restore_serialization_state( id: event_data[:id], type: event_data[:type], payload: event_data[:payload], metadata: event_data[:metadata] ) end |
#packer ⇒ ::MessagePack::Packer (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/evil_events/plugins/mpacker_engine/mpacker.rb', line 66 def packer factory.packer end |
#unpacker ⇒ ::MessagePack::Unpacker (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 |
# File 'lib/evil_events/plugins/mpacker_engine/mpacker.rb', line 74 def unpacker factory.unpacker(symbolize_keys: true) end |