Class: Telos::Message::Incoming

Inherits:
Object
  • Object
show all
Defined in:
lib/telos/message/incoming.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Incoming

Returns a new instance of Incoming.



4
5
6
# File 'lib/telos/message/incoming.rb', line 4

def initialize(data)
  @data = data
end

Instance Method Details

#argument_sizeObject



12
13
14
# File 'lib/telos/message/incoming.rb', line 12

def argument_size
  from_word(@data.byteslice(4,2))
end

#argumentsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/telos/message/incoming.rb', line 16

def arguments
  pos = 6
  arguments = {}
  argument_size.times do
    key = @data.byteslice(pos, 4)
    type = @data.byteslice(pos + 4, 1)
    case type
    when "\x02" # Array / String
      size = from_word(@data.byteslice(pos + 5, 2))
      value = @data.byteslice(pos + 7, size - 1)
      pos += 7 + size
    when "\x01" # DWord
      value = from_dword(@data.byteslice(pos + 5, 4))
      pos += 5 + 4
    end

    arguments[key] = value
  end

  arguments
end

#commandObject



8
9
10
# File 'lib/telos/message/incoming.rb', line 8

def command
  from_dword(@data.byteslice(0,4))
end

#inspectObject



42
43
44
# File 'lib/telos/message/incoming.rb', line 42

def inspect
  %{#<Telos::Message::Incoming command="#{command}" arguments=#{arguments.inspect}>}
end

#to_hashObject



38
39
40
# File 'lib/telos/message/incoming.rb', line 38

def to_hash
  arguments
end