Skip to main content

codec/
lib.rs

1//! Snapshot and delta encoding/decoding for the sdec codec.
2//!
3//! This is the main codec crate that ties together bitstream, wire, and schema
4//! to provide full snapshot and delta encoding/decoding capabilities.
5//!
6//! # Features
7//!
8//! - Full snapshot encoding/decoding
9//! - Delta encoding relative to a baseline
10//! - Baseline history management
11//! - Entity create/update/destroy operations
12//! - Per-component and per-field change masks
13//!
14//! # Design Principles
15//!
16//! - **Correctness first** - All invariants are documented and tested.
17//! - **No steady-state allocations** - Uses caller-provided buffers.
18//! - **Deterministic** - Same inputs produce same outputs.
19
20mod baseline;
21mod delta;
22mod error;
23mod limits;
24mod scratch;
25mod session;
26mod snapshot;
27mod types;
28
29pub use baseline::{BaselineError, BaselineStore};
30pub use delta::{
31    apply_delta_snapshot, apply_delta_snapshot_from_packet, decode_delta_packet,
32    encode_delta_snapshot, encode_delta_snapshot_for_client,
33    encode_delta_snapshot_for_client_session,
34    encode_delta_snapshot_for_client_session_with_scratch,
35    encode_delta_snapshot_for_client_with_scratch, encode_delta_snapshot_with_scratch,
36    select_baseline_tick, DeltaDecoded, DeltaUpdateComponent, DeltaUpdateEntity,
37};
38pub use error::{CodecError, CodecResult, LimitKind, MaskKind, MaskReason, ValueReason};
39pub use limits::CodecLimits;
40pub use scratch::CodecScratch;
41pub use session::{
42    decode_session_init_packet, decode_session_packet, encode_session_init_packet,
43    CompactHeaderMode, SessionState,
44};
45pub use snapshot::{
46    decode_full_snapshot, decode_full_snapshot_from_packet, encode_full_snapshot,
47    ComponentSnapshot, EntitySnapshot, FieldValue, Snapshot,
48};
49pub use types::{EntityId, SnapshotTick};
50pub use wire::Limits as WireLimits;
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn public_api_exports() {
58        // Verify all expected items are exported
59        let _ = SnapshotTick::new(0);
60        let _ = EntityId::new(0);
61        let _ = WireLimits::default();
62        let _ = CodecLimits::default();
63
64        // Error types
65        let _: CodecResult<()> = Ok(());
66    }
67
68    #[test]
69    fn snapshot_tick_usage() {
70        let tick = SnapshotTick::new(100);
71        assert_eq!(tick.raw(), 100);
72        assert!(!tick.is_zero());
73    }
74
75    #[test]
76    fn entity_id_usage() {
77        let id = EntityId::new(42);
78        assert_eq!(id.raw(), 42);
79    }
80
81    #[test]
82    fn limits_reexported() {
83        // Limits is re-exported from wire
84        let limits = WireLimits::default();
85        assert!(limits.max_packet_bytes > 0);
86    }
87}