smppex v2.2.6 SMPPEX.Pdu View Source

Module for working with Pdu struct representing parsed SMPP PDU

Link to this section Summary

Functions

Makes pdu be reply to the reply_to_pdu, i.e. assigns reply_to_pdu’s sequence_number to pdu

Checks if Pdu is a bind request

Checks if Pdu is a bind response

Returns Pdu’s command_id

Returns Pdu’s symbolic command name as an atom or :unknown if Pdu’s command_id do not correspond to any real SMPP command

Returns Pdu’s command_status

Returns Pdu’s :destination_addr, :dest_addr_ton and :dest_addr_npi fields in a tuple

Get Pdu mandatory or optional(TLV) field by name or by integer id. If Pdu does not have the field or field name is unknown, nil is returned

Get Pdu mandatory field. If Pdu does not have the field, nil is returned

Get the whole set of mandatory fields as a map

Construct a new Pdu from header, mandatory fields and optional(TLV) fields

Get Pdu optional(TLV) field by name or by integer id. If Pdu does not have the field or field name is unknown, nil is returned

Get the whole set of optional(TLV) fields as a map

Returns Pdu’s unique reference ref

Checks if Pdu is a response Pdu

Checks if two Pdus are copies of the same Pdu

Returns Pdu’s sequence_number

Sets Pdu mandatory field. New Pdu is returned

Sets Pdu optional field. New Pdu is returned

Returns Pdu’s :source_addr, :source_addr_ton and :source_addr_npi fields in a tuple

Checks if Pdu is a successful response Pdu

Link to this section Types

Link to this type addr() View Source
addr() :: {String.t, byte, byte}
Link to this type header() View Source
header ::
  {non_neg_integer, non_neg_integer, non_neg_integer} |
  non_neg_integer
Link to this type t() View Source
t() :: %SMPPEX.Pdu{command_id: non_neg_integer, command_status: non_neg_integer, mandatory: map, optional: map, ref: reference, sequence_number: non_neg_integer}

Link to this section Functions

Link to this function as_reply_to(pdu, reply_to_pdu) View Source
as_reply_to(pdu :: SMPPEX.Pdu.t, reply_to_pdu :: SMPPEX.Pdu.t) :: SMPPEX.Pdu.t

Makes pdu be reply to the reply_to_pdu, i.e. assigns reply_to_pdu’s sequence_number to pdu.

Examples

iex(1)> pdu1 = SMPPEX.Pdu.new({0x00000004, 0, 123})
iex(2)> pdu2 = SMPPEX.Pdu.new(0x80000004) |> SMPPEX.Pdu.as_reply_to(pdu1)
iex(3)> SMPPEX.Pdu.sequence_number(pdu2)
123
Link to this function bind?(pdu) View Source
bind?(t) :: boolean

Checks if Pdu is a bind request.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4)
iex(2)> SMPPEX.Pdu.bind?(pdu)
false
iex(3)> pdu = SMPPEX.Pdu.new(1)
iex(4)> SMPPEX.Pdu.bind?(pdu)
true
Link to this function bind_resp?(pdu) View Source
bind_resp?(t) :: boolean

Checks if Pdu is a bind response.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(0x80000004)
iex(2)> SMPPEX.Pdu.bind_resp?(pdu)
false
iex(3)> pdu = SMPPEX.Pdu.new(0x80000001)
iex(4)> SMPPEX.Pdu.bind_resp?(pdu)
true
Link to this function command_id(pdu) View Source
command_id(t) :: non_neg_integer

Returns Pdu’s command_id.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(1)
iex(2)> SMPPEX.Pdu.command_id(pdu)
1
Link to this function command_name(pdu) View Source
command_name(t) :: atom

Returns Pdu’s symbolic command name as an atom or :unknown if Pdu’s command_id do not correspond to any real SMPP command.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(1)
iex(2)> SMPPEX.Pdu.command_name(pdu)
:bind_receiver
iex(3)> pdu = SMPPEX.Pdu.new(1111111)
iex(4)> SMPPEX.Pdu.command_name(pdu)
:unknown
Link to this function command_status(pdu) View Source
command_status(t) :: non_neg_integer

Returns Pdu’s command_status.

Examples

iex(1)> pdu = SMPPEX.Pdu.new({1, 4, 123})
iex(2)> SMPPEX.Pdu.command_status(pdu)
4

Returns Pdu’s :destination_addr, :dest_addr_ton and :dest_addr_npi fields in a tuple.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4, %{destination_addr: "to", dest_addr_ton: 1, dest_addr_npi: 2})
iex(2)> SMPPEX.Pdu.dest(pdu)
{"to", 1, 2}
Link to this function field(pdu, id) View Source
field(t, integer | atom) :: any

Get Pdu mandatory or optional(TLV) field by name or by integer id. If Pdu does not have the field or field name is unknown, nil is returned.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4, %{short_message: "hi"}, %{0x0424 => "hello"})
iex(2)> SMPPEX.Pdu.field(pdu, :message_payload)
"hello"
iex(3)> SMPPEX.Pdu.field(pdu, 0x0424)
"hello"
iex(4)> SMPPEX.Pdu.field(pdu, :short_message)
"hi"
iex(5)> SMPPEX.Pdu.field(pdu, :unknown_name)
nil
Link to this function mandatory_field(pdu, name) View Source
mandatory_field(t, atom) :: term

Get Pdu mandatory field. If Pdu does not have the field, nil is returned.

Examples

