View Source SMPPEX.Pdu.Multipart (smppex v3.2.3)
Module for operating with multipart information packed as UDH in message body.
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.
Types
@type actual_part_info() :: {ref_num :: non_neg_integer(), count :: non_neg_integer(), seq_num :: non_neg_integer()}
@type part_info() :: :single | actual_part_info()
Functions
@spec 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 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"}
@spec 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}
@spec extract_from_message(binary()) :: extract_result()
Extracts multipart information from binary message.
Returns one of the following:
{:ok, :single, message}
if themessage
does not contain any multipart information and represents a single message. The outcomingmessage
is cleared from UDH bytes.{: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_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"}
@spec extract_from_pdu(SMPPEX.Pdu.t()) :: extract_result()
Extracts multipart information from PDU.
Returns one of the following:
{:ok, :single, message}
if themessage
does not contain any multipart information and represents a single message. The outcomingmessage
is cleared from UDH bytes.{: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> 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"}
@spec 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"}
@spec 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">>}
@spec 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">>
]}
@spec 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">>
]}