class Movie::Remote::MessageRegistry

Overview

MessageRegistry manages serialization and deserialization of message types. Message types must be registered before they can be sent over the wire.

Defined in:

movie/remote/message_registry.cr

Constant Summary

PAYLOAD_DECODER = ->(tag : String, pull : JSON::PullParser) do (MessageRegistry.decode_payload(tag, pull)).as(JsonPayload) end

Class Method Summary

Macro Summary

Class Method Detail

def self.clear #

Clears all registrations (useful for testing).


[View source]
def self.decode_payload(tag : String, pull : JSON::PullParser) : JsonPayload #

Consumes a registered payload directly from the envelope pull parser. Unknown tags retain the raw/lazy compatibility path.


[View source]
def self.deserialize(tag : String, payload : JsonPayload) : MessageWrapper #

Deserializes a message from its tag and JSON payload. Raises if the tag is not registered.


[View source]
def self.deserialize(tag : String, payload : JSON::Any) : MessageWrapper #

[View source]
def self.payload_decoder : JsonPayloadDecoder #

Returns the reusable callback injected into connection-owned frame decoders. Public/stateless FrameCodec decoding does not use the registry.


[View source]
def self.prepare(message : JSON::Serializable) : Tuple(String, JsonPayload) #

[View source]
def self.prepare(message : T) : Tuple(String, JsonPayload) forall T #

Prepares a message for direct wire serialization without materializing an intermediate String or JSON DOM.


[View source]
def self.register_type(tag : String, type_name : String, deserializer : MessageDeserializer) #

Internal method to register type handlers.


[View source]
def self.registered?(tag : String) : Bool #

Checks if a tag is registered.


[View source]
def self.registered_tags : Array(String) #

Returns all registered tags.


[View source]
def self.serialize(message : JSON::Serializable) : Tuple(String, JSON::Any) #

[View source]
def self.serialize(message : T) : Tuple(String, JSON::Any) forall T #

Compatibility API for callers that explicitly require a JSON DOM. Remoting hot paths use .prepare and never materialize this value.


[View source]
def self.tag_for(type_name : String) : String #

Returns the tag for a type, or the type name if not registered.


[View source]

Macro Detail

macro register(type, tag = nil) #

Registers a message type with optional custom tag. The type must include JSON::Serializable.

Example: MessageRegistry.register(MyMessage) MessageRegistry.register(MyMessage, "custom-tag")


[View source]