Class: LibSL::LLPacketNumber
- Inherits:
-
Object
- Object
- LibSL::LLPacketNumber
- Defined in:
- lib/types.rb
Instance Attribute Summary collapse
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#number ⇒ Object
Returns the value of attribute number.
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(number) ⇒ LLPacketNumber
constructor
A new instance of LLPacketNumber.
Constructor Details
#initialize(number) ⇒ LLPacketNumber
Returns a new instance of LLPacketNumber.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/types.rb', line 33 def initialize(number) @number = number if @number < 0xff then @frequency = :high elsif @number < 0xffff then @frequency = :medium elsif @number < 0xfffffffa then @frequency = :low else @frequency = :fixed end end |
Instance Attribute Details
#frequency ⇒ Object
Returns the value of attribute frequency.
32 33 34 |
# File 'lib/types.rb', line 32 def frequency @frequency end |
#number ⇒ Object
Returns the value of attribute number.
32 33 34 |
# File 'lib/types.rb', line 32 def number @number end |
Class Method Details
.decode(data) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/types.rb', line 4 def self.decode(data) data = data.unpack('C1a*') num = data.shift() unless num < 0xff then data = data[0].unpack('C1a*') num = (num << 8) + data.shift() end unless num < 0xffff then data = data[0].unpack('C2a*') num = (num << 16) + (data.shift() << 8) + data.shift() end if [*data].length > 0 then data = data[0] else data = nil end return self.new(num), data end |
Instance Method Details
#encode ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/types.rb', line 23 def encode() case @frequency when :high then data = [@number].pack('C') when :medium then data = [@number].pack('n') else data = [@number].pack('N') end return data end |