Class: Kobako::Transport::Yield
- Inherits:
-
Object
- Object
- Kobako::Transport::Yield
- Defined in:
- lib/kobako/transport/yield.rb,
sig/kobako/transport/yield.rbs
Overview
Value object for a single YieldResponse envelope (docs/wire-codec.md YieldResponse Envelope).
The wire form is a one-byte tag followed by an msgpack payload.
The three live tags are 0x01 (ok), 0x02 (break), and 0x04
(error); 0x03 is reserved and rejected by both sides.
value carries whatever the wire payload decoded to — a plain
Ruby value for the ok / break tags, and a {"class",
"message", "backtrace"} Hash for the error tag. No further
shape constraint is enforced here; the host-side dispatcher
decides how to translate each variant into Ruby control flow.
Lives alongside the other envelope value objects (+Request+,
Response) since it is the guest-to-host shape used
mid-dispatch-frame to answer a __kobako_yield_to_block re-entry.
Instance Attribute Summary collapse
-
#tag ⇒ Integer
readonly
Returns the value of attribute tag.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.decode(bytes) ⇒ Yield
Decode
bytesinto a Yield.
Instance Method Summary collapse
- #== ⇒ Boolean
- #break? ⇒ Boolean
-
#encode ⇒ String
Encode this Yield to YieldResponse bytes: one tag byte followed by an msgpack-encoded
value. - #error? ⇒ Boolean
- #hash ⇒ Integer
-
#initialize(tag:, value:) ⇒ Yield
constructor
A new instance of Yield.
- #ok? ⇒ Boolean
- #with ⇒ Yield
Constructor Details
#initialize(tag:, value:) ⇒ Yield
Returns a new instance of Yield.
42 43 44 45 46 47 48 49 |
# File 'lib/kobako/transport/yield.rb', line 42 def initialize(tag:, value:) unless Kobako::Transport::LIVE_TAGS.include?(tag) raise ArgumentError, "Yield tag must be one of #{Kobako::Transport::LIVE_TAGS.inspect}, got #{tag.inspect}" end super end |
Instance Attribute Details
#tag ⇒ Integer (readonly)
Returns the value of attribute tag.
10 11 12 |
# File 'sig/kobako/transport/yield.rbs', line 10 def tag @tag end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
11 12 13 |
# File 'sig/kobako/transport/yield.rbs', line 11 def value @value end |
Class Method Details
.decode(bytes) ⇒ Yield
Decode bytes into a Kobako::Transport::Yield. Rejects empty input, the reserved
tag 0x03, and any tag outside LIVE_TAGS by raising
Kobako::Codec::InvalidType — these are wire violations per the
SPEC's YieldResponse envelope contract.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kobako/transport/yield.rb', line 65 def self.decode(bytes) bytes = bytes.b raise Codec::InvalidType, "YieldResponse must carry at least one byte" if bytes.empty? tag = bytes.getbyte(0) # : Integer body = bytes.byteslice(1, bytes.bytesize - 1) # : String reject_dead_tag!(tag) new(tag: tag, value: Codec::Decoder.decode(body)) end |
Instance Method Details
#== ⇒ Boolean
29 |
# File 'sig/kobako/transport/yield.rbs', line 29
def ==: (untyped other) -> bool
|
#break? ⇒ Boolean
52 |
# File 'lib/kobako/transport/yield.rb', line 52 def break? = tag == Kobako::Transport::TAG_BREAK |
#encode ⇒ String
Encode this Yield to YieldResponse bytes: one tag byte followed
by an msgpack-encoded value.
57 58 59 |
# File 'lib/kobako/transport/yield.rb', line 57 def encode [tag].pack("C") + Codec::Encoder.encode(value) end |
#error? ⇒ Boolean
53 |
# File 'lib/kobako/transport/yield.rb', line 53 def error? = tag == Kobako::Transport::TAG_ERROR |
#hash ⇒ Integer
31 |
# File 'sig/kobako/transport/yield.rbs', line 31
def hash: () -> Integer
|
#ok? ⇒ Boolean
51 |
# File 'lib/kobako/transport/yield.rb', line 51 def ok? = tag == Kobako::Transport::TAG_OK |
#with ⇒ Yield
19 |
# File 'sig/kobako/transport/yield.rbs', line 19
def with: (?tag: Integer, ?value: untyped) -> Yield
|