dispnet_shared/
lib.rs

1use std::time::{SystemTime, UNIX_EPOCH};
2
3/// The meta data package describes all details to store and retrive content.
4#[derive(Debug)]
5pub struct MetaPackage {
6    /// Identifier for the metadata package.
7    pub meta_package_id: String,
8    /// Creation timestamp (duration since Unix Epoch as seconds).
9    pub created: u64,
10    /// Total size of the content.
11    pub size: u64,
12    /// Content packages.
13    pub content: Vec<Package>,
14}
15
16/// A package contains a part of content.
17#[derive(Debug)]
18pub struct Package {
19    /// Identifier for the package.
20    pub package_id: String,
21    /// Index of the package which is needed for the recreation.
22    pub index: u64,
23    /// Checksum which is based on the normaized package size.
24    pub checksum: String,
25    /// Real size of the content bytes in the package (uncompressed).
26    pub size: u64,
27    /// Package bytes.
28    pub normalized_size: u64,
29    /// Name of the compression algorithm used if any.
30    pub compression_algorithm: String,
31}
32
33impl MetaPackage {
34    pub fn new(id: String, size: u64) -> Self {
35        Self {
36            meta_package_id: id,
37            created: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
38            size,
39            content: vec![],
40        }
41    }
42}