Class: Telos::Message::Outgoing

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

Instance Method Summary collapse

Constructor Details

#initialize(command, arguments = {}) ⇒ Outgoing

Returns a new instance of Outgoing.



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

def initialize(command, arguments = {})
  @command = command
  @arguments = arguments
end

Instance Method Details

#payloadObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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_sizeObject



44
45
46
# File 'lib/telos/message/outgoing.rb', line 44

def payload_size
  payload.size
end

#payload_xorObject



48
49
50
# File 'lib/telos/message/outgoing.rb', line 48

def payload_xor
  0xA5A55A5A ^ payload_size
end

#to_bytesObject



9
10
11
12
13
14
15
# File 'lib/telos/message/outgoing.rb', line 9

def to_bytes
  [
      dword(payload_size),
      dword(payload_xor),
      payload
  ].join
end