Class: AgentClientProtocol::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_client_protocol/decoder.rb

Defined Under Namespace

Classes: DecodedPayload

Constant Summary collapse

VALID_SIDES =
%i[agent client protocol].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(side:, unstable: false, validate_schema: true) ⇒ Decoder

Returns a new instance of Decoder.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/agent_client_protocol/decoder.rb', line 42

def initialize(side:, unstable: false, validate_schema: true)
  normalized_side = side.to_sym
  unless VALID_SIDES.include?(normalized_side)
    raise ArgumentError, "side must be one of: #{VALID_SIDES.join(', ')}"
  end

  @side = normalized_side
  @unstable = unstable
  @validate_schema = validate_schema
  @catalog = SchemaRegistry.method_catalog(unstable: unstable).fetch(normalized_side, {})
end

Instance Attribute Details

#sideObject (readonly)

Returns the value of attribute side.



40
41
42
# File 'lib/agent_client_protocol/decoder.rb', line 40

def side
  @side
end

#unstableObject (readonly)

Returns the value of attribute unstable.



40
41
42
# File 'lib/agent_client_protocol/decoder.rb', line 40

def unstable
  @unstable
end

#validate_schemaObject (readonly)

Returns the value of attribute validate_schema.



40
41
42
# File 'lib/agent_client_protocol/decoder.rb', line 40

def validate_schema
  @validate_schema
end

Instance Method Details

#decode_notification(method:, params:) ⇒ Object



58
59
60
# File 'lib/agent_client_protocol/decoder.rb', line 58

def decode_notification(method:, params:)
  decode(kind: :notification, method: method, payload: params, require_payload: true)
end

#decode_request(method:, params:) ⇒ Object



54
55
56
# File 'lib/agent_client_protocol/decoder.rb', line 54

def decode_request(method:, params:)
  decode(kind: :request, method: method, payload: params, require_payload: true)
end

#decode_response(method:, result:) ⇒ Object



62
63
64
# File 'lib/agent_client_protocol/decoder.rb', line 62

def decode_response(method:, result:)
  decode(kind: :response, method: method, payload: result, require_payload: false)
end