From 5858299ff9da451a5ea1100731aba3b60b87da84 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Thu, 17 Oct 2024 15:31:24 +0100 Subject: [PATCH 01/10] Unify FlatLayout with other layouts and add metadata to their flatbuffer representation --- .../flatbuffers/vortex-serde/footer.fbs | 26 +- vortex-flatbuffers/src/generated/footer.rs | 535 +++++------------- vortex-serde/src/layouts/read/builder.rs | 59 +- vortex-serde/src/layouts/read/context.rs | 58 +- vortex-serde/src/layouts/read/footer.rs | 67 ++- vortex-serde/src/layouts/read/layouts.rs | 334 ----------- .../src/layouts/read/layouts/chunked.rs | 115 ++++ .../src/layouts/read/layouts/column.rs | 147 +++++ vortex-serde/src/layouts/read/layouts/flat.rs | 134 +++++ vortex-serde/src/layouts/read/layouts/mod.rs | 7 + vortex-serde/src/layouts/read/mod.rs | 8 +- vortex-serde/src/layouts/write/footer.rs | 38 +- vortex-serde/src/layouts/write/layouts.rs | 112 ++-- vortex-serde/src/layouts/write/writer.rs | 66 ++- 14 files changed, 782 insertions(+), 924 deletions(-) delete mode 100644 vortex-serde/src/layouts/read/layouts.rs create mode 100644 vortex-serde/src/layouts/read/layouts/chunked.rs create mode 100644 vortex-serde/src/layouts/read/layouts/column.rs create mode 100644 vortex-serde/src/layouts/read/layouts/flat.rs create mode 100644 vortex-serde/src/layouts/read/layouts/mod.rs diff --git a/vortex-flatbuffers/flatbuffers/vortex-serde/footer.fbs b/vortex-flatbuffers/flatbuffers/vortex-serde/footer.fbs index fecbf58f85..b467e57767 100644 --- a/vortex-flatbuffers/flatbuffers/vortex-serde/footer.fbs +++ b/vortex-flatbuffers/flatbuffers/vortex-serde/footer.fbs @@ -1,24 +1,18 @@ -table FlatLayout { - begin: uint64; - end: uint64; -} - -table NestedLayout { +table Layout { children: [Layout]; encoding: uint16; -} - -union LayoutVariant { - FlatLayout, - NestedLayout, -} - -table Layout { - layout: LayoutVariant; + metadata: [ubyte]; } table Footer { layout: Layout; + row_count: uint64; +} + +table Postscript { + schema_offset: uint64; + footer_offset: uint64; } -root_type Footer; \ No newline at end of file +root_type Footer; +root_type Postscript; \ No newline at end of file diff --git a/vortex-flatbuffers/src/generated/footer.rs b/vortex-flatbuffers/src/generated/footer.rs index 9db4c2d820..16c54008c3 100644 --- a/vortex-flatbuffers/src/generated/footer.rs +++ b/vortex-flatbuffers/src/generated/footer.rs @@ -9,240 +9,37 @@ use core::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::{EndianScalar, Follow}; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_LAYOUT_VARIANT: u8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_LAYOUT_VARIANT: u8 = 2; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_LAYOUT_VARIANT: [LayoutVariant; 3] = [ - LayoutVariant::NONE, - LayoutVariant::FlatLayout, - LayoutVariant::NestedLayout, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct LayoutVariant(pub u8); -#[allow(non_upper_case_globals)] -impl LayoutVariant { - pub const NONE: Self = Self(0); - pub const FlatLayout: Self = Self(1); - pub const NestedLayout: Self = Self(2); - - pub const ENUM_MIN: u8 = 0; - pub const ENUM_MAX: u8 = 2; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::NONE, - Self::FlatLayout, - Self::NestedLayout, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::NONE => Some("NONE"), - Self::FlatLayout => Some("FlatLayout"), - Self::NestedLayout => Some("NestedLayout"), - _ => None, - } - } -} -impl core::fmt::Debug for LayoutVariant { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for LayoutVariant { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for LayoutVariant { - type Output = LayoutVariant; - #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for LayoutVariant { - type Scalar = u8; - #[inline] - fn to_little_endian(self) -> u8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: u8) -> Self { - let b = u8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for LayoutVariant { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - u8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for LayoutVariant {} -pub struct LayoutVariantUnionTableOffset {} - -pub enum FlatLayoutOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct FlatLayout<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for FlatLayout<'a> { - type Inner = FlatLayout<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> FlatLayout<'a> { - pub const VT_BEGIN: flatbuffers::VOffsetT = 4; - pub const VT_END: flatbuffers::VOffsetT = 6; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - FlatLayout { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args FlatLayoutArgs - ) -> flatbuffers::WIPOffset> { - let mut builder = FlatLayoutBuilder::new(_fbb); - builder.add_end(args.end); - builder.add_begin(args.begin); - builder.finish() - } - - - #[inline] - pub fn begin(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(FlatLayout::VT_BEGIN, Some(0)).unwrap()} - } - #[inline] - pub fn end(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(FlatLayout::VT_END, Some(0)).unwrap()} - } -} - -impl flatbuffers::Verifiable for FlatLayout<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("begin", Self::VT_BEGIN, false)? - .visit_field::("end", Self::VT_END, false)? - .finish(); - Ok(()) - } -} -pub struct FlatLayoutArgs { - pub begin: u64, - pub end: u64, -} -impl<'a> Default for FlatLayoutArgs { - #[inline] - fn default() -> Self { - FlatLayoutArgs { - begin: 0, - end: 0, - } - } -} - -pub struct FlatLayoutBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> FlatLayoutBuilder<'a, 'b, A> { - #[inline] - pub fn add_begin(&mut self, begin: u64) { - self.fbb_.push_slot::(FlatLayout::VT_BEGIN, begin, 0); - } - #[inline] - pub fn add_end(&mut self, end: u64) { - self.fbb_.push_slot::(FlatLayout::VT_END, end, 0); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> FlatLayoutBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - FlatLayoutBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for FlatLayout<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("FlatLayout"); - ds.field("begin", &self.begin()); - ds.field("end", &self.end()); - ds.finish() - } -} -pub enum NestedLayoutOffset {} +pub enum LayoutOffset {} #[derive(Copy, Clone, PartialEq)] -pub struct NestedLayout<'a> { +pub struct Layout<'a> { pub _tab: flatbuffers::Table<'a>, } -impl<'a> flatbuffers::Follow<'a> for NestedLayout<'a> { - type Inner = NestedLayout<'a>; +impl<'a> flatbuffers::Follow<'a> for Layout<'a> { + type Inner = Layout<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: flatbuffers::Table::new(buf, loc) } } } -impl<'a> NestedLayout<'a> { +impl<'a> Layout<'a> { pub const VT_CHILDREN: flatbuffers::VOffsetT = 4; pub const VT_ENCODING: flatbuffers::VOffsetT = 6; + pub const VT_METADATA: flatbuffers::VOffsetT = 8; #[inline] pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - NestedLayout { _tab: table } + Layout { _tab: table } } #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args NestedLayoutArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = NestedLayoutBuilder::new(_fbb); + args: &'args LayoutArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = LayoutBuilder::new(_fbb); + if let Some(x) = args.metadata { builder.add_metadata(x); } if let Some(x) = args.children { builder.add_children(x); } builder.add_encoding(args.encoding); builder.finish() @@ -254,18 +51,25 @@ impl<'a> NestedLayout<'a> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>>(NestedLayout::VT_CHILDREN, None)} + unsafe { self._tab.get::>>>(Layout::VT_CHILDREN, None)} } #[inline] pub fn encoding(&self) -> u16 { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(NestedLayout::VT_ENCODING, Some(0)).unwrap()} + unsafe { self._tab.get::(Layout::VT_ENCODING, Some(0)).unwrap()} + } + #[inline] + pub fn metadata(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(Layout::VT_METADATA, None)} } } -impl flatbuffers::Verifiable for NestedLayout<'_> { +impl flatbuffers::Verifiable for Layout<'_> { #[inline] fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize @@ -274,393 +78,364 @@ impl flatbuffers::Verifiable for NestedLayout<'_> { v.visit_table(pos)? .visit_field::>>>("children", Self::VT_CHILDREN, false)? .visit_field::("encoding", Self::VT_ENCODING, false)? + .visit_field::>>("metadata", Self::VT_METADATA, false)? .finish(); Ok(()) } } -pub struct NestedLayoutArgs<'a> { +pub struct LayoutArgs<'a> { pub children: Option>>>>, pub encoding: u16, + pub metadata: Option>>, } -impl<'a> Default for NestedLayoutArgs<'a> { +impl<'a> Default for LayoutArgs<'a> { #[inline] fn default() -> Self { - NestedLayoutArgs { + LayoutArgs { children: None, encoding: 0, + metadata: None, } } } -pub struct NestedLayoutBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { +pub struct LayoutBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, start_: flatbuffers::WIPOffset, } -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> NestedLayoutBuilder<'a, 'b, A> { +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> LayoutBuilder<'a, 'b, A> { #[inline] pub fn add_children(&mut self, children: flatbuffers::WIPOffset>>>) { - self.fbb_.push_slot_always::>(NestedLayout::VT_CHILDREN, children); + self.fbb_.push_slot_always::>(Layout::VT_CHILDREN, children); } #[inline] pub fn add_encoding(&mut self, encoding: u16) { - self.fbb_.push_slot::(NestedLayout::VT_ENCODING, encoding, 0); + self.fbb_.push_slot::(Layout::VT_ENCODING, encoding, 0); + } + #[inline] + pub fn add_metadata(&mut self, metadata: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Layout::VT_METADATA, metadata); } #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> NestedLayoutBuilder<'a, 'b, A> { + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> LayoutBuilder<'a, 'b, A> { let start = _fbb.start_table(); - NestedLayoutBuilder { + LayoutBuilder { fbb_: _fbb, start_: start, } } #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { + pub fn finish(self) -> flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); flatbuffers::WIPOffset::new(o.value()) } } -impl core::fmt::Debug for NestedLayout<'_> { +impl core::fmt::Debug for Layout<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("NestedLayout"); + let mut ds = f.debug_struct("Layout"); ds.field("children", &self.children()); ds.field("encoding", &self.encoding()); + ds.field("metadata", &self.metadata()); ds.finish() } } -pub enum LayoutOffset {} +pub enum FooterOffset {} #[derive(Copy, Clone, PartialEq)] -pub struct Layout<'a> { +pub struct Footer<'a> { pub _tab: flatbuffers::Table<'a>, } -impl<'a> flatbuffers::Follow<'a> for Layout<'a> { - type Inner = Layout<'a>; +impl<'a> flatbuffers::Follow<'a> for Footer<'a> { + type Inner = Footer<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: flatbuffers::Table::new(buf, loc) } } } -impl<'a> Layout<'a> { - pub const VT_LAYOUT_TYPE: flatbuffers::VOffsetT = 4; - pub const VT_LAYOUT: flatbuffers::VOffsetT = 6; +impl<'a> Footer<'a> { + pub const VT_LAYOUT: flatbuffers::VOffsetT = 4; + pub const VT_ROW_COUNT: flatbuffers::VOffsetT = 6; #[inline] pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Layout { _tab: table } + Footer { _tab: table } } #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args LayoutArgs - ) -> flatbuffers::WIPOffset> { - let mut builder = LayoutBuilder::new(_fbb); + args: &'args FooterArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = FooterBuilder::new(_fbb); + builder.add_row_count(args.row_count); if let Some(x) = args.layout { builder.add_layout(x); } - builder.add_layout_type(args.layout_type); builder.finish() } #[inline] - pub fn layout_type(&self) -> LayoutVariant { + pub fn layout(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(Layout::VT_LAYOUT_TYPE, Some(LayoutVariant::NONE)).unwrap()} + unsafe { self._tab.get::>(Footer::VT_LAYOUT, None)} } #[inline] - pub fn layout(&self) -> Option> { + pub fn row_count(&self) -> u64 { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(Layout::VT_LAYOUT, None)} - } - #[inline] - #[allow(non_snake_case)] - pub fn layout_as_flat_layout(&self) -> Option> { - if self.layout_type() == LayoutVariant::FlatLayout { - self.layout().map(|t| { - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - unsafe { FlatLayout::init_from_table(t) } - }) - } else { - None - } + unsafe { self._tab.get::(Footer::VT_ROW_COUNT, Some(0)).unwrap()} } - - #[inline] - #[allow(non_snake_case)] - pub fn layout_as_nested_layout(&self) -> Option> { - if self.layout_type() == LayoutVariant::NestedLayout { - self.layout().map(|t| { - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - unsafe { NestedLayout::init_from_table(t) } - }) - } else { - None - } - } - } -impl flatbuffers::Verifiable for Layout<'_> { +impl flatbuffers::Verifiable for Footer<'_> { #[inline] fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; v.visit_table(pos)? - .visit_union::("layout_type", Self::VT_LAYOUT_TYPE, "layout", Self::VT_LAYOUT, false, |key, v, pos| { - match key { - LayoutVariant::FlatLayout => v.verify_union_variant::>("LayoutVariant::FlatLayout", pos), - LayoutVariant::NestedLayout => v.verify_union_variant::>("LayoutVariant::NestedLayout", pos), - _ => Ok(()), - } - })? + .visit_field::>("layout", Self::VT_LAYOUT, false)? + .visit_field::("row_count", Self::VT_ROW_COUNT, false)? .finish(); Ok(()) } } -pub struct LayoutArgs { - pub layout_type: LayoutVariant, - pub layout: Option>, +pub struct FooterArgs<'a> { + pub layout: Option>>, + pub row_count: u64, } -impl<'a> Default for LayoutArgs { +impl<'a> Default for FooterArgs<'a> { #[inline] fn default() -> Self { - LayoutArgs { - layout_type: LayoutVariant::NONE, + FooterArgs { layout: None, + row_count: 0, } } } -pub struct LayoutBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { +pub struct FooterBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, start_: flatbuffers::WIPOffset, } -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> LayoutBuilder<'a, 'b, A> { +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> FooterBuilder<'a, 'b, A> { #[inline] - pub fn add_layout_type(&mut self, layout_type: LayoutVariant) { - self.fbb_.push_slot::(Layout::VT_LAYOUT_TYPE, layout_type, LayoutVariant::NONE); + pub fn add_layout(&mut self, layout: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Footer::VT_LAYOUT, layout); } #[inline] - pub fn add_layout(&mut self, layout: flatbuffers::WIPOffset) { - self.fbb_.push_slot_always::>(Layout::VT_LAYOUT, layout); + pub fn add_row_count(&mut self, row_count: u64) { + self.fbb_.push_slot::(Footer::VT_ROW_COUNT, row_count, 0); } #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> LayoutBuilder<'a, 'b, A> { + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> FooterBuilder<'a, 'b, A> { let start = _fbb.start_table(); - LayoutBuilder { + FooterBuilder { fbb_: _fbb, start_: start, } } #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { + pub fn finish(self) -> flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); flatbuffers::WIPOffset::new(o.value()) } } -impl core::fmt::Debug for Layout<'_> { +impl core::fmt::Debug for Footer<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Layout"); - ds.field("layout_type", &self.layout_type()); - match self.layout_type() { - LayoutVariant::FlatLayout => { - if let Some(x) = self.layout_as_flat_layout() { - ds.field("layout", &x) - } else { - ds.field("layout", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - LayoutVariant::NestedLayout => { - if let Some(x) = self.layout_as_nested_layout() { - ds.field("layout", &x) - } else { - ds.field("layout", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - _ => { - let x: Option<()> = None; - ds.field("layout", &x) - }, - }; + let mut ds = f.debug_struct("Footer"); + ds.field("layout", &self.layout()); + ds.field("row_count", &self.row_count()); ds.finish() } } -pub enum FooterOffset {} +pub enum PostscriptOffset {} #[derive(Copy, Clone, PartialEq)] -pub struct Footer<'a> { +pub struct Postscript<'a> { pub _tab: flatbuffers::Table<'a>, } -impl<'a> flatbuffers::Follow<'a> for Footer<'a> { - type Inner = Footer<'a>; +impl<'a> flatbuffers::Follow<'a> for Postscript<'a> { + type Inner = Postscript<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: flatbuffers::Table::new(buf, loc) } } } -impl<'a> Footer<'a> { - pub const VT_LAYOUT: flatbuffers::VOffsetT = 4; +impl<'a> Postscript<'a> { + pub const VT_SCHEMA_OFFSET: flatbuffers::VOffsetT = 4; + pub const VT_FOOTER_OFFSET: flatbuffers::VOffsetT = 6; #[inline] pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Footer { _tab: table } + Postscript { _tab: table } } #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args FooterArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = FooterBuilder::new(_fbb); - if let Some(x) = args.layout { builder.add_layout(x); } + args: &'args PostscriptArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = PostscriptBuilder::new(_fbb); + builder.add_footer_offset(args.footer_offset); + builder.add_schema_offset(args.schema_offset); builder.finish() } #[inline] - pub fn layout(&self) -> Option> { + pub fn schema_offset(&self) -> u64 { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>(Footer::VT_LAYOUT, None)} + unsafe { self._tab.get::(Postscript::VT_SCHEMA_OFFSET, Some(0)).unwrap()} + } + #[inline] + pub fn footer_offset(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Postscript::VT_FOOTER_OFFSET, Some(0)).unwrap()} } } -impl flatbuffers::Verifiable for Footer<'_> { +impl flatbuffers::Verifiable for Postscript<'_> { #[inline] fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::>("layout", Self::VT_LAYOUT, false)? + .visit_field::("schema_offset", Self::VT_SCHEMA_OFFSET, false)? + .visit_field::("footer_offset", Self::VT_FOOTER_OFFSET, false)? .finish(); Ok(()) } } -pub struct FooterArgs<'a> { - pub layout: Option>>, +pub struct PostscriptArgs { + pub schema_offset: u64, + pub footer_offset: u64, } -impl<'a> Default for FooterArgs<'a> { +impl<'a> Default for PostscriptArgs { #[inline] fn default() -> Self { - FooterArgs { - layout: None, + PostscriptArgs { + schema_offset: 0, + footer_offset: 0, } } } -pub struct FooterBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { +pub struct PostscriptBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, start_: flatbuffers::WIPOffset, } -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> FooterBuilder<'a, 'b, A> { +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PostscriptBuilder<'a, 'b, A> { #[inline] - pub fn add_layout(&mut self, layout: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Footer::VT_LAYOUT, layout); + pub fn add_schema_offset(&mut self, schema_offset: u64) { + self.fbb_.push_slot::(Postscript::VT_SCHEMA_OFFSET, schema_offset, 0); } #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> FooterBuilder<'a, 'b, A> { + pub fn add_footer_offset(&mut self, footer_offset: u64) { + self.fbb_.push_slot::(Postscript::VT_FOOTER_OFFSET, footer_offset, 0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> PostscriptBuilder<'a, 'b, A> { let start = _fbb.start_table(); - FooterBuilder { + PostscriptBuilder { fbb_: _fbb, start_: start, } } #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { + pub fn finish(self) -> flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); flatbuffers::WIPOffset::new(o.value()) } } -impl core::fmt::Debug for Footer<'_> { +impl core::fmt::Debug for Postscript<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Footer"); - ds.field("layout", &self.layout()); + let mut ds = f.debug_struct("Postscript"); + ds.field("schema_offset", &self.schema_offset()); + ds.field("footer_offset", &self.footer_offset()); ds.finish() } } #[inline] -/// Verifies that a buffer of bytes contains a `Footer` +/// Verifies that a buffer of bytes contains a `Postscript` /// and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use -/// `root_as_footer_unchecked`. -pub fn root_as_footer(buf: &[u8]) -> Result { - flatbuffers::root::