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#run, paired with the truncation flag the WASI pipe sets when the guest wrote past the configured per-channel cap (SPEC.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.from_ext for ext-provided binary bytes (handles UTF-8 / ASCII-8BIT fallback) or reach Capture::EMPTY for the pre-run sentinel that Sandbox uses before any #run has executed.
Constant Summary collapse
- EMPTY =
Pre-run sentinel (SPEC.md B-05). Empty UTF-8 bytes and truncated? == false; reused by every fresh
Sandboxand by Sandbox#run between invocations to denote “no capture yet”. new(bytes: "", truncated: false)
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Class Method Summary collapse
-
.from_ext(bytes, truncated) ⇒ Object
Construct a Capture from ext-provided binary 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 originating Sandbox#run (SPEC.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). Freezes the instance so callers cannot mutate the pair.
20 21 22 23 24 |
# File 'lib/kobako/capture.rb', line 20 def initialize(bytes:, truncated:) @bytes = bytes @truncated = truncated freeze end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
15 16 17 |
# File 'lib/kobako/capture.rb', line 15 def bytes @bytes end |
Class Method Details
.from_ext(bytes, truncated) ⇒ Object
Construct a Capture from ext-provided binary bytes. Coerces bytes to UTF-8 when the bytes are valid UTF-8, otherwise falls back to ASCII-8BIT so invalid sequences remain inspectable without raising. bytes is not mutated.
35 36 37 38 39 |
# File 'lib/kobako/capture.rb', line 35 def self.from_ext(bytes, truncated) copy = bytes.dup.force_encoding(Encoding::UTF_8) copy.force_encoding(Encoding::ASCII_8BIT) unless copy.valid_encoding? new(bytes: copy, truncated: truncated) end |
Instance Method Details
#truncated? ⇒ Boolean
Returns true iff the underlying capture channel exceeded its configured cap during the originating Sandbox#run (SPEC.md B-04).
29 |
# File 'lib/kobako/capture.rb', line 29 def truncated? = @truncated |