Skip to main content

harmos_domain/operations/storage/
append_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::POLICY;
22use crate::MemorySize;
23use crate::model::storage::codec::{Bytes, Nested, Unsigned, product};
24use crate::model::storage::{FileProducer, FileSession, MutationId};
25use crate::operations::{ReplaySafety, Visibility};
26
27/* === Constants === */
28
29/* === Macros === */
30
31product!(AppendFile {
32    mutation: Nested<MutationId> => 1,
33    session: Nested<FileSession> => 2,
34    offset: Unsigned => 3,
35    bytes: Bytes => 4,
36});
37
38crate::declare!(AppendFile {
39    id: "storage.append_file",
40    version: 1,
41    policy: POLICY,
42    response: FileProducer,
43    visibility: Visibility::Host,
44    replay: ReplaySafety::Idempotent,
45});
46
47/* === Type Aliases === */
48
49/* === Structs === */
50
51// Append Bytes At An Offset Of A Producing File Session.
52#[derive(Clone, Debug, PartialEq, Eq)]
53pub struct AppendFile {
54    pub mutation: MutationId,
55    pub session: FileSession,
56    pub offset: u64,
57    pub bytes: Vec<u8>,
58}
59
60/* === Enums === */
61
62/* === Traits === */
63
64/* === Implementations === */
65
66impl MemorySize for AppendFile {
67    fn memory_size(&self) -> usize {
68        std::mem::size_of::<Self>()
69            .saturating_add(self.mutation.memory_size().saturating_sub(std::mem::size_of_val(&self.mutation)))
70            .saturating_add(self.session.memory_size().saturating_sub(std::mem::size_of_val(&self.session)))
71            .saturating_add(self.offset.memory_size().saturating_sub(std::mem::size_of_val(&self.offset)))
72            .saturating_add(self.bytes.memory_size().saturating_sub(std::mem::size_of_val(&self.bytes)))
73    }
74}
75
76/* === Public Functions === */
77
78/* === Private Functions === */
79
80/* === Tests === */