Class: EventStoreClient::Serializer::EventDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/event_store_client/serializer/event_deserializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serializer:, config:) ⇒ EventDeserializer

Returns a new instance of EventDeserializer.

Parameters:



23
24
25
26
# File 'lib/event_store_client/serializer/event_deserializer.rb', line 23

def initialize(serializer:, config:)
  @serializer = serializer
  @config = config
end

Class Method Details

.call(raw_event, config:, serializer: Serializer::Json) ⇒ EventStoreClient::DeserializedEvent

Parameters:

  • raw_event (EventStore::Client::Streams::ReadResp::ReadEvent::RecordedEvent, EventStore::Client::PersistentSubscriptions::ReadResp::ReadEvent::RecordedEvent)
  • config (EventStoreClient::Config)
  • serializer (#serialize, #deserialize) (defaults to: Serializer::Json)

Returns:



13
14
15
# File 'lib/event_store_client/serializer/event_deserializer.rb', line 13

def call(raw_event, config:, serializer: Serializer::Json)
  new(config: config, serializer: serializer).call(raw_event)
end

Instance Method Details

#call(raw_event) ⇒ EventStoreClient::DeserializedEvent

Parameters:

  • raw_event (EventStore::Client::Streams::ReadResp::ReadEvent::RecordedEvent, EventStore::Client::PersistentSubscriptions::ReadResp::ReadEvent::RecordedEvent)

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/event_store_client/serializer/event_deserializer.rb', line 30

def call(raw_event)
  data = serializer.deserialize(normalize_serialized(raw_event.data))
   = serializer.deserialize(normalize_serialized(raw_event.))
   = raw_event..to_h

  event_class = EventStoreClient::EventClassResolver.new(config).resolve(['type'])
  event_class.new(
    skip_validation: true,
    id: raw_event.id.string,
    title: "#{raw_event.stream_revision}@#{raw_event.stream_identifier.stream_name}",
    type: ['type'],
    data: data,
    metadata: ,
    custom_metadata: ,
    stream_revision: raw_event.stream_revision,
    commit_position: raw_event.commit_position,
    prepare_position: raw_event.prepare_position,
    stream_name: raw_event.stream_identifier.stream_name
  )
end