Skip to main content

harmos_domain/model/storage/
arrow.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10// Arrow Data On The Wire: One IPC Message. The Runtime Decodes It With Its
11// Allocation Preflight; The Domain Holds Only The Bounded Bytes.
12
13/* === Modules === */
14
15/* === Re-Exports === */
16
17/* === Imports === */
18
19// Standard Library Imports
20use std::sync::Arc;
21// Third Party Imports
22
23// Local Imports
24use super::codec::{Bytes, product};
25use crate::MemorySize;
26
27/* === Constants === */
28
29/* === Macros === */
30
31product!(ArrowIpc { ipc: Bytes => 1 });
32
33/* === Type Aliases === */
34
35/* === Structs === */
36
37#[derive(Clone, Debug, PartialEq, Eq)]
38pub struct ArrowIpc {
39    ipc: Vec<u8>,
40}
41
42/* === Enums === */
43
44/* === Traits === */
45
46/* === Implementations === */
47
48impl ArrowIpc {
49    pub fn new(ipc: Vec<u8>) -> Self {
50        Self { ipc }
51    }
52
53    pub fn bytes(&self) -> &[u8] {
54        &self.ipc
55    }
56
57    pub fn into_bytes(self) -> Vec<u8> {
58        self.ipc
59    }
60}
61
62impl From<Arc<Vec<u8>>> for ArrowIpc {
63    fn from(ipc: Arc<Vec<u8>>) -> Self {
64        Self { ipc: Arc::unwrap_or_clone(ipc) }
65    }
66}
67
68impl MemorySize for ArrowIpc {
69    fn memory_size(&self) -> usize {
70        std::mem::size_of::<Self>().saturating_add(self.ipc.capacity())
71    }
72}
73
74/* === Public Functions === */
75
76/* === Private Functions === */
77
78/* === Tests === */