Class: Interpreter

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

Constant Summary collapse

@@handler =
Handler.new

Instance Method Summary collapse

Instance Method Details

#execute(command, connection_type, connection_data) ⇒ Object



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

def execute(command, connection_type, connection_data)
  message_byte_array = CommandSerializer.new.serialize(command, connection_data)
  if command.runtime_name == RuntimeNameJavonet::RUBY && connection_type == ConnectionType::IN_MEMORY
    require_relative '../receiver/receiver_new'
    response_byte_array = Receiver.new.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



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

def process(byte_array)
  received_command = CommandDeserializer.new(byte_array).deserialize
  @@handler.handle_command(received_command)
end