class

Movie::Remote::MessageRegistry

Inherits Reference < Object

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

Class methods

clear

Clears all registrations (useful for testing).

Source
deserialize(tag : String, json : JSON::Any) : MessageWrapper

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

Source
register_type(tag : String, type_name : String, deserializer : MessageDeserializer)

Internal method to register type handlers.

Source
registered?(tag : String) : Bool

Checks if a tag is registered.

Source
registered_tags

Returns all registered tags.

Source
serialize(message : T) : Tuple(String, JSON::Any) forall T

Serializes a message, returning {tag, json_payload}. The type must include JSON::Serializable.

Source
tag_for(type_name : String) : String

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

Source

Macros

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

Source