Skip to main content

harmos_domain/operations/storage/
follow_production.rs

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