Module: Kobako::Wire::Codec::Decoder

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

Overview

Module-level entry point for the host side of the kobako wire (SPEC.md → Wire Codec → Type Mapping).

Translates msgpack gem exceptions into the kobako error taxonomy (Truncated, InvalidType, InvalidEncoding, UnsupportedType) so callers can pattern-match on the SPEC’s wire-violation categories without leaking the gem’s internal exception classes.

Public API is a single function — Decoder.decode. The decoder is stateless; the MessagePack::Unpacker instance is built per call because callers always decode exactly one wire value at a time.

Class Method Summary collapse

Class Method Details

.decode(bytes) ⇒ Object

Decode bytes into one Ruby value and validate transitively against the SPEC type mapping. Raises Truncated, InvalidType, or InvalidEncoding on wire violations.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kobako/wire/codec/decoder.rb', line 44

def self.decode(bytes)
  value = Factory.instance.load(bytes.b)
  validate_utf8!(value)
  value
rescue *INVALID_TYPE_ERRORS => e
  raise InvalidType, e.message
rescue *TRUNCATED_ERRORS => e
  raise Truncated, e.message
rescue ::EncodingError => e
  raise InvalidEncoding, e.message
end