vortex_file/v2/footer/
file_layout.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::sync::Arc;

use vortex_flatbuffers::{footer2 as fb, FlatBufferRoot, WriteFlatBuffer};
use vortex_layout::LayoutData;

use crate::v2::footer::segment::Segment;

/// Captures the layout information of a Vortex file.
#[derive(Clone)]
pub(crate) struct FileLayout {
    pub(crate) root_layout: LayoutData,
    pub(crate) segments: Arc<[Segment]>,
}

impl FlatBufferRoot for FileLayout {}

impl WriteFlatBuffer for FileLayout {
    type Target<'a> = fb::FileLayout<'a>;

    fn write_flatbuffer<'fb>(
        &self,
        fbb: &mut flatbuffers::FlatBufferBuilder<'fb>,
    ) -> flatbuffers::WIPOffset<Self::Target<'fb>> {
        let root_layout = self.root_layout.write_flatbuffer(fbb);

        let segments = self
            .segments
            .iter()
            .map(|segment| segment.write_flatbuffer(fbb))
            .collect::<Vec<_>>();
        let segments = fbb.create_vector(&segments);

        fb::FileLayout::create(
            fbb,
            &fb::FileLayoutArgs {
                root_layout: Some(root_layout),
                segments: Some(segments),
            },
        )
    }
}