Skip to main content

harmos_domain/operations/storage/
hash_file.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10// HashFile 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::{Nested, product};
26use crate::model::storage::files::{ByteRange, FileHash, FileSource};
27use crate::operations::{ReplaySafety, Visibility};
28
29/* === Constants === */
30
31/* === Macros === */
32
33product!(HashFile {
34    source: Nested<FileSource> => 1,
35    range: Nested<ByteRange> => 2,
36});
37
38crate::declare!(HashFile {
39    id: "storage.hash_file",
40    version: 1,
41    policy: IO_POLICY,
42    response: FileHash,
43    visibility: Visibility::Shared,
44    replay: ReplaySafety::Idempotent,
45    grpc: ("harmos.storage.v1", "Storage", "HashFile"),
46    grant: |request: &HashFile| request.source.grant_scope().map(|scope| crate::plugin::Grant::of("storage.hash_file", scope)),
47});
48
49/* === Type Aliases === */
50
51/* === Structs === */
52
53#[derive(Clone, Debug, PartialEq, Eq)]
54pub struct HashFile {
55    pub source: FileSource,
56    pub range: ByteRange,
57}
58
59/* === Enums === */
60
61/* === Traits === */
62
63/* === Implementations === */
64
65impl MemorySize for HashFile {
66    fn memory_size(&self) -> usize {
67        std::mem::size_of::<Self>()
68            .saturating_add(self.source.memory_size().saturating_sub(std::mem::size_of_val(&self.source)))
69            .saturating_add(self.range.memory_size().saturating_sub(std::mem::size_of_val(&self.range)))
70    }
71}
72
73/* === Public Functions === */
74
75/* === Private Functions === */
76
77/* === Tests === */