Class: EventStoreClient::SerializedEvent

Inherits:
Object
  • Object
show all
Includes:
Extensions::OptionsExtension
Defined in:
lib/event_store_client/serialized_event.rb

Instance Method Summary collapse

Methods included from Extensions::OptionsExtension

included, #initialize, #options_hash

Instance Method Details

#to_grpcHash

Constructs a hash that can be passed directly in the proposed_message attribute of the append request, or it can be used to instantiate the raw EventStore event. Example:

```ruby
serialized_event = EventStoreClient::SerializedEvent.new(
  id: 'some id',
  data: { foo: :bar },
  custom_metadata: { bar: :baz },
  metadata: { baz: :foo },
  serializer: EventStoreClient::Serializer::Json
)
# Compute proposed_message
EventStore::Client::Streams::AppendReq::ProposedMessage.new(
  serialized_event.to_grpc
)
# Compute raw event
EventStore::Client::Streams::ReadResp::ReadEvent::RecordedEvent.new(
  serialized_event.to_grpc
)
```

Returns:

  • (Hash)


34
35
36
37
38
39
40
41
# File 'lib/event_store_client/serialized_event.rb', line 34

def to_grpc
  {
    id: { string: id },
    data: serializer.serialize(data).force_encoding('ASCII-8BIT'),
    custom_metadata: serializer.serialize().force_encoding('ASCII-8BIT'),
    metadata: 
  }
end