pub struct SyncSession<T: DeltaPack + Clone> { /* private fields */ }Expand description
A stateful handle over a one-way state-sync session between two endpoints.
Each endpoint holds a SyncSession representing the current shared view
of the peer’s state. The sender calls encode to produce
bytes; the receiver calls decode to apply them. Both
sides converge on the same view as long as messages are delivered in order.
The type handles the “first call is full encode, subsequent are diffs”
distinction internally. It also ensures the sender’s view always matches
what the peer reconstructs — even when the user’s state has been mutated
or reordered in ways that would break a raw encode_diff call.
§Example
let mut session = SyncSession::<GameState>::new();
// Sender
let bytes = session.encode(&state);
// Receiver
let state = session.decode(&bytes);Implementations§
Source§impl<T: DeltaPack + Clone> SyncSession<T>
impl<T: DeltaPack + Clone> SyncSession<T>
Sourcepub fn encode(&mut self, state: &T) -> Vec<u8> ⓘ
pub fn encode(&mut self, state: &T) -> Vec<u8> ⓘ
Produce bytes to send to the peer. First call emits a full encode; subsequent calls emit a diff against the current view. Either way, the internal view is updated to match what the peer will hold after applying the returned bytes.