Class: Kobako::Transport::Request
- Inherits:
-
Data
- Object
- Data
- Kobako::Transport::Request
- Defined in:
- lib/kobako/transport/request.rb,
sig/kobako/transport/request.rbs
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 (+""MyService::KV")
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; 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.
Instance Attribute Summary collapse
-
#args ⇒ Array[untyped]
readonly
Returns the value of attribute args.
-
#block_given ⇒ Boolean
readonly
Returns the value of attribute block_given.
-
#kwargs ⇒ Hash[Symbol, untyped]
readonly
Returns the value of attribute kwargs.
-
#method_name ⇒ String
readonly
Returns the value of attribute method_name.
-
#target ⇒ String, Kobako::Handle
readonly
Returns the value of attribute target.
Class Method Summary collapse
-
.decode(bytes) ⇒ Request
Decode
bytesinto a Request. - .new ⇒ Request
Instance Method Summary collapse
- #== ⇒ Boolean
-
#encode ⇒ String
Encode this Request to msgpack bytes.
- #hash ⇒ Integer
-
#initialize(target:, method_name:, args: [], kwargs: {}, block_given: false) ⇒ Request
constructor
A new instance of Request.
- #validate_kwargs!(kwargs) ⇒ void
- #with ⇒ Request
Constructor Details
#initialize(target:, method_name:, args: [], kwargs: {}, block_given: false) ⇒ Request
Returns a new instance of Request.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kobako/transport/request.rb', line 26 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 |
Instance Attribute Details
#args ⇒ Array[untyped] (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'sig/kobako/transport/request.rbs', line 6 def args @args end |
#block_given ⇒ Boolean (readonly)
Returns the value of attribute block_given.
8 9 10 |
# File 'sig/kobako/transport/request.rbs', line 8 def block_given @block_given end |
#kwargs ⇒ Hash[Symbol, untyped] (readonly)
Returns the value of attribute kwargs.
7 8 9 |
# File 'sig/kobako/transport/request.rbs', line 7 def kwargs @kwargs end |
#method_name ⇒ String (readonly)
Returns the value of attribute method_name.
5 6 7 |
# File 'sig/kobako/transport/request.rbs', line 5 def method_name @method_name end |
#target ⇒ String, Kobako::Handle (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'sig/kobako/transport/request.rbs', line 4 def target @target end |
Class Method Details
.decode(bytes) ⇒ Request
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.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kobako/transport/request.rb', line 49 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 |
.new ⇒ Request
10 |
# File 'sig/kobako/transport/request.rbs', line 10
def self.new: (target: String | Kobako::Handle, method_name: String, ?args: Array[untyped], ?kwargs: Hash[Symbol, untyped], ?block_given: bool) -> Request
|
Instance Method Details
#== ⇒ Boolean
20 |
# File 'sig/kobako/transport/request.rbs', line 20
def ==: (untyped other) -> bool
|
#encode ⇒ String
Encode this Request to msgpack bytes. The Value Object's own invariants are the contract; this method does not re-check the shape.
42 43 44 |
# File 'lib/kobako/transport/request.rb', line 42 def encode Codec::Encoder.encode([target, method_name, args, kwargs, block_given]) end |
#hash ⇒ Integer
22 |
# File 'sig/kobako/transport/request.rbs', line 22
def hash: () -> Integer
|
#validate_kwargs!(kwargs) ⇒ void
This method returns an undefined value.
62 63 64 65 66 67 68 |
# File 'lib/kobako/transport/request.rb', line 62 def validate_kwargs!(kwargs) raise ArgumentError, "Request kwargs must be Hash" unless kwargs.is_a?(Hash) kwargs.each_key do |k| raise ArgumentError, "Request kwargs keys must be Symbol, got #{k.class}" unless k.is_a?(Symbol) end end |
#with ⇒ Request
18 |
# File 'sig/kobako/transport/request.rbs', line 18
def with: (?target: String | Kobako::Handle, ?method_name: String, ?args: Array[untyped], ?kwargs: Hash[Symbol, untyped], ?block_given: bool) -> Request
|