Skip to main content

harmos_storage/writes/
decoded.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::DataBatch;
22use crate::arrow::ArrowBatch;
23use crate::{MemorySize, Result};
24
25/* === Constants === */
26
27/* === Macros === */
28
29/* === Type Aliases === */
30
31/* === Structs === */
32
33// A Write Batch Whose Arrow IPC Data Has Been Decoded For Admission.
34pub struct DecodedBatch {
35    pub destination: crate::Identifier,
36    pub schema: crate::storage::SchemaKey,
37    pub data: ArrowBatch,
38}
39
40/* === Enums === */
41
42/* === Traits === */
43
44/* === Implementations === */
45
46impl DecodedBatch {
47    pub fn of(batch: &DataBatch) -> Result<Self> {
48        Ok(Self { data: ArrowBatch::from_ipc(batch.data.bytes())?, destination: batch.destination.clone(), schema: batch.schema.clone() })
49    }
50}
51
52impl MemorySize for DecodedBatch {
53    fn memory_size(&self) -> usize {
54        std::mem::size_of::<Self>()
55            .saturating_add(self.destination.memory_size().saturating_sub(std::mem::size_of_val(&self.destination)))
56            .saturating_add(self.schema.memory_size().saturating_sub(std::mem::size_of_val(&self.schema)))
57            .saturating_add(self.data.memory_size().saturating_sub(std::mem::size_of_val(&self.data)))
58    }
59}
60
61/* === Public Functions === */
62
63/* === Private Functions === */
64
65/* === Tests === */