elephant v0.2.1 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.

Link to this section Summary

Functions

Get header by key

Checks if a header exists, by both key and value

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

Splits a string into two at the first zero-byte.

Examples

iex> Elephant.Message.read_until_zero(<<65, 66, 0, 67, 68>>)
{"AB", "CD"}

iex> Elephant.Message.read_until_zero(<<65, 66, 0>>)
{"AB", ""}

iex> Elephant.Message.read_until_zero(<<0, 67, 68>>)
{"", "CD"}

iex> Elephant.Message.read_until_zero(<<65, 66>>)
{"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"