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

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
23
# File 'lib/javonet-ruby-sdk/core/protocol/command_serializer.rb', line 7

def serialize(root_command, connection_data = nil, runtime_version = 0)
  buffer = []
  buffer << root_command.runtime_name
  buffer << runtime_version

  if connection_data
    buffer.concat(connection_data.serialize_connection_data)
  else
    buffer.concat([0, 0, 0, 0, 0, 0, 0])
  end

  buffer << RuntimeName::RUBY
  buffer << root_command.command_type

  serialize_recursively(root_command, buffer)
  buffer
end

#serialize_recursively(command, buffer) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/javonet-ruby-sdk/core/protocol/command_serializer.rb', line 25

def serialize_recursively(command, buffer)
  command.payload.each do |item|
    if item.is_a?(Command)
      buffer.concat(TypeSerializer.serialize_command(item))
      serialize_recursively(item, buffer)
    elsif TypesHandler.primitive_or_none?(item)
      buffer.concat(TypeSerializer.serialize_primitive(item))
    else
      cached_reference = ReferencesCache.new.cache_reference(item)
      ref_command = Command.new(RuntimeName::RUBY, CommandType::REFERENCE, cached_reference)
      serialize_recursively(ref_command, buffer)
    end
  end
end