Module: Kobako::Wire::Codec::Encoder

Defined in:
lib/kobako/wire/codec/encoder.rb

Overview

Module-level entry point for the host side of the kobako wire (SPEC.md → Wire Codec → 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 Factory via Factory.instance.

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 (see Envelope.encode_outcome for the canonical example).

Class Method Summary collapse

Class Method Details

.encode(value) ⇒ Object

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).



33
34
35
36
37
# File 'lib/kobako/wire/codec/encoder.rb', line 33

def self.encode(value)
  Factory.instance.dump(value)
rescue ::RangeError, ::NoMethodError => e
  raise UnsupportedType, e.message
end