Class: Kobako::Transport::Request
- Inherits:
-
Object
- Object
- Kobako::Transport::Request
- Defined in:
- lib/kobako/transport/request.rb
Overview
Value object for a single guest-initiated Transport Request (docs/wire-codec.md Envelope Encoding → Request).
5-element msgpack array: [target, method_name, args, kwargs, block_given]. target is either a String (+“Namespace::Member”+) or a Handle. SPEC pins kwargs map keys to ext 0x00 Symbol; enforced at construction so the Value Object is the single source of truth. block_given is a Boolean signalling whether the guest call site supplied a block (B-23); the block body itself never crosses the wire.
Built on the class X < Data.define(…) subclass form so the class body is fully Steep-visible; see lib/kobako/outcome/panic.rb for the rationale.
Class Method Summary collapse
-
.decode(bytes) ⇒ Object
Decode
bytesinto a Request.
Instance Method Summary collapse
-
#encode ⇒ Object
Encode this Request to msgpack bytes.
-
#initialize(target:, method_name:, args: [], kwargs: {}, block_given: false) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(target:, method_name:, args: [], kwargs: {}, block_given: false) ⇒ Request
Returns a new instance of Request.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kobako/transport/request.rb', line 33 def initialize(target:, method_name:, args: [], kwargs: {}, block_given: false) unless target.is_a?(String) || target.is_a?(Kobako::Handle) raise ArgumentError, "Request target must be String or Kobako::Handle, got #{target.class}" end raise ArgumentError, "Request method_name must be String" unless method_name.is_a?(String) raise ArgumentError, "Request args must be Array" unless args.is_a?(Array) unless block_given.is_a?(TrueClass) || block_given.is_a?(FalseClass) raise ArgumentError, "Request block_given must be Boolean, got #{block_given.class}" end validate_kwargs!(kwargs) super end |
Class Method Details
.decode(bytes) ⇒ Object
Decode bytes into a Kobako::Transport::Request. Raises Codec::InvalidType when the envelope is not the expected 5-element msgpack array, or when the Value Object’s construction invariants reject the decoded fields.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/kobako/transport/request.rb', line 56 def self.decode(bytes) Codec::Decoder.decode(bytes) do |arr| unless arr.is_a?(Array) && arr.length == 5 raise Codec::InvalidType, "Request envelope is malformed (expected a 5-element array)" end target, method_name, args, kwargs, block_given = arr new(target: target, method_name: method_name, args: args, kwargs: kwargs, block_given: block_given) end end |