Class: Hypertube::Core::Interpreter::Interpreter

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

Constant Summary collapse

COMMAND_SENT_FROM_CALLING_SIDE =
'Command sent from calling side'
COMMAND_RECEIVED_ON_CALLING_SIDE =
'Command received on calling side'
COMMAND_RECEIVED_ON_CALLED_SIDE =
'Command received on called side'
RESPONSE_SENT_FROM_CALLED_SIDE =
'Response sent from called side'

Class Method Summary collapse

Class Method Details

.build_context_metadata_payload(command, connection_data) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hypertube-ruby-sdk/core/interpreter/interpreter.rb', line 62

def self.(command, connection_data)
   = []
  headers = connection_data.get_headers

  headers.each do |key, value|
     << key
     << value
  end

  Hypertube::Utils::Command.new(command.runtime_name, Hypertube::Utils::CommandType::ARRAY, )
end

.execute(command, connection_data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hypertube-ruby-sdk/core/interpreter/interpreter.rb', line 17

def self.execute(command, connection_data)
  log_debug(COMMAND_SENT_FROM_CALLING_SIDE, command)
  message_byte_array = Hypertube::Core::Protocol::CommandSerializer.serialize(command, connection_data)
  if connection_data.is_a? Utils::WsConnectionData
    require_relative '../web_socket_client/web_socket_client'
    response_byte_array = Hypertube::Core::WebSocketClient::WebSocketClient.send_message(connection_data, message_byte_array)
  elsif connection_data.is_a? Utils::Http2ConnectionData
    require_relative '../http2_client/http2_client'
    response_byte_array = Hypertube::Core::Http2Client::Http2Client.send_message(connection_data, message_byte_array)
  else
    if connection_data.get_headers.length.positive?
       = (command, connection_data)
      command = Hypertube::Utils::Command.new(
        command.runtime_name,
        Hypertube::Utils::CommandType::CONTEXT_METADATA,
        [, command]
      )
      message_byte_array = Hypertube::Core::Protocol::CommandSerializer.serialize(command, connection_data)
    end
    if command.runtime_name == Hypertube::Utils::RuntimeNameHt::RUBY && (connection_data.is_a? Utils::InMemoryConnectionData)
      require_relative '../receiver/receiver'
      response_byte_array = Hypertube::Core::Receiver::Receiver.send_command(message_byte_array)[1]
    else
      require_relative '../transmitter/transmitter'
      response_byte_array = Hypertube::Core::Transmitter::Transmitter.send_command(
        message_byte_array,
        message_byte_array.length,
        connection_data.get_config
      )
    end
  end

  response_command = Hypertube::Core::Protocol::CommandDeserializer.new(response_byte_array).deserialize
  log_debug(COMMAND_RECEIVED_ON_CALLING_SIDE, response_command)
  response_command
end

.process(byte_array) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/hypertube-ruby-sdk/core/interpreter/interpreter.rb', line 54

def self.process(byte_array)
  received_command = Hypertube::Core::Protocol::CommandDeserializer.new(byte_array).deserialize
  log_debug(COMMAND_RECEIVED_ON_CALLED_SIDE, received_command)
  response_command = Hypertube::Core::Handler::Handler.handle_command(received_command)
  log_debug(RESPONSE_SENT_FROM_CALLED_SIDE, response_command)
  response_command
end