pub enum StateEnvelope {
State {
for_player: Option<String>,
state: Value,
engine_ms: Option<u32>,
emit_ms: Option<u32>,
fingerprint: Option<String>,
},
StateDelta {
for_player: Option<String>,
base: String,
fingerprint: String,
patch: Value,
engine_ms: Option<u32>,
emit_ms: Option<u32>,
},
Display {
event: Value,
},
Prompt {
for_player: String,
prompt: Value,
engine_ms: Option<u32>,
emit_ms: Option<u32>,
},
Response {
from_player: String,
prompt_id: u32,
action: Value,
},
Directive {
from_player: String,
directive: Value,
},
EngineDirective {
for_player: String,
directive: Value,
},
Log {
from_player: String,
entry: GameLogEntryDto,
},
Snapshot {
from_player: String,
entry: Box<GameSnapshotEventDto>,
},
Fatal {
message: String,
},
Error {
for_player: String,
error: Value,
},
RoomRelay {
protocol: String,
version: u32,
message_id: String,
from_player: Option<String>,
target_player: Option<String>,
room_id: Option<String>,
payload: Value,
},
}Expand description
Typed envelope carried inside ClientMessage::BroadcastState.state /
ServerMessage::StateUpdate.state. One discriminator (kind) plus the
payload for that variant. Constructed and parsed in every layer that
touches the relay (engine, bot, host, web/Tauri UI) — anything that needs
to handcraft json!({"kind": "..."}) belongs here instead.
Variants§
State
Fields
engine_ms: Option<u32>Milliseconds the engine host spent between receiving the response that caused this state and sending it. Lets a receiver separate engine work from the hop to the engine host, which is otherwise impossible: only the relay stamps these envelopes, and comparing clocks across hosts is not something we want to rely on.
emit_ms: Option<u32>Milliseconds the engine host then spent building this envelope:
serialising the state, fingerprinting it, diffing it. Sampled after
engine_ms, so subtracting both from a relay-stamped round trip
leaves the hop alone. Otherwise that work reads as network, and
unlike the network it grows with the board. Always None here: the
value is stamped onto the serialised envelope by the sender, which
cannot know it until the serialising is done.
fingerprint: Option<String>Set only when the sender also emits StateEnvelope::StateDelta,
so a receiver can tell whether a later patch applies to what it
holds. Receivers never compute it: the sender is the only authority,
which keeps Rust and TypeScript from having to agree on a hash.
StateDelta
Patch turning the receiver’s previous state into the current one, as
produced by [crate::state_delta::diff]. base is the fingerprint of
the state it applies to; a receiver holding a different one must ask for
a full StateEnvelope::State rather than apply the patch.
Fields
emit_ms: Option<u32>See StateEnvelope::State::emit_ms. Stamped after the patch is
built, so it covers the diff that produced this envelope.
Display
Prompt
Engine asks a player for a decision. prompt is AgentPrompt for the
Rust engine; the Java bridge emits a different shape, so the payload is
kept as raw Value here and parsed by the receiver.
Response
Player answers a prompt. action is PlayerAction for Rust; raw value
Directive
EngineDirective
Log
Engine log entry broadcast to observers.
Snapshot
Engine snapshot broadcast to observers.
Fatal
Error
Engine rejects a response (stale prompt, wrong player, unknown action).
error is ProtocolError; recoverable unless the session is terminated.
RoomRelay
Out-of-band message tunneled through the relay (manual tabletop launch,
self-hosted-node control plane, heartbeats, …). The relay never
interprets the payload.
Implementations§
Source§impl StateEnvelope
impl StateEnvelope
pub fn for_agent_message(for_player: String, message: &AgentMessage) -> Self
Sourcepub fn for_agent_message_timed(
for_player: String,
message: &AgentMessage,
engine_ms: Option<u32>,
) -> Self
pub fn for_agent_message_timed( for_player: String, message: &AgentMessage, engine_ms: Option<u32>, ) -> Self
As Self::for_agent_message, carrying how long the engine host took
to produce this message.