sectorsync_core/snapshot.rs
1//! Snapshot metadata and station snapshot containers.
2
3use crate::entity::EntityRecord;
4use crate::ids::{InstanceId, OwnerEpoch, StationId, Tick};
5
6/// Version metadata associated with a snapshot.
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub struct SnapshotVersion {
9 /// Runtime version selected by the embedding application.
10 pub runtime_version: u32,
11 /// Entity/schema version selected by the embedding application.
12 pub schema_version: u32,
13 /// Ruleset version selected by the embedding application.
14 pub ruleset_version: u32,
15 /// Module version selected by the embedding application.
16 pub module_version: u32,
17}
18
19impl Default for SnapshotVersion {
20 fn default() -> Self {
21 Self {
22 runtime_version: 1,
23 schema_version: 1,
24 ruleset_version: 1,
25 module_version: 1,
26 }
27 }
28}
29
30/// Snapshot metadata for a single station.
31#[derive(Clone, Debug, PartialEq, Eq)]
32pub struct SnapshotMeta {
33 /// World instance id.
34 pub instance_id: InstanceId,
35 /// Station id.
36 pub station_id: StationId,
37 /// Tick captured by the snapshot.
38 pub tick: Tick,
39 /// Entity count captured by the snapshot.
40 pub entity_count: usize,
41 /// Current station owner epoch.
42 pub owner_epoch: OwnerEpoch,
43 /// Version metadata.
44 pub version: SnapshotVersion,
45}
46
47/// In-memory station snapshot.
48#[derive(Clone, Debug, PartialEq)]
49pub struct StationSnapshot {
50 /// Snapshot metadata.
51 pub meta: SnapshotMeta,
52 /// Entity records captured by the snapshot.
53 pub entities: Vec<EntityRecord>,
54}
55
56/// Hook interface for runtime version upgrades around a full barrier.
57pub trait RuntimeUpgradeHook {
58 /// Called before state migration while the runtime is frozen.
59 fn pre_upgrade(&mut self, _meta: &SnapshotMeta) {}
60
61 /// Called to migrate a station snapshot while frozen.
62 fn migrate_state(&mut self, snapshot: StationSnapshot) -> StationSnapshot {
63 snapshot
64 }
65
66 /// Called after migration and before resume.
67 fn post_upgrade(&mut self, _meta: &SnapshotMeta) {}
68}