View Source Mammoth.Message (mammoth v0.4.4)

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:

  • :ack
  • :nack
  • :begin
  • :commit
  • :abort
  • :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, either at the first null byte, or at content_length if non-nil. Terminal null byte is still required and consumed when specifying content_length

Removes single CR / CRLF pair 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

Examples

iex> Mammoth.Message.apply_value_decoding(<<"foo", 92, 92, "bar">>) <<"foo", 92, "bar">>

iex> Mammoth.Message.apply_value_decoding(<<"foo", 92, 99, "bar">>) "foo:bar"

iex> Mammoth.Message.apply_value_decoding(<<"foo", 92, 110, "bar">>) <<"foo", 10, "bar">>

iex> Mammoth.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> Mammoth.Message.normalize_headers([<<"message-id:ID", 92, 99, "b39dd">>]) [{"message-id", "ID:b39dd"}]

Link to this function

read_until_end(string, content_length)

View Source

Splits a string into two, either at the first null byte, or at content_length if non-nil. Terminal null byte is still required and consumed when specifying content_length

examples

Examples

iex> Mammoth.Message.read_until_end(<<65, 66, 0, 67, 68>>, nil)
{:ok, "AB", "CD"}

iex> Mammoth.Message.read_until_end(<<65, 66, 0>>, nil)
{:ok, "AB", ""}

iex> Mammoth.Message.read_until_end(<<0, 67, 68>>, nil)
{:ok, "", "CD"}

iex> Mammoth.Message.read_until_end(<<65, 66>>, nil)
{:incomplete, "AB"}
Link to this function

set_content_length_header(headers, body)

View Source

Removes single CR / CRLF pair at the beginning of the string.

examples

Examples

iex> Mammoth.Message.skip_newline("\n\n\nHello")
"\n\nHello"

iex> Mammoth.Message.skip_newline("Hello")
"Hello"

iex> Mammoth.Message.skip_newline("\r\n\r\nHello")
"\r\nHello"