firefly_types/
meta.rs

1use crate::Encode;
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
5pub struct Meta<'a> {
6    pub app_id: &'a str,
7    /// App name is shown in the launcher in the list of apps.
8    pub app_name: &'a str,
9    pub author_id: &'a str,
10    pub author_name: &'a str,
11    /// Launcher is the app that starts first when runtime is launched.
12    pub launcher: bool,
13    /// Let the app to use privileged and dangerous runtime API.
14    pub sudo: bool,
15    /// The ever-incrementing version number of the app build.
16    /// Used by netplay to ensure both devices running the same version.
17    pub version: u32,
18}
19
20impl<'a> Encode<'a> for Meta<'a> {}
21
22/// A struct with only a few safe fields from Meta.
23///
24/// It is used to serialize information about an app outside of the app dir.
25/// Since it is outside, it escapes the hash and signature checks
26/// and so it must not store any information that must be verified before use.
27#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
28#[allow(clippy::module_name_repetitions)]
29pub struct ShortMeta<'a> {
30    pub app_id: &'a str,
31    pub author_id: &'a str,
32}
33
34impl<'a> Encode<'a> for ShortMeta<'a> {}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_meta_roundtrip() {
42        let given = Meta {
43            app_id: "some-app-id",
44            app_name: "Some App Name",
45            author_id: "some-author-id",
46            author_name: "Some Author Name",
47            launcher: false,
48            sudo: false,
49            version: 12,
50        };
51        let mut buf = vec![0; given.size()];
52        let raw = given.encode_buf(&mut buf).unwrap();
53        let actual = Meta::decode(raw).unwrap();
54        assert_eq!(given, actual);
55    }
56
57    #[test]
58    fn test_short_meta_roundtrip() {
59        let given = ShortMeta {
60            app_id: "some-app-id",
61            author_id: "some-author-id",
62        };
63        let mut buf = vec![0; given.size()];
64        let raw = given.encode_buf(&mut buf).unwrap();
65        let actual = ShortMeta::decode(raw).unwrap();
66        assert_eq!(given, actual);
67    }
68}