Class: OpenC3::JsonRpc

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/openc3/io/json_rpc.rb

Overview

Base class for all JSON Remote Procedure Calls. Provides basic comparison and Hash to JSON conversions.

Direct Known Subclasses

JsonRpcError, JsonRpcRequest, JsonRpcResponse

Instance Method Summary collapse

Constructor Details

#initializeJsonRpc

Returns a new instance of JsonRpc.



191
192
193
# File 'lib/openc3/io/json_rpc.rb', line 191

def initialize
  @hash = {}
end

Instance Method Details

#<=>(other) ⇒ Object

Parameters:

  • other (JsonRpc)

    Another JsonRpc to compare hash values with



196
197
198
199
200
# File 'lib/openc3/io/json_rpc.rb', line 196

def <=>(other)
  return nil unless other.respond_to?(:as_json)

  self.as_json(:allow_nan => true) <=> other.as_json(:allow_nan => true)
end

#as_json(*a) ⇒ Hash

Returns Hash representing the object.

Parameters:

  • a (Array)

    Array of options

Returns:

  • (Hash)

    Hash representing the object



204
205
206
# File 'lib/openc3/io/json_rpc.rb', line 204

def as_json(*a)
  @hash.as_json(*a)
end

#to_json(*a) ⇒ String

Returns The JSON encoded String.

Parameters:

  • a (Array)

    Array of options

Returns:

  • (String)

    The JSON encoded String



210
211
212
# File 'lib/openc3/io/json_rpc.rb', line 210

def to_json(*a)
  as_json(*a).to_json(*a)
end