iex(1)> pdu = SMPPEX.Pdu.new({1, 4, 123}, %{system_id: "system_id"})
iex(2)> SMPPEX.Pdu.mandatory_field(pdu, :system_id)
"system_id"
iex(3)> SMPPEX.Pdu.mandatory_field(pdu, :short_message)
nil
Link to this function mandatory_fields(pdu) View Source
mandatory_fields(t) :: map

Get the whole set of mandatory fields as a map.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4, %{short_message: "hi"}, %{0x0424 => "hello"})
iex(2)> SMPPEX.Pdu.mandatory_fields(pdu)
%{short_message: "hi"}
Link to this function new(header, mandatory_fields \\ %{}, optional_fields \\ %{}) View Source
new(header, map, map) :: t

Construct a new Pdu from header, mandatory fields and optional(TLV) fields.

Header may be either an integer, then it is treated as command id, or a tuple {command_id, command_status, sequence_number}

Each Pdu is created with a unique ref field, by which one can later trace Pdu’s identity.

Examples

iex(1)> SMPPEX.Pdu.new(1)
%SMPPEX.Pdu{command_id: 1, command_status: 0, mandatory: %{}, optional: %{},
ref: #Reference<0.0.3.215>, sequence_number: 0}
iex(2)> SMPPEX.Pdu.new({1, 0, 123}, %{system_id: "sid", password: "pass"}, %{})
%SMPPEX.Pdu{command_id: 1, command_status: 0,
mandatory: %{password: "pass", system_id: "sid"}, optional: %{},
ref: #Reference<0.0.3.219>, sequence_number: 123}
Link to this function optional_field(pdu, id) View Source
optional_field(t, integer | atom) :: any

Get Pdu optional(TLV) field by name or by integer id. If Pdu does not have the field or field name is unknown, nil is returned.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4, %{}, %{0x0424 => "hello"})
iex(2)> SMPPEX.Pdu.optional_field(pdu, :message_payload)
"hello"
iex(3)> SMPPEX.Pdu.optional_field(pdu, 0x0424)
"hello"
iex(4)> SMPPEX.Pdu.optional_field(pdu, :receipted_message_id)
nil
iex(5)> SMPPEX.Pdu.optional_field(pdu, :unknown_tlv_name)
nil
Link to this function optional_fields(pdu) View Source
optional_fields(t) :: map

Get the whole set of optional(TLV) fields as a map.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4, %{short_message: "hi"}, %{0x0424 => "hello"})
iex(2)> SMPPEX.Pdu.optional_fields(pdu)
%{0x0424 => "hello"}

Returns Pdu’s unique reference ref.

Examples

iex(1)> pdu = SMPPEX.Pdu.new({1, 4, 123})
iex(2)> is_reference SMPPEX.Pdu.ref(pdu)
true
Link to this function resp?(pdu) View Source
resp?(t) :: boolean

Checks if Pdu is a response Pdu.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4)
iex(2)> SMPPEX.Pdu.resp?(pdu)
false
iex(3)> pdu = SMPPEX.Pdu.new(0x80000004)
iex(4)> SMPPEX.Pdu.resp?(pdu)
true
Link to this function same?(pdu1, pdu2) View Source
same?(t, t) :: boolean

Checks if two Pdus are copies of the same Pdu.

Examples

iex(1)> pdu1 = SMPPEX.Pdu.new(4)
iex(2)> pdu2 = SMPPEX.Pdu.new(4)
iex(3)> SMPPEX.Pdu.same?(pdu1, pdu2)
false
iex(4)> SMPPEX.Pdu.same?(pdu1, pdu1)
true
Link to this function sequence_number(pdu) View Source
sequence_number(t) :: non_neg_integer

Returns Pdu’s sequence_number.

Examples

iex(1)> pdu = SMPPEX.Pdu.new({1, 4, 123})
iex(2)> SMPPEX.Pdu.sequence_number(pdu)
123
Link to this function set_mandatory_field(pdu, name, value) View Source
set_mandatory_field(t, atom, any) :: t

Sets Pdu mandatory field. New Pdu is returned.

Examples

iex(1)> pdu = SMPPEX.Pdu.new({1, 4, 123}, %{system_id: "system_id"})
iex(2)> pdu1 = SMPPEX.Pdu.set_mandatory_field(pdu, :password, "pass")
iex(3)> SMPPEX.Pdu.mandatory_field(pdu1, :password)
"pass"
Link to this function set_optional_field(pdu, name, value) View Source
set_optional_field(t, integer | atom, any) :: t

Sets Pdu optional field. New Pdu is returned.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4)
iex(2)> pdu1 = SMPPEX.Pdu.set_optional_field(pdu, :message_payload, "hello")
iex(3)> SMPPEX.Pdu.optional_field(pdu1, 0x0424)
"hello"

Returns Pdu’s :source_addr, :source_addr_ton and :source_addr_npi fields in a tuple.

Examples

iex(1)> pdu = SMPPEX.Pdu.new(4, %{source_addr: "from", source_addr_ton: 1, source_addr_npi: 2})
iex(2)> SMPPEX.Pdu.source(pdu)
{"from", 1, 2}
Link to this function success_resp?(pdu) View Source
success_resp?(t) :: boolean

Checks if Pdu is a successful response Pdu.

Examples

iex(1)> pdu = SMPPEX.Pdu.new({0x80000004, 1, 0})
iex(2)> SMPPEX.Pdu.success_resp?(pdu)
false
iex(3)> pdu = SMPPEX.Pdu.new({0x80000004, 0, 0})
iex(4)> SMPPEX.Pdu.success_resp?(pdu)
true