class Telos::Message::Outgoing

Public Class Methods

new(command, arguments = {}) click to toggle source
# File lib/telos/message/outgoing.rb, line 4
def initialize(command, arguments = {})
  @command = command
  @arguments = arguments
end

Public Instance Methods

payload() click to toggle source
# File lib/telos/message/outgoing.rb, line 17
def payload
  [
      dword(@command),
      word(@arguments.size),
      @arguments.map do |name, argument|
        content = case argument
                  when String
                    [
                        "\x02", # Array Type
                        word(argument.length + 1), # Argument length + end
                        argument + "\x00"
                    ]
                  when Integer
                    [
                        "\x01", # DWORD type
                        dword(argument)
                    ]
                  end

        [
            name.to_s.upcase,
            content
        ]
      end
  ].flatten.join
end
payload_size() click to toggle source
# File lib/telos/message/outgoing.rb, line 44
def payload_size
  payload.size
end
payload_xor() click to toggle source
# File lib/telos/message/outgoing.rb, line 48
def payload_xor
  0xA5A55A5A ^ payload_size
end
to_bytes() click to toggle source
# File lib/telos/message/outgoing.rb, line 9
def to_bytes
  [
      dword(payload_size),
      dword(payload_xor),
      payload
  ].join
end

Private Instance Methods

dword(content) click to toggle source
# File lib/telos/message/outgoing.rb, line 53
def dword(content)
  [content].pack('N')
end
word(content) click to toggle source
# File lib/telos/message/outgoing.rb, line 57
def word(content)
  [content].pack('n')
end