Skip to main content

harmos_domain/operations/storage/
read_file.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17
18// Third Party Imports
19
20// Local Imports
21use super::IO_POLICY;
22use crate::MemorySize;
23use crate::model::storage::codec::{Nested, product};
24use crate::model::storage::{ByteRange, FileBatch, FileCompletion, FileReference};
25use crate::operations::{ReplaySafety, Visibility};
26
27/* === Constants === */
28
29/* === Macros === */
30
31product!(ReadFile {
32    file: Nested<FileReference> => 1,
33    range: Nested<ByteRange> => 2,
34});
35
36crate::declare!(ReadFile {
37    id: "storage.read_file",
38    version: 1,
39    policy: IO_POLICY,
40    response: FileCompletion,
41    output: FileBatch,
42    visibility: Visibility::Shared,
43    replay: ReplaySafety::Idempotent,
44    grpc: ("harmos.storage.v1", "Storage", "ReadFile"),
45    grant: |request: &ReadFile| Some(crate::plugin::Grant::of("storage.read_file", request.file.metadata.id.as_str().to_owned(),)),
46});
47
48/* === Type Aliases === */
49
50/* === Structs === */
51
52// Read A Byte Range Of A Finished, Immutable File.
53#[derive(Clone, Debug, PartialEq, Eq)]
54pub struct ReadFile {
55    pub file: FileReference,
56    pub range: ByteRange,
57}
58
59/* === Enums === */
60
61/* === Traits === */
62
63/* === Implementations === */
64
65impl MemorySize for ReadFile {
66    fn memory_size(&self) -> usize {
67        std::mem::size_of::<Self>()
68            .saturating_add(self.file.memory_size().saturating_sub(std::mem::size_of_val(&self.file)))
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 === */