Class: TCellAgent::Rust::NativeAgentResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/tcell_agent/rust/native_agent_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native_method_name, response, response_len) ⇒ NativeAgentResponse

Returns a new instance of NativeAgentResponse.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tcell_agent/rust/native_agent_response.rb', line 6

def initialize(native_method_name, response, response_len)
  @response = {}
  @errors = []

  if response_len < 0
    @errors.push(
      "Error response from `#{native_method_name}` in native library method: #{response_len}"
    )
    return
  end

  begin
    @response = JSON.parse(response.get_string(0, response_len))
    if @response['error']
      @errors.push(
        "#{native_method_name} returned an error: #{@response['error']}"
      )
      @response = {}
    end
    if @response['errors']
      @response['errors'].each do |error|
        @errors.push(
          "#{native_method_name} returned an error: #{error}"
        )
        @response = {}
      end
    end
  rescue JSON::ParserError
    @errors.push(
      "Could not parse json response from `#{native_method_name}` in native library."
    )
    @response = {}
  end
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/tcell_agent/rust/native_agent_response.rb', line 4

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/tcell_agent/rust/native_agent_response.rb', line 4

def response
  @response
end