vortex_flatbuffers/
lib.rs1#![deny(missing_docs)]
9
10#[cfg(feature = "array")]
11#[allow(clippy::all)]
12#[allow(clippy::derive_partial_eq_without_eq)]
13#[allow(clippy::many_single_char_names)]
14#[allow(clippy::unwrap_used)]
15#[allow(clippy::borrow_as_ptr)]
16#[allow(dead_code)]
17#[allow(mismatched_lifetime_syntaxes)]
18#[allow(non_snake_case)]
19#[allow(non_camel_case_types)]
20#[allow(unused_imports)]
21#[allow(unused_lifetimes)]
22#[allow(unused_qualifications)]
23#[allow(missing_docs)]
24#[rustfmt::skip]
25#[path = "./generated/array.rs"]
26#[doc = include_str!("../flatbuffers/vortex-array/array.fbs")]
31pub mod array;
33
34#[cfg(feature = "dtype")]
35#[allow(clippy::all)]
36#[allow(clippy::derive_partial_eq_without_eq)]
37#[allow(clippy::many_single_char_names)]
38#[allow(clippy::unwrap_used)]
39#[allow(clippy::borrow_as_ptr)]
40#[allow(dead_code)]
41#[allow(mismatched_lifetime_syntaxes)]
42#[allow(non_snake_case)]
43#[allow(non_camel_case_types)]
44#[allow(unused_imports)]
45#[allow(unused_lifetimes)]
46#[allow(unused_qualifications)]
47#[allow(missing_docs)]
48#[rustfmt::skip]
49#[path = "./generated/dtype.rs"]
50#[doc = include_str!("../flatbuffers/vortex-dtype/dtype.fbs")]
55pub mod dtype;
57
58#[cfg(feature = "file")]
59#[allow(clippy::all)]
60#[allow(clippy::derive_partial_eq_without_eq)]
61#[allow(clippy::many_single_char_names)]
62#[allow(clippy::unwrap_used)]
63#[allow(clippy::borrow_as_ptr)]
64#[allow(dead_code)]
65#[allow(mismatched_lifetime_syntaxes)]
66#[allow(non_snake_case)]
67#[allow(non_camel_case_types)]
68#[allow(unused_imports)]
69#[allow(unused_lifetimes)]
70#[allow(unused_qualifications)]
71#[allow(missing_docs)]
72#[rustfmt::skip]
73#[path = "./generated/footer.rs"]
74#[doc = include_str!("../flatbuffers/vortex-file/footer.fbs")]
79pub mod footer;
81
82#[cfg(feature = "layout")]
83#[allow(clippy::all)]
84#[allow(clippy::derive_partial_eq_without_eq)]
85#[allow(clippy::many_single_char_names)]
86#[allow(clippy::unwrap_used)]
87#[allow(clippy::borrow_as_ptr)]
88#[allow(dead_code)]
89#[allow(mismatched_lifetime_syntaxes)]
90#[allow(non_snake_case)]
91#[allow(non_camel_case_types)]
92#[allow(unused_imports)]
93#[allow(unused_lifetimes)]
94#[allow(unused_qualifications)]
95#[allow(missing_docs)]
96#[rustfmt::skip]
97#[path = "./generated/layout.rs"]
98#[doc = include_str!("../flatbuffers/vortex-layout/layout.fbs")]
103pub mod layout;
105
106#[cfg(feature = "ipc")]
107#[allow(clippy::all)]
108#[allow(clippy::derive_partial_eq_without_eq)]
109#[allow(clippy::many_single_char_names)]
110#[allow(clippy::unwrap_used)]
111#[allow(clippy::borrow_as_ptr)]
112#[allow(dead_code)]
113#[allow(mismatched_lifetime_syntaxes)]
114#[allow(non_snake_case)]
115#[allow(non_camel_case_types)]
116#[allow(unused_imports)]
117#[allow(unused_lifetimes)]
118#[allow(unused_qualifications)]
119#[allow(missing_docs)]
120#[rustfmt::skip]
121#[path = "./generated/message.rs"]
122#[doc = include_str!("../flatbuffers/vortex-serde/message.fbs")]
127pub mod message;
129
130use flatbuffers::{FlatBufferBuilder, Follow, InvalidFlatbuffer, Verifiable, WIPOffset, root};
131use vortex_buffer::{ByteBuffer, ConstByteBuffer};
132
133pub type FlatBuffer = ConstByteBuffer<8>;
138
139pub trait FlatBufferRoot {}
141
142pub trait ReadFlatBuffer: Sized {
144 type Source<'a>: Verifiable + Follow<'a>;
146 type Error: From<InvalidFlatbuffer>;
148
149 fn read_flatbuffer<'buf>(
151 fb: &<Self::Source<'buf> as Follow<'buf>>::Inner,
152 ) -> Result<Self, Self::Error>;
153
154 fn read_flatbuffer_bytes<'buf>(bytes: &'buf [u8]) -> Result<Self, Self::Error>
156 where
157 <Self as ReadFlatBuffer>::Source<'buf>: 'buf,
158 {
159 let fb = root::<Self::Source<'buf>>(bytes)?;
160 Self::read_flatbuffer(&fb)
161 }
162}
163
164pub trait WriteFlatBuffer {
166 type Target<'a>;
168
169 fn write_flatbuffer<'fb>(
171 &self,
172 fbb: &mut FlatBufferBuilder<'fb>,
173 ) -> WIPOffset<Self::Target<'fb>>;
174}
175
176pub trait WriteFlatBufferExt: WriteFlatBuffer + FlatBufferRoot {
178 fn write_flatbuffer_bytes(&self) -> FlatBuffer;
180}
181
182impl<F: WriteFlatBuffer + FlatBufferRoot> WriteFlatBufferExt for F {
183 fn write_flatbuffer_bytes(&self) -> FlatBuffer {
184 let mut fbb = FlatBufferBuilder::new();
185 let root_offset = self.write_flatbuffer(&mut fbb);
186 fbb.finish_minimal(root_offset);
187 let (vec, start) = fbb.collapse();
188 let end = vec.len();
189 FlatBuffer::align_from(ByteBuffer::from(vec).slice(start..end))
190 }
191}