elephant v0.2.11 Elephant.Message View Source
Representation of sent or received messages.
Each message has three components:
- command
- list of headers
- body
The command is an atom and only commands specified in the STOMP specification
are allowed. Each header is a 2-tuple {"header-key", "header-value"}
. The
body is a binary.
All commands are:
:send
:message
:error
:connect
:connected
:disconnect
:receipt
:subscribe
:unsubscribe
Link to this section Summary
Functions
Apply “Value Decoding” for header values
Get header by key
Checks if a header exists, by both key and value
Turn list of raw header lines into key value pairs
Splits a string into two at the first zero-byte
Removes CR / CRLF at the beginning of the string
Link to this section Functions
Apply “Value Decoding” for header values.
See https://stomp.github.io/stomp-specification-1.2.html#Valuea_Encoding
Examples
iex> Elephant.Message.apply_value_decoding(<<”foo”, 92, 92, “bar”>>) <<”foo”, 92, “bar”>>
iex> Elephant.Message.apply_value_decoding(<<”foo”, 92, 99, “bar”>>) “foo:bar”
iex> Elephant.Message.apply_value_decoding(<<”foo”, 92, 110, “bar”>>) <<”foo”, 10, “bar”>>
iex> Elephant.Message.apply_value_decoding(<<”foo”, 92, 114, “bar”>>) <<”foo”, 13, “bar”>>
Get header by key.
Returns {:ok, value}
or {:error, :notfound}
if the header does not exist.
Checks if a header exists, by both key and value.
Turn list of raw header lines into key value pairs.
iex> Elephant.Message.normalize_headers([<<”message-id:ID”, 92, 99, “b39dd”>>]) [{“message-id”, “ID:b39dd”}]
Splits a string into two at the first zero-byte.
Examples
iex> Elephant.Message.read_until_zero(<<65, 66, 0, 67, 68>>)
{:ok, "AB", "CD"}
iex> Elephant.Message.read_until_zero(<<65, 66, 0>>)
{:ok, "AB", ""}
iex> Elephant.Message.read_until_zero(<<0, 67, 68>>)
{:ok, "", "CD"}
iex> Elephant.Message.read_until_zero(<<65, 66>>)
{:nozero, "AB"}