Class: Smpp::OptionalParameter

Inherits:
Object
  • Object
show all
Defined in:
lib/smpp/optional_parameter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, value) ⇒ OptionalParameter

Returns a new instance of OptionalParameter.



5
6
7
8
# File 'lib/smpp/optional_parameter.rb', line 5

def initialize(tag, value)
  @tag = tag
  @value = value
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



3
4
5
# File 'lib/smpp/optional_parameter.rb', line 3

def tag
  @tag
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/smpp/optional_parameter.rb', line 3

def value
  @value
end

Class Method Details

.from_wire_data(data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/smpp/optional_parameter.rb', line 20

def from_wire_data(data)

  return nil if data.nil?
  tag, length, remaining_bytes = data.unpack('H4na*')
  tag = tag.hex

  if tag == 0 || length.nil?
    Smpp::Base.logger.error "invalid data, cannot parse optional parameters tag: #{tag} length:#{length}"
    length = length.to_i
  end

  value = remaining_bytes.slice!(0...length)

  return new(tag, value), remaining_bytes
end

Instance Method Details

#[](symbol) ⇒ Object



10
11
12
# File 'lib/smpp/optional_parameter.rb', line 10

def [](symbol)
  self.send symbol
end

#to_sObject



14
15
16
# File 'lib/smpp/optional_parameter.rb', line 14

def to_s
  self.inspect
end