class Telos::Message::Incoming

Public Class Methods

new(data) click to toggle source
# File lib/telos/message/incoming.rb, line 4
def initialize(data)
  @data = data
end

Public Instance Methods

argument_size() click to toggle source
# File lib/telos/message/incoming.rb, line 12
def argument_size
  from_word(@data.byteslice(4,2))
end
arguments() click to toggle source
# 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
command() click to toggle source
# File lib/telos/message/incoming.rb, line 8
def command
  from_dword(@data.byteslice(0,4))
end
inspect() click to toggle source
# File lib/telos/message/incoming.rb, line 42
def inspect
  %{#<Telos::Message::Incoming command="#{command}" arguments=#{arguments.inspect}>}
end
to_hash() click to toggle source
# File lib/telos/message/incoming.rb, line 38
def to_hash
  arguments
end

Private Instance Methods

from_dword(string) click to toggle source
# File lib/telos/message/incoming.rb, line 47
def from_dword(string)
  string.unpack('N')[0]
end
from_word(string) click to toggle source
# File lib/telos/message/incoming.rb, line 51
def from_word(string)
  string.unpack('n')[0]
end