Module: Kobako::Codec::Utils
- Defined in:
- lib/kobako/codec/utils.rb,
sig/kobako/codec/utils.rbs
Overview
Byte-boundary helpers shared by the host-side encoder and decoder. Two concerns live here:
- UTF-8 assertion at the codec boundary
({docs/wire-codec.md}[link:../../../docs/wire-codec.md]
§ str/bin Encoding Rules and § Ext Types → ext 0x00). Used by
Decoder when walking +str+ family payloads and by ExtTypes
when validating the +ext 0x00+ Symbol payload.
- +ArgumentError+ translation at the codec boundary
(#with_boundary) so the public taxonomy stays
Kobako::Codec::Error.
Both helpers are pure — they only inspect inputs, never mutate them. The host↔guest Handle substitution walk lives in HandleWalk.
Class Method Summary collapse
-
.assert_utf8!(string, label) ⇒ Object
Raise InvalidEncoding unless +string+'s bytes are valid under its current encoding tag.
-
.with_boundary ⇒ Object
Run
blockat the codec boundary: a value object raisesArgumentErrorwhen an invariant is violated at construction, and this helper surfaces that as InvalidType so the public taxonomy stays Kobako::Codec::Error and never leaksArgumentErrorfrom the Ruby standard library.
Instance Method Summary collapse
Class Method Details
.assert_utf8!(string, label) ⇒ Object
Raise InvalidEncoding unless +string+'s bytes are valid under
its current encoding tag. label is the caller-supplied prefix
for the error message (e.g. "str payload", "Symbol payload").
27 28 29 30 31 |
# File 'lib/kobako/codec/utils.rb', line 27 def assert_utf8!(string, label) return if string.valid_encoding? raise InvalidEncoding, "#{label} is not valid UTF-8" end |
.with_boundary ⇒ Object
Run block at the codec boundary: a value object raises
ArgumentError when an invariant is violated at construction, and
this helper surfaces that as InvalidType so the public taxonomy
stays Kobako::Codec::Error and never leaks ArgumentError from
the Ruby standard library.
Reach for this only where a value object is constructed outside a
Decoder.decode block, whose rescue already performs the same
mapping (worked example: ExtTypes#unpack_handle building
Handle.restore from a raw fixext payload). Do not use it for
general-purpose validation outside the codec boundary —
host-layer ArgumentError values should propagate unchanged.
45 46 47 48 49 |
# File 'lib/kobako/codec/utils.rb', line 45 def with_boundary yield rescue ::ArgumentError => e raise InvalidType, e. end |
Instance Method Details
#self?.assert_utf8! ⇒ void
This method returns an undefined value.
4 |
# File 'sig/kobako/codec/utils.rbs', line 4
def self?.assert_utf8!: (String string, String label) -> void
|
#self?.with_boundary ⇒ void
This method returns an undefined value.
6 |
# File 'sig/kobako/codec/utils.rbs', line 6
def self?.with_boundary: [T] () { () -> T } -> T
|