Skip to main content

harmos_domain/operations/storage/
capture_file.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10// CaptureFile Declaration.
11
12/* === Modules === */
13
14/* === Re-Exports === */
15
16/* === Imports === */
17
18// Standard Library Imports
19
20// Third Party Imports
21
22// Local Imports
23use super::IO_POLICY;
24use crate::MemorySize;
25use crate::model::storage::codec::{Code, Nested, product};
26use crate::model::storage::files::{ByteRange, CaptureConsistency, FileMetadata, FileReference, FileSource};
27use crate::operations::{ReplaySafety, Visibility};
28
29/* === Constants === */
30
31/* === Macros === */
32
33product!(CaptureFile {
34    source: Nested<FileSource> => 1,
35    range: Nested<ByteRange> => 2,
36    metadata: Nested<FileMetadata> => 3,
37    consistency: Code<CaptureConsistency> => 4,
38});
39
40crate::declare!(CaptureFile {
41    id: "storage.capture_file",
42    version: 1,
43    policy: IO_POLICY,
44    response: FileReference,
45    visibility: Visibility::Shared,
46    replay: ReplaySafety::Unknown,
47    grpc: ("harmos.storage.v1", "Storage", "CaptureFile"),
48    grant: |request: &CaptureFile| request.source.grant_scope().map(|scope| crate::plugin::Grant::of("storage.capture_file", scope)),
49});
50
51/* === Type Aliases === */
52
53/* === Structs === */
54
55#[derive(Clone, Debug, PartialEq, Eq)]
56pub struct CaptureFile {
57    pub source: FileSource,
58    pub range: ByteRange,
59    pub metadata: FileMetadata,
60    pub consistency: CaptureConsistency,
61}
62
63/* === Enums === */
64
65/* === Traits === */
66
67/* === Implementations === */
68
69impl MemorySize for CaptureFile {
70    fn memory_size(&self) -> usize {
71        std::mem::size_of::<Self>()
72            .saturating_add(self.source.memory_size().saturating_sub(std::mem::size_of_val(&self.source)))
73            .saturating_add(self.range.memory_size().saturating_sub(std::mem::size_of_val(&self.range)))
74            .saturating_add(self.metadata.memory_size().saturating_sub(std::mem::size_of_val(&self.metadata)))
75            .saturating_add(self.consistency.memory_size().saturating_sub(std::mem::size_of_val(&self.consistency)))
76    }
77}
78
79/* === Public Functions === */
80
81/* === Private Functions === */
82
83/* === Tests === */