class
Movie::Remote::MessageRegistry
- Movie::Remote::MessageRegistry
- Reference
- Object
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.crConstant Summary
-
PAYLOAD_DECODER =
->(tag : String, pull : JSON::PullParser) do (MessageRegistry.decode_payload(tag, pull)).as(JsonPayload) end
Class Method Summary
-
.clear
Clears all registrations (useful for testing).
-
.decode_payload(tag : String, pull : JSON::PullParser) : JsonPayload
Consumes a registered payload directly from the envelope pull parser.
-
.deserialize(tag : String, payload : JsonPayload) : MessageWrapper
Deserializes a message from its tag and JSON payload.
- .deserialize(tag : String, payload : JSON::Any) : MessageWrapper
-
.payload_decoder : JsonPayloadDecoder
Returns the reusable callback injected into connection-owned frame decoders.
- .prepare(message : JSON::Serializable) : Tuple(String, JsonPayload)
-
.prepare(message : T) : Tuple(String, JsonPayload) forall T
Prepares a message for direct wire serialization without materializing an intermediate String or JSON DOM.
-
.register_type(tag : String, type_name : String, deserializer : MessageDeserializer)
Internal method to register type handlers.
-
.registered?(tag : String) : Bool
Checks if a tag is registered.
-
.registered_tags : Array(String)
Returns all registered tags.
- .serialize(message : JSON::Serializable) : Tuple(String, JSON::Any)
-
.serialize(message : T) : Tuple(String, JSON::Any) forall T
Compatibility API for callers that explicitly require a JSON DOM.
-
.tag_for(type_name : String) : String
Returns the tag for a type, or the type name if not registered.
Macro Summary
-
register(type, tag = nil)
Registers a message type with optional custom tag.
Class Method Detail
Consumes a registered payload directly from the envelope pull parser. Unknown tags retain the raw/lazy compatibility path.
Deserializes a message from its tag and JSON payload. Raises if the tag is not registered.
Returns the reusable callback injected into connection-owned frame decoders. Public/stateless FrameCodec decoding does not use the registry.
Prepares a message for direct wire serialization without materializing an intermediate String or JSON DOM.
Internal method to register type handlers.
Compatibility API for callers that explicitly require a JSON DOM. Remoting hot paths use .prepare and never materialize this value.
Returns the tag for a type, or the type name if not registered.
Macro Detail
Registers a message type with optional custom tag. The type must include JSON::Serializable.
Example: MessageRegistry.register(MyMessage) MessageRegistry.register(MyMessage, "custom-tag")