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