Class: Kobako::Capture
- Inherits:
-
Object
- Object
- Kobako::Capture
- Defined in:
- lib/kobako/capture.rb
Overview
Host-side captured prefix of guest stdout / stderr produced during a single Kobako::Sandbox invocation, paired with the truncation flag the WASI pipe sets when the guest wrote past the configured per-channel cap (docs/behavior.md B-04).
Immutable value object: the captured bytes and the truncation flag always travel together and the instance is frozen on construction. Construct via Capture.new(bytes:, truncated:) for the ext-provided binary bytes (the constructor handles the UTF-8 / ASCII-8BIT fallback) or reach Capture::EMPTY for the pre-invocation sentinel that Sandbox uses before any invocation has executed.
Constant Summary collapse
- EMPTY =
Pre-invocation sentinel (docs/behavior.md B-05). Empty UTF-8 bytes and truncated? == false; reused by every fresh
Sandboxand bySandboxbetween invocations to denote “no capture yet”. new(bytes: "", truncated: false)
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Instance Method Summary collapse
-
#initialize(bytes:, truncated:) ⇒ Capture
constructor
Build a Capture wrapping
bytes(the captured prefix as a String) andtruncated(whether the originating WASI pipe reported the cap was hit). -
#truncated? ⇒ Boolean
Returns
trueiff the underlying capture channel exceeded its configured cap during the originatingSandboxinvocation (docs/behavior.md B-04).
Constructor Details
#initialize(bytes:, truncated:) ⇒ Capture
Build a Capture wrapping bytes (the captured prefix as a String) and truncated (whether the originating WASI pipe reported the cap was hit). Coerces bytes to UTF-8 when they are valid UTF-8, otherwise falls back to ASCII-8BIT so invalid sequences remain inspectable without raising; bytes is duplicated, never mutated. Freezes the instance so callers cannot mutate the pair.
24 25 26 27 28 29 30 |
# File 'lib/kobako/capture.rb', line 24 def initialize(bytes:, truncated:) copy = bytes.dup.force_encoding(Encoding::UTF_8) copy.force_encoding(Encoding::ASCII_8BIT) unless copy.valid_encoding? @bytes = copy @truncated = truncated freeze end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
16 17 18 |
# File 'lib/kobako/capture.rb', line 16 def bytes @bytes end |
Instance Method Details
#truncated? ⇒ Boolean
Returns true iff the underlying capture channel exceeded its configured cap during the originating Sandbox invocation (docs/behavior.md B-04).
35 |
# File 'lib/kobako/capture.rb', line 35 def truncated? = @truncated |