harmos_domain/operations/storage/
hash_file.rs1use 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
29product!(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#[derive(Clone, Debug, PartialEq, Eq)]
54pub struct HashFile {
55 pub source: FileSource,
56 pub range: ByteRange,
57}
58
59impl 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