Class: CommandSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-ruby-sdk/core/protocol/command_serializer.rb

Instance Method Summary collapse

Instance Method Details

#serialize(root_command, connection_data = nil, runtime_version = 0) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/javonet-ruby-sdk/core/protocol/command_serializer.rb', line 7

def serialize(root_command, connection_data = nil, runtime_version = 0)
  buffer = ''.dup
  buffer << [root_command.runtime_name, runtime_version].pack('C*')

  if connection_data
    buffer << connection_data.serialize_connection_data.pack('C*')
  else
    buffer << [0, 0, 0, 0, 0, 0, 0].pack('C*')
  end
  buffer << [RuntimeNameJavonet::RUBY, root_command.command_type].pack('C*')

  # Payload (recursive)
  serialize_recursively(root_command, buffer)

  buffer.bytes
end