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

Link to this function apply_value_decoding(value) View Source

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”>>

Link to this function get_header(message, key) View Source

Get header by key.

Returns {:ok, value} or {:error, :notfound} if the header does not exist.

Link to this function has_header(headers, arg) View Source

Checks if a header exists, by both key and value.

Link to this function normalize_headers(headers) View Source

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"}

Removes CR / CRLF at the beginning of the string.

Examples

iex> Elephant.Message.skip_newlines("\n\n\nHello")
"Hello"

iex> Elephant.Message.skip_newlines("Hello")
"Hello"

iex> Elephant.Message.skip_newlines("\r\n\r\nHello")
"Hello"