Class: Interpreter

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

Class Method Summary collapse

Class Method Details

.execute(command, connection_type, connection_data) ⇒ Object



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

def self.execute(command, connection_type, connection_data)
  message_byte_array = CommandSerializer.serialize(command, connection_data)
  if command.runtime_name == RuntimeNameJavonet::RUBY && connection_type == ConnectionType::IN_MEMORY
    require_relative '../receiver/receiver'
    response_byte_array = Receiver.send_command(message_byte_array)[1]
  elsif connection_type == ConnectionType::WEB_SOCKET
    require_relative '../web_socket_client/web_socket_client'
    response_byte_array = WebSocketClient.send_message(connection_data.hostname, message_byte_array)
  else
    require_relative '../transmitter/transmitter'
    response_byte_array = Transmitter.send_command(message_byte_array, message_byte_array.length)
  end

  CommandDeserializer.new(response_byte_array).deserialize
end

.process(byte_array) ⇒ Object



22
23
24
25
# File 'lib/javonet-ruby-sdk/core/interpreter/interpreter.rb', line 22

def self.process(byte_array)
  received_command = CommandDeserializer.new(byte_array).deserialize
  Handler.handle_command(received_command)
end