Spear.Event.to_proposed_message

You're seeing just the function to_proposed_message, go back to Spear.Event module for more information.
Link to this function

to_proposed_message(event, encoder_mapping \\ %{"application/json" => &Jason.encode!/1})

View Source (since 0.1.0)

Specs

to_proposed_message(t(), encoder_mapping :: %{}) :: AppendReq.t()

Converts a Spear.Event into an append-request struct which proposes a new message

Note that each event must be individually structured as an AppendReq message in order to be written to an EventStoreDB. The RPC definition for writing events specifies a stream input, though, so all AppendReq events passed to Spear.append/4 will be batched into a single write operation.

rpc Append (stream AppendReq) returns (AppendResp);

These messages are serialized to wire data before being sent to the EventStoreDB when using Spear.append/4 to write events via protobuf encoding.

encoder_mapping is a mapping of content-types to 1-arity encode functions. The default is

%{"application/json" => &Jason.encode!/1}

The Spear.Event.t/0's .metadata.content_type value will be searched in this map. If an encoder is found for that content-type, the event body will be encoded with the encoding function. If no encoder is found, the event body will be passed as-is.

To set up an encoder for something like Erlang term format, an encoding map like the following could be used

%{"application/vnd.erlang-term-format" => &:erlang.term_to_binary/1}

In order to disable JSON encoding, pass an empty map %{} as the encoder_mapping

Examples

iex> events
[%Spear.Event{}, %Spear.Event{}, ..]
iex> events |> Enum.map(&Spear.Event.to_proposed_message/1)
[%EventStore.Client.Streams.AppendReq{}, ..]