smppex v2.1.0 SMPPEX.Pdu.Multipart 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
Extracts multipart information from already parsed list of UDH IEs
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
actual_part_info() :: {ref_num :: non_neg_integer, count :: non_neg_integer, seq_num :: non_neg_integer}
extract_result() :: {:ok, part_info, binary} | {:error, term}
split_result :: {:ok, :unsplit} | {:ok, :split, [binary]} | {:error, term}
Link to this section Functions
Extracts multipart information from PDU or directly from binary message.
Return one of the following:
{:ok, :single, message}
if themessage
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 outcomingmessage
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"}
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}
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"}
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">>}
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 intomax_len
bytes;{:ok, :split, parts}
if the message was succesfully split intoparts
;{: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">>
]}
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">>
]}