Class: CommandSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-ruby-sdk/core/protocol/command_serializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/protocol/command_serializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/protocol/command_serializer.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/protocol/command_serializer.rb

Instance Method Summary collapse

Constructor Details

#initializeCommandSerializer

Returns a new instance of CommandSerializer.



7
8
9
# File 'lib/javonet-ruby-sdk/core/protocol/command_serializer.rb', line 7

def initialize
  @buffer = []
end

Instance Method Details

#insert_into_buffer(arguments) ⇒ Object



34
35
36
# File 'lib/javonet-ruby-sdk/core/protocol/command_serializer.rb', line 34

def insert_into_buffer(arguments)
  @buffer += arguments
end

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



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

def serialize(root_command, connection_data = nil, runtime_version = 0)
  insert_into_buffer([root_command.runtime_name, runtime_version])
  if connection_data.nil?
    insert_into_buffer([0, 0, 0, 0, 0, 0, 0])
  else
    insert_into_buffer(connection_data.serialize_connection_data)
  end
  insert_into_buffer([RuntimeName::PYTHON, root_command.command_type])
  serialize_recursively(root_command)
  @buffer
end

#serialize_recursively(command) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/javonet-ruby-sdk/core/protocol/command_serializer.rb', line 23

def serialize_recursively(command)
  command.payload.each do |item|
    if item.is_a?(Command)
      insert_into_buffer(TypeSerializer.serialize_command(item))
      serialize_recursively(item)
    else
      insert_into_buffer(TypeSerializer.serialize_primitive(item))
    end
  end
end