room-protocol
Wire format types for the room multi-user chat system.
This crate defines the Message enum and constructor functions shared by all room components (broker, TUI, agent wrappers, future UIs). It contains no transport or IO logic — just types and serialization.
Installation
[]
= "2.0.0"
Message types
All messages use a flat, internally-tagged JSON format (#[serde(tag = "type")]):
| Type | Description | Key fields |
|---|---|---|
join |
User joined the room | user |
leave |
User left the room | user |
message |
Chat message | user, content |
reply |
Reply to a specific message | user, reply_to, content |
command |
Slash command | user, cmd, params |
system |
Broker system message | user, content |
direct_message |
Private message | user, to, content |
Every variant carries id (UUID), room, user, ts (UTC timestamp), and an optional seq (sequence number).
Usage
use ;
// Create a message
let msg = make_message;
// Serialize to JSON (NDJSON wire format)
let json = to_string.unwrap;
// Deserialize from JSON
let parsed: Message = from_str.unwrap;
// Parse raw client input (plain text or JSON envelope)
let msg = parse_client_line.unwrap;
Public API
Message— enum with variants for all wire format typesmake_join,make_leave,make_message,make_reply,make_command,make_system,make_dm— constructorsparse_client_line— parse raw client input (plain text becomes aMessage, JSON envelopes are deserialized)
Design constraints
- No
#[serde(flatten)]with#[serde(tag)]— this combination breaks deserialization in serde. Each variant carries its own fields. - No transport logic — this crate is types-only. Consumers handle their own IO.
- Stable wire format — changes to the
Messageenum are breaking changes that require coordination.
License
MIT