vortex_file/v2/footer/
postscript.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
42
43
44
45
46
47
48
49
50
51
52
use flatbuffers::Follow;
use vortex_error::{vortex_err, VortexError};
use vortex_flatbuffers::{footer2 as fb, FlatBufferRoot, ReadFlatBuffer, WriteFlatBuffer};

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

/// Captures the layout information of a Vortex file.
pub(crate) struct Postscript {
    pub(crate) dtype: Segment,
    pub(crate) file_layout: Segment,
}

impl FlatBufferRoot for Postscript {}

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

    fn write_flatbuffer<'fb>(
        &self,
        fbb: &mut flatbuffers::FlatBufferBuilder<'fb>,
    ) -> flatbuffers::WIPOffset<Self::Target<'fb>> {
        let dtype = self.dtype.write_flatbuffer(fbb);
        let file_layout = self.file_layout.write_flatbuffer(fbb);
        fb::Postscript::create(
            fbb,
            &fb::PostscriptArgs {
                dtype: Some(dtype),
                file_layout: Some(file_layout),
            },
        )
    }
}

impl ReadFlatBuffer for Postscript {
    type Source<'a> = fb::Postscript<'a>;
    type Error = VortexError;

    fn read_flatbuffer<'buf>(
        fb: &<Self::Source<'buf> as Follow<'buf>>::Inner,
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            dtype: Segment::read_flatbuffer(
                &fb.dtype()
                    .ok_or_else(|| vortex_err!("Postscript missing dtype segment"))?,
            )?,
            file_layout: Segment::read_flatbuffer(
                &fb.file_layout()
                    .ok_or_else(|| vortex_err!("Postscript missing file_layout segment"))?,
            )?,
        })
    }
}