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 snapshot;
26mod types;
27
28pub use baseline::{BaselineError, BaselineStore};
29pub use delta::{
30    apply_delta_snapshot, apply_delta_snapshot_from_packet, decode_delta_packet,
31    encode_delta_snapshot, encode_delta_snapshot_with_scratch, select_baseline_tick, DeltaDecoded,
32    DeltaUpdateComponent, DeltaUpdateEntity,
33};
34pub use error::{CodecError, CodecResult, LimitKind, MaskKind, MaskReason, ValueReason};
35pub use limits::CodecLimits;
36pub use scratch::CodecScratch;
37pub use snapshot::{
38    decode_full_snapshot, decode_full_snapshot_from_packet, encode_full_snapshot,
39    ComponentSnapshot, EntitySnapshot, FieldValue, Snapshot,
40};
41pub use types::{EntityId, SnapshotTick};
42pub use wire::Limits as WireLimits;
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn public_api_exports() {
50        // Verify all expected items are exported
51        let _ = SnapshotTick::new(0);
52        let _ = EntityId::new(0);
53        let _ = WireLimits::default();
54        let _ = CodecLimits::default();
55
56        // Error types
57        let _: CodecResult<()> = Ok(());
58    }
59
60    #[test]
61    fn snapshot_tick_usage() {
62        let tick = SnapshotTick::new(100);
63        assert_eq!(tick.raw(), 100);
64        assert!(!tick.is_zero());
65    }
66
67    #[test]
68    fn entity_id_usage() {
69        let id = EntityId::new(42);
70        assert_eq!(id.raw(), 42);
71    }
72
73    #[test]
74    fn limits_reexported() {
75        // Limits is re-exported from wire
76        let limits = WireLimits::default();
77        assert!(limits.max_packet_bytes > 0);
78    }
79}