Class: Sourced::Message::JSONCodec

Inherits:
Codec
  • Object
show all
Defined in:
lib/sourced/message/json_codec.rb

Overview

Serializes messages to and from JSON-native structures — Hashes, Arrays, Strings, numbers, booleans, nil — ready for JSON.dump. The codec never writes bytes itself, so the transport decides how they are stored or framed.

codec = Sourced::Message::JSONCodec.default.compile!
codec.encode(message)  # => JSON-native Hash
codec.decode(attrs)    # => the message

Plumb::Codec::JSON is a process-wide global, so an encoder registered on it teaches every JSON codec in the process at once:

Plumb::Codec::JSON.encoder(MoneyEncoder)

Register at load time — a codec compiled before an encoder arrives never sees it.

See Codec for the machinery, and for the seams a subclass overrides.

Constant Summary

Constants inherited from Codec

Codec::DecodeError, Codec::EncodeError, Codec::UnregisteredTypeError

Instance Attribute Summary

Attributes inherited from Codec

#format

Class Method Summary collapse

Methods inherited from Codec

clear_pairs!, #compile!, #compiled?, #decode, default, #encode, #initialize, #inspect, pairs, #recompile!, #registered?, reset!

Constructor Details

This class inherits a constructor from Sourced::Message::Codec

Class Method Details

.default_formatObject



24
# File 'lib/sourced/message/json_codec.rb', line 24

def self.default_format = Plumb::Codec::JSON