Module: Kobako::RPC
- Defined in:
- lib/kobako/rpc.rb,
lib/kobako/rpc/fault.rb,
lib/kobako/rpc/handle.rb,
lib/kobako/rpc/server.rb,
lib/kobako/rpc/envelope.rb,
lib/kobako/rpc/namespace.rb,
lib/kobako/rpc/dispatcher.rb,
lib/kobako/rpc/handle_table.rb
Overview
See lib/kobako/rpc.rb for the umbrella module doc; this file owns the Request / Response value objects and their encode/decode helpers.
Defined Under Namespace
Modules: Dispatcher Classes: Fault, Handle, HandleTable, Namespace, Request, Response, Server
Constant Summary collapse
- STATUS_OK =
Response variant marker for the success branch.
0- STATUS_ERROR =
Response variant marker for the fault branch.
1
Class Method Summary collapse
- .decode_request(bytes) ⇒ Object
- .decode_response(bytes) ⇒ Object
-
.encode_request(request) ⇒ Object
Encode a Request to msgpack bytes.
- .encode_response(response) ⇒ Object
Class Method Details
.decode_request(bytes) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kobako/rpc/envelope.rb', line 56 def self.decode_request(bytes) arr = Codec::Decoder.decode(bytes) unless arr.is_a?(Array) && arr.length == 4 raise Codec::InvalidType, "Request must be a 4-element array, got #{arr.inspect}" end target, method_name, args, kwargs = arr Codec::Utils.wire_boundary do Request.new(target: target, method: method_name, args: args, kwargs: kwargs) end end |
.decode_response(bytes) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/kobako/rpc/envelope.rb', line 108 def self.decode_response(bytes) arr = Codec::Decoder.decode(bytes) unless arr.is_a?(Array) && arr.length == 2 raise Codec::InvalidType, "Response must be a 2-element array, got #{arr.inspect}" end status, payload = arr Codec::Utils.wire_boundary { Response.new(status: status, payload: payload) } end |
.encode_request(request) ⇒ Object
Encode a Request to msgpack bytes. The Value Object’s own invariants are the contract; this method does not re-check the shape.
52 53 54 |
# File 'lib/kobako/rpc/envelope.rb', line 52 def self.encode_request(request) Codec::Encoder.encode([request.target, request.method_name, request.args, request.kwargs]) end |