Module: Kobako::Codec::Encoder
- Defined in:
- lib/kobako/codec/encoder.rb,
sig/kobako/codec/encoder.rbs
Overview
Module-level entry point for the host side of the kobako wire (docs/wire-codec.md § Type Mapping).
The codec backbone is the official msgpack gem: integers, floats,
strings, arrays, and maps go through the gem's narrowest-encoding
logic; the three kobako-specific ext types (0x00 Symbol, 0x01
Capability Handle, 0x02 Exception envelope) are registered on
the cached Factory singleton.
Public API is a single function — Encoder.encode. The codec is stateless; there is no buffer accumulator and no streaming write API. Callers that need to concatenate multiple encodings build the bytes themselves.
Class Method Summary collapse
-
.encode(value) ⇒ String
Encode
valueto wire bytes (binary-encoded String).
Class Method Details
.encode(value) ⇒ String
Encode value to wire bytes (binary-encoded String).
Wire violations surface as UnsupportedType: SPEC's 12-entry type
mapping is a closed set, and anything outside it is rejected by
the msgpack gem itself (arbitrary objects raise NoMethodError
from missing to_msgpack, integers outside i64..u64 raise
RangeError). The NoMethodError catch is deliberately broad:
MessagePack signals "no wire representation" only through that error,
so there is no narrower discriminator — a packer-internal
NoMethodError is likewise reported as UnsupportedType rather than
propagating.
34 35 36 37 38 |
# File 'lib/kobako/codec/encoder.rb', line 34 def self.encode(value) Factory.dump(value) rescue ::RangeError, ::NoMethodError => e raise UnsupportedType, e. end |