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_from_changes, 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_from_updates,
36    encode_delta_snapshot_with_scratch, select_baseline_tick, DeltaDecoded, DeltaUpdateComponent,
37    DeltaUpdateEntity, SessionEncoder,
38};
39pub use error::{CodecError, CodecResult, LimitKind, MaskKind, MaskReason, ValueReason};
40pub use limits::CodecLimits;
41pub use scratch::CodecScratch;
42pub use session::{
43    decode_session_init_packet, decode_session_packet, encode_session_init_packet,
44    CompactHeaderMode, SessionState,
45};
46pub use snapshot::{
47    decode_full_snapshot, decode_full_snapshot_from_packet, encode_full_snapshot,
48    ComponentSnapshot, EntitySnapshot, FieldValue, Snapshot,
49};
50pub use types::{EntityId, SnapshotTick};
51pub use wire::Limits as WireLimits;
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn public_api_exports() {
59        // Verify all expected items are exported
60        let _ = SnapshotTick::new(0);
61        let _ = EntityId::new(0);
62        let _ = WireLimits::default();
63        let _ = CodecLimits::default();
64
65        // Error types
66        let _: CodecResult<()> = Ok(());
67    }
68
69    #[test]
70    fn snapshot_tick_usage() {
71        let tick = SnapshotTick::new(100);
72        assert_eq!(tick.raw(), 100);
73        assert!(!tick.is_zero());
74    }
75
76    #[test]
77    fn entity_id_usage() {
78        let id = EntityId::new(42);
79        assert_eq!(id.raw(), 42);
80    }
81
82    #[test]
83    fn limits_reexported() {
84        // Limits is re-exported from wire
85        let limits = WireLimits::default();
86        assert!(limits.max_packet_bytes > 0);
87    }
88}