1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::entity_information::AuthChain;
use crate::{ContentId, EntityId, EntityType};
use serde::Deserialize;

#[derive(Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Snapshot {
    pub hash: ContentId,
    pub last_included_deployment_timestamp: u64, // TODO(fran): use chrono?
    pub entities: EntitySnapshots,
}

#[derive(Debug, Deserialize, Eq, PartialEq)]
pub struct EntitySnapshots {
    pub scene: EntityTypeSnapshot,
    pub profile: EntityTypeSnapshot,
    pub wearable: EntityTypeSnapshot,
    pub store: EntityTypeSnapshot,
}

#[derive(Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct EntityTypeSnapshot {
    pub hash: ContentId,
    pub last_included_deployment_timestamp: u64, // TODO(fran): use chrono?
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EntitySnapshot<T> {
    pub entity_id: EntityId,
    pub entity_type: EntityType,
    pub pointers: Vec<T>,
    pub local_timestamp: u64, // TODO(fran): use chrono?
    pub auth_chain: Vec<AuthChain>,
}

#[cfg(test)]
mod test {
    use crate::snapshot::Snapshot;
    use crate::ContentId;

    #[test]
    fn it_deserializes_from_json() {
        let json = include_str!("../fixtures/snapshot.json");
        let result: Snapshot = serde_json::from_str(json).unwrap();
        assert_eq!(
            result.hash,
            ContentId::new("bafybeifkmnczrywizlqhfirodivjenxyzu33k7wk4azxi7upklzfc5h3uy")
        );
    }
}