SMPPEX.Pdu.Multipart (smppex v3.0.4) View Source

Module for operating with multipart information packed as UDH in message body.

Link to this section Summary

Functions

Extracts multipart information from PDU or directly from binary message. This function is deprecated. Use extract_from_pdu/1 or extract_from_message/1 instead.

Extracts multipart information from already parsed list of UDH IEs.

Extracts multipart information from binary message.

Extracts multipart information from PDU.

Generates IE encoding multipart information.

Prepends message with multipart info encoded as UDH.

Splits message into parts prepending each part with multipart information UDH so that the resulting size of each part does not exceed max_len bytes.

Splits message into parts not exceeding max_split bytes and prepending each part with multipart information UDH. The message is not split if its size does not exceed max_len bytes.

Link to this section Types

Specs

actual_part_info() ::
  {ref_num :: non_neg_integer(), count :: non_neg_integer(),
   seq_num :: non_neg_integer()}

Specs

extract_result() :: {:ok, part_info(), binary()} | {:error, term()}

Specs

part_info() :: :single | actual_part_info()

Specs

split_result() :: {:ok, :unsplit} | {:ok, :split, [binary()]} | {:error, term()}

Link to this section Functions

Specs

extract(SMPPEX.Pdu.t() | binary()) :: extract_result()

Extracts multipart information from PDU or directly from binary message. This function is deprecated. Use extract_from_pdu/1 or extract_from_message/1 instead.

Returns one of the following:

  • {:ok, :single, message} if the message does not contain any multipart information and represents a single message;
  • {:ok, {ref_num, count, seq_num}, message} if the original message contains multipart information in UDH fields. The outcoming message is cleared from UDH bytes.
  • {:error, reason}

Example

iex> data = <<0x05, 0x00, 0x03, 0x03, 0x02, 0x01, "message">>
iex> SMPPEX.Pdu.Multipart.extract(data)
{:ok, {3,2,1}, "message"}

iex> data = <<0x06, 0x08, 0x04, 0x00, 0x03, 0x02, 0x01, "message">>
iex> SMPPEX.Pdu.Multipart.extract(data)
{:ok, {3,2,1}, "message"}

iex> pdu = Pdu.new({1,0,1}, %{esm_class: 0b01000000, short_message: <<0x05, 0x00, 0x03, 0x03, 0x02, 0x01, "message">>})
iex> SMPPEX.Pdu.Multipart.extract(pdu)
{:ok, {3,2,1}, "message"}

iex> pdu = Pdu.new({1,0,1}, %{short_message: <<0x05, 0x00, 0x03, 0x03, 0x02, 0x01, "message">>})
iex> SMPPEX.Pdu.Multipart.extract(pdu)
{:error, "Message is not multipart"}

Specs

extract_from_ies([SMPPEX.Pdu.UDH.ie()]) :: {:ok, part_info()} | {:error, any()}

Extracts multipart information from already parsed list of UDH IEs.

Return one of the following:

  • {:ok, :single} if IEs do not contain any multipart message related ones;
  • {:ok, {ref_num, count, seq_num}} if there are multipart message related IEs (the first is taken);
  • {:error, reason} in case of errors.

Example

iex> ies = [{0, <<0x03, 0x02, 0x01>>}]
iex> SMPPEX.Pdu.Multipart.extract_from_ies(ies)
{:ok, {3, 2, 1}}

iex> ies = [{0, <<0x03, 0x02, 0x01>>}, {8, <<0x00, 0x04, 0x02, 0x01>>}]
iex> SMPPEX.Pdu.Multipart.extract_from_ies(ies)
{:ok, {3, 2, 1}}

iex> ies = [{8, <<0x00, 0x03, 0x02, 0x01>>}]
iex> SMPPEX.Pdu.Multipart.extract_from_ies(ies)
{:ok, {3, 2, 1}}

iex> ies = [{8, <<0x00, 0x03, 0x02>>}]
iex> SMPPEX.Pdu.Multipart.extract_from_ies(ies)
{:error, "Invalid 16bit refrence number concatenated short messages info"}

iex> ies = []
iex> SMPPEX.Pdu.Multipart.extract_from_ies(ies)
{:ok, :single}
Link to this function

extract_from_message(message)

View Source

Specs

extract_from_message(binary()) :: extract_result()

Extracts multipart information from binary message.

Returns one of the following:

  • {:ok, :single, message} if the message does not contain any multipart information and represents a single message. The outcoming message is cleared from UDH bytes.
  • {:ok, {ref_num, count, seq_num}, message} if the original message contains multipart information in UDH fields. The outcoming message is cleared from UDH bytes.
  • {:error, reason}

