Class: PDUTools::Encoder

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/pdu_tools/encoder.rb

Defined Under Namespace

Classes: MessagePart

Constant Summary collapse

DEFAULT_OPTIONS =
{
    klass: nil,
    require_receipt: false,
    expiry_seconds: nil
}

Constants included from Helpers

Helpers::GSM_03_38_ESCAPES

Instance Method Summary collapse

Methods included from Helpers

#dec2hexbyte, #decode16bit, #decode7bit, #decode8bit, #encode7bit, #encode8bit, #gsm0338_to_utf8, #normal2swapped, #swapped2normal, #utf8_to_gsm0338

Constructor Details

#initialize(options) ⇒ Encoder

PDU structure - read.pudn.com/downloads150/sourcecode/embed/646395/Short%20Message%20in%20PDU%20Encoding.pdf X Bytes - SMSC - Service Center Address 1 Byte - Flags / PDU Type

- 1 bit  Reply Path parameter indicator
- 1 bit  User Data Header Indicator
- 1 bit  Status Request Report
- 2 bits Validity Period Format
- 1 bit  Reject Duplicates
- 2 bits Message Type Indicator

2 Bytes - Message Reference X Bytes - Address length and address 1 Byte - Protocol identificator (PID) 1 Byte - Data Coding Scheme X Bytes - Validity Period 1 Byte - User Data Length X Bytes - User Data

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pdu_tools/encoder.rb', line 30

def initialize options
  raise ArgumentError, :recipient unless options[:recipient]
  raise ArgumentError, :message unless options[:message]
  @options = DEFAULT_OPTIONS.merge options

  @smsc = '00' # Phone Specified
  @message_parts, @alphabet = prepare_message options[:message]
  @pdu_type = pdu_type @concatenated_message_reference, options[:require_receipt], options[:expiry_seconds]
  @message_reference = '00' # Phone Specified
  @address = prepare_recipient options[:recipient]
  @protocol_identifier = '00' # SMS
  @data_coding_scheme = data_coding_scheme options[:klass], @alphabet
  @validity_period = validity_period options[:expiry_seconds]
end

Instance Method Details

#encodeObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pdu_tools/encoder.rb', line 45

def encode
  head = ""
  head << @smsc
  head << @pdu_type
  head << @message_reference
  head << @address
  head << @protocol_identifier
  head << @data_coding_scheme
  head << @validity_period
  pdus = []
  @message_parts.each do |part|
    pdus << PDU.new(head + part.length + part.data)
  end
  pdus
end