Example

iex> data = <<0x05, 0x00, 0x03, 0x03, 0x02, 0x01, "message">>
iex> SMPPEX.Pdu.Multipart.extract_from_message(data)
{:ok, {3,2,1}, "message"}

iex> data = <<0x06, 0x08, 0x04, 0x00, 0x03, 0x02, 0x01, "message">>
iex> SMPPEX.Pdu.Multipart.extract_from_message(data)
{:ok, {3,2,1}, "message"}

Specs

extract_from_pdu(SMPPEX.Pdu.t()) :: extract_result()

Extracts multipart information from PDU.

Returns one of the following:

  • {:ok, :single, message} if the message does not contain any multipart information and represents a single message. The outcoming message is cleared from UDH bytes.
  • {:ok, {ref_num, count, seq_num}, message} if the original message contains multipart information in UDH fields. The outcoming message is cleared from UDH bytes.
  • {:error, reason}

Example

iex> pdu = Pdu.new({1,0,1}, %{esm_class: 0b01000000, short_message: <<0x05, 0x00, 0x03, 0x03, 0x02, 0x01, "message">>})
iex> SMPPEX.Pdu.Multipart.extract_from_pdu(pdu)
{:ok, {3,2,1}, "message"}

iex> pdu = Pdu.new({1,0,1}, %{short_message: <<0x05, 0x00, 0x03, 0x03, 0x02, 0x01, "message">>})
iex> SMPPEX.Pdu.Multipart.extract_from_pdu(pdu)
{:error, "Message is not multipart"}

Specs

multipart_ie(actual_part_info()) ::
  {:error, term()} | {:ok, SMPPEX.Pdu.UDH.ie()}

Generates IE encoding multipart information.

Example

iex> SMPPEX.Pdu.Multipart.multipart_ie({3,2,1})
{:ok, {0, <<0x03, 0x02, 0x01>>}}

iex> SMPPEX.Pdu.Multipart.multipart_ie({256,2,1})
{:ok, {8, <<0x01, 0x00, 0x02, 0x01>>}}

iex> SMPPEX.Pdu.Multipart.multipart_ie({1, 1, 256})
{:error, "Invalid sequence number in multipart info"}
Link to this function

prepend_message_with_part_info(part_info, message)

View Source

Specs

prepend_message_with_part_info(actual_part_info(), binary()) ::
  {:error, term()} | {:ok, binary()}

Prepends message with multipart info encoded as UDH.

Example

iex> SMPPEX.Pdu.Multipart.prepend_message_with_part_info({3,2,1}, "message")
{:ok, <<0x05, 0x00, 0x03, 0x03, 0x02, 0x01, "message">>}

iex> SMPPEX.Pdu.Multipart.prepend_message_with_part_info({256,2,1}, "message")
{:ok, <<0x06, 0x08, 0x04, 0x01, 0x00, 0x02, 0x01, "message">>}
Link to this function

split_message(ref_num, message, max_len)

View Source

Specs

split_message(ref_num :: integer(), message :: binary(), max_len :: integer()) ::
  split_result()

Splits message into parts prepending each part with multipart information UDH so that the resulting size of each part does not exceed max_len bytes.

The result is one of the following:

  • {:ok, :unsplit} if the message already fits into max_len bytes;
  • {:ok, :split, parts} if the message was succesfully split into parts;
  • {:error, reason} in case of errors.

Example

iex> SMPPEX.Pdu.Multipart.split_message(123, "abc", 3)
{:ok, :unsplit}

iex> SMPPEX.Pdu.Multipart.split_message(123, "abcdefg", 6)
{:error, "Invalid limits for splitting message"}

iex> SMPPEX.Pdu.Multipart.split_message(123, "abcdefghi", 8)
{:ok, :split, [
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x01, "ab">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x02, "cd">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x03, "ef">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x04, "gh">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x05, "i">>
]}
Link to this function

split_message(ref_num, message, max_len, max_split)

View Source

Specs

split_message(
  ref_num :: integer(),
  message :: binary(),
  max_len :: integer(),
  max_split :: integer()
) :: split_result()

Splits message into parts not exceeding max_split bytes and prepending each part with multipart information UDH. The message is not split if its size does not exceed max_len bytes.

The results format is the same as in split_message/3.

Example

iex> SMPPEX.Pdu.Multipart.split_message(123, "abcdefghi", 0, 2)
{:ok, :split, [
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x01, "ab">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x02, "cd">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x03, "ef">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x04, "gh">>,
  <<0x05, 0x00, 0x03, 0x7b, 0x05, 0x05, "i">>
]}