arrow_ipc/gen/
File.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#![allow(dead_code)]
19#![allow(unused_imports)]
20
21use crate::gen::Schema::*;
22use flatbuffers::EndianScalar;
23use std::{cmp::Ordering, mem};
24// automatically generated by the FlatBuffers compiler, do not modify
25
26// struct Block, aligned to 8
27#[repr(transparent)]
28#[derive(Clone, Copy, PartialEq)]
29pub struct Block(pub [u8; 24]);
30impl Default for Block {
31    fn default() -> Self {
32        Self([0; 24])
33    }
34}
35impl core::fmt::Debug for Block {
36    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
37        f.debug_struct("Block")
38            .field("offset", &self.offset())
39            .field("metaDataLength", &self.metaDataLength())
40            .field("bodyLength", &self.bodyLength())
41            .finish()
42    }
43}
44
45impl flatbuffers::SimpleToVerifyInSlice for Block {}
46impl<'a> flatbuffers::Follow<'a> for Block {
47    type Inner = &'a Block;
48    #[inline]
49    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
50        <&'a Block>::follow(buf, loc)
51    }
52}
53impl<'a> flatbuffers::Follow<'a> for &'a Block {
54    type Inner = &'a Block;
55    #[inline]
56    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
57        flatbuffers::follow_cast_ref::<Block>(buf, loc)
58    }
59}
60impl<'b> flatbuffers::Push for Block {
61    type Output = Block;
62    #[inline]
63    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
64        let src = ::core::slice::from_raw_parts(self as *const Block as *const u8, Self::size());
65        dst.copy_from_slice(src);
66    }
67}
68
69impl<'a> flatbuffers::Verifiable for Block {
70    #[inline]
71    fn run_verifier(
72        v: &mut flatbuffers::Verifier,
73        pos: usize,
74    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
75        use flatbuffers::Verifiable;
76        v.in_buffer::<Self>(pos)
77    }
78}
79
80impl<'a> Block {
81    #[allow(clippy::too_many_arguments)]
82    pub fn new(offset: i64, metaDataLength: i32, bodyLength: i64) -> Self {
83        let mut s = Self([0; 24]);
84        s.set_offset(offset);
85        s.set_metaDataLength(metaDataLength);
86        s.set_bodyLength(bodyLength);
87        s
88    }
89
90    /// Index to the start of the RecordBlock (note this is past the Message header)
91    pub fn offset(&self) -> i64 {
92        let mut mem = core::mem::MaybeUninit::<<i64 as EndianScalar>::Scalar>::uninit();
93        // Safety:
94        // Created from a valid Table for this object
95        // Which contains a valid value in this slot
96        EndianScalar::from_little_endian(unsafe {
97            core::ptr::copy_nonoverlapping(
98                self.0[0..].as_ptr(),
99                mem.as_mut_ptr() as *mut u8,
100                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
101            );
102            mem.assume_init()
103        })
104    }
105
106    pub fn set_offset(&mut self, x: i64) {
107        let x_le = x.to_little_endian();
108        // Safety:
109        // Created from a valid Table for this object
110        // Which contains a valid value in this slot
111        unsafe {
112            core::ptr::copy_nonoverlapping(
113                &x_le as *const _ as *const u8,
114                self.0[0..].as_mut_ptr(),
115                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
116            );
117        }
118    }
119
120    /// Length of the metadata
121    pub fn metaDataLength(&self) -> i32 {
122        let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
123        // Safety:
124        // Created from a valid Table for this object
125        // Which contains a valid value in this slot
126        EndianScalar::from_little_endian(unsafe {
127            core::ptr::copy_nonoverlapping(
128                self.0[8..].as_ptr(),
129                mem.as_mut_ptr() as *mut u8,
130                core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
131            );
132            mem.assume_init()
133        })
134    }
135
136    pub fn set_metaDataLength(&mut self, x: i32) {
137        let x_le = x.to_little_endian();
138        // Safety:
139        // Created from a valid Table for this object
140        // Which contains a valid value in this slot
141        unsafe {
142            core::ptr::copy_nonoverlapping(
143                &x_le as *const _ as *const u8,
144                self.0[8..].as_mut_ptr(),
145                core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
146            );
147        }
148    }
149
150    /// Length of the data (this is aligned so there can be a gap between this and
151    /// the metadata).
152    pub fn bodyLength(&self) -> i64 {
153        let mut mem = core::mem::MaybeUninit::<<i64 as EndianScalar>::Scalar>::uninit();
154        // Safety:
155        // Created from a valid Table for this object
156        // Which contains a valid value in this slot
157        EndianScalar::from_little_endian(unsafe {
158            core::ptr::copy_nonoverlapping(
159                self.0[16..].as_ptr(),
160                mem.as_mut_ptr() as *mut u8,
161                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
162            );
163            mem.assume_init()
164        })
165    }
166
167    pub fn set_bodyLength(&mut self, x: i64) {
168        let x_le = x.to_little_endian();
169        // Safety:
170        // Created from a valid Table for this object
171        // Which contains a valid value in this slot
172        unsafe {
173            core::ptr::copy_nonoverlapping(
174                &x_le as *const _ as *const u8,
175                self.0[16..].as_mut_ptr(),
176                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
177            );
178        }
179    }
180}
181
182pub enum FooterOffset {}
183#[derive(Copy, Clone, PartialEq)]
184
185/// ----------------------------------------------------------------------
186/// Arrow File metadata
187///
188pub struct Footer<'a> {
189    pub _tab: flatbuffers::Table<'a>,
190}
191
192impl<'a> flatbuffers::Follow<'a> for Footer<'a> {
193    type Inner = Footer<'a>;
194    #[inline]
195    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
196        Self {
197            _tab: flatbuffers::Table::new(buf, loc),
198        }
199    }
200}
201
202impl<'a> Footer<'a> {
203    pub const VT_VERSION: flatbuffers::VOffsetT = 4;
204    pub const VT_SCHEMA: flatbuffers::VOffsetT = 6;
205    pub const VT_DICTIONARIES: flatbuffers::VOffsetT = 8;
206    pub const VT_RECORDBATCHES: flatbuffers::VOffsetT = 10;
207    pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 12;
208
209    #[inline]
210    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
211        Footer { _tab: table }
212    }
213    #[allow(unused_mut)]
214    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
215        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
216        args: &'args FooterArgs<'args>,
217    ) -> flatbuffers::WIPOffset<Footer<'bldr>> {
218        let mut builder = FooterBuilder::new(_fbb);
219        if let Some(x) = args.custom_metadata {
220            builder.add_custom_metadata(x);
221        }
222        if let Some(x) = args.recordBatches {
223            builder.add_recordBatches(x);
224        }
225        if let Some(x) = args.dictionaries {
226            builder.add_dictionaries(x);
227        }
228        if let Some(x) = args.schema {
229            builder.add_schema(x);
230        }
231        builder.add_version(args.version);
232        builder.finish()
233    }
234
235    #[inline]
236    pub fn version(&self) -> MetadataVersion {
237        // Safety:
238        // Created from valid Table for this object
239        // which contains a valid value in this slot
240        unsafe {
241            self._tab
242                .get::<MetadataVersion>(Footer::VT_VERSION, Some(MetadataVersion::V1))
243                .unwrap()
244        }
245    }
246    #[inline]
247    pub fn schema(&self) -> Option<Schema<'a>> {
248        // Safety:
249        // Created from valid Table for this object
250        // which contains a valid value in this slot
251        unsafe {
252            self._tab
253                .get::<flatbuffers::ForwardsUOffset<Schema>>(Footer::VT_SCHEMA, None)
254        }
255    }
256    #[inline]
257    pub fn dictionaries(&self) -> Option<flatbuffers::Vector<'a, Block>> {
258        // Safety:
259        // Created from valid Table for this object
260        // which contains a valid value in this slot
261        unsafe {
262            self._tab
263                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Block>>>(
264                    Footer::VT_DICTIONARIES,
265                    None,
266                )
267        }
268    }
269    #[inline]
270    pub fn recordBatches(&self) -> Option<flatbuffers::Vector<'a, Block>> {
271        // Safety:
272        // Created from valid Table for this object
273        // which contains a valid value in this slot
274        unsafe {
275            self._tab
276                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Block>>>(
277                    Footer::VT_RECORDBATCHES,
278                    None,
279                )
280        }
281    }
282    /// User-defined metadata
283    #[inline]
284    pub fn custom_metadata(
285        &self,
286    ) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<KeyValue<'a>>>> {
287        // Safety:
288        // Created from valid Table for this object
289        // which contains a valid value in this slot
290        unsafe {
291            self._tab.get::<flatbuffers::ForwardsUOffset<
292                flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<KeyValue>>,
293            >>(Footer::VT_CUSTOM_METADATA, None)
294        }
295    }
296}
297
298impl flatbuffers::Verifiable for Footer<'_> {
299    #[inline]
300    fn run_verifier(
301        v: &mut flatbuffers::Verifier,
302        pos: usize,
303    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
304        use flatbuffers::Verifiable;
305        v.visit_table(pos)?
306            .visit_field::<MetadataVersion>("version", Self::VT_VERSION, false)?
307            .visit_field::<flatbuffers::ForwardsUOffset<Schema>>("schema", Self::VT_SCHEMA, false)?
308            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Block>>>(
309                "dictionaries",
310                Self::VT_DICTIONARIES,
311                false,
312            )?
313            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Block>>>(
314                "recordBatches",
315                Self::VT_RECORDBATCHES,
316                false,
317            )?
318            .visit_field::<flatbuffers::ForwardsUOffset<
319                flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<KeyValue>>,
320            >>("custom_metadata", Self::VT_CUSTOM_METADATA, false)?
321            .finish();
322        Ok(())
323    }
324}
325pub struct FooterArgs<'a> {
326    pub version: MetadataVersion,
327    pub schema: Option<flatbuffers::WIPOffset<Schema<'a>>>,
328    pub dictionaries: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Block>>>,
329    pub recordBatches: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Block>>>,
330    pub custom_metadata: Option<
331        flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<KeyValue<'a>>>>,
332    >,
333}
334impl<'a> Default for FooterArgs<'a> {
335    #[inline]
336    fn default() -> Self {
337        FooterArgs {
338            version: MetadataVersion::V1,
339            schema: None,
340            dictionaries: None,
341            recordBatches: None,
342            custom_metadata: None,
343        }
344    }
345}
346
347pub struct FooterBuilder<'a: 'b, 'b> {
348    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
349    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
350}
351impl<'a: 'b, 'b> FooterBuilder<'a, 'b> {
352    #[inline]
353    pub fn add_version(&mut self, version: MetadataVersion) {
354        self.fbb_
355            .push_slot::<MetadataVersion>(Footer::VT_VERSION, version, MetadataVersion::V1);
356    }
357    #[inline]
358    pub fn add_schema(&mut self, schema: flatbuffers::WIPOffset<Schema<'b>>) {
359        self.fbb_
360            .push_slot_always::<flatbuffers::WIPOffset<Schema>>(Footer::VT_SCHEMA, schema);
361    }
362    #[inline]
363    pub fn add_dictionaries(
364        &mut self,
365        dictionaries: flatbuffers::WIPOffset<flatbuffers::Vector<'b, Block>>,
366    ) {
367        self.fbb_
368            .push_slot_always::<flatbuffers::WIPOffset<_>>(Footer::VT_DICTIONARIES, dictionaries);
369    }
370    #[inline]
371    pub fn add_recordBatches(
372        &mut self,
373        recordBatches: flatbuffers::WIPOffset<flatbuffers::Vector<'b, Block>>,
374    ) {
375        self.fbb_
376            .push_slot_always::<flatbuffers::WIPOffset<_>>(Footer::VT_RECORDBATCHES, recordBatches);
377    }
378    #[inline]
379    pub fn add_custom_metadata(
380        &mut self,
381        custom_metadata: flatbuffers::WIPOffset<
382            flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset<KeyValue<'b>>>,
383        >,
384    ) {
385        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
386            Footer::VT_CUSTOM_METADATA,
387            custom_metadata,
388        );
389    }
390    #[inline]
391    pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> FooterBuilder<'a, 'b> {
392        let start = _fbb.start_table();
393        FooterBuilder {
394            fbb_: _fbb,
395            start_: start,
396        }
397    }
398    #[inline]
399    pub fn finish(self) -> flatbuffers::WIPOffset<Footer<'a>> {
400        let o = self.fbb_.end_table(self.start_);
401        flatbuffers::WIPOffset::new(o.value())
402    }
403}
404
405impl core::fmt::Debug for Footer<'_> {
406    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
407        let mut ds = f.debug_struct("Footer");
408        ds.field("version", &self.version());
409        ds.field("schema", &self.schema());
410        ds.field("dictionaries", &self.dictionaries());
411        ds.field("recordBatches", &self.recordBatches());
412        ds.field("custom_metadata", &self.custom_metadata());
413        ds.finish()
414    }
415}
416#[inline]
417/// Verifies that a buffer of bytes contains a `Footer`
418/// and returns it.
419/// Note that verification is still experimental and may not
420/// catch every error, or be maximally performant. For the
421/// previous, unchecked, behavior use
422/// `root_as_footer_unchecked`.
423pub fn root_as_footer(buf: &[u8]) -> Result<Footer, flatbuffers::InvalidFlatbuffer> {
424    flatbuffers::root::<Footer>(buf)
425}
426#[inline]
427/// Verifies that a buffer of bytes contains a size prefixed
428/// `Footer` and returns it.
429/// Note that verification is still experimental and may not
430/// catch every error, or be maximally performant. For the
431/// previous, unchecked, behavior use
432/// `size_prefixed_root_as_footer_unchecked`.
433pub fn size_prefixed_root_as_footer(buf: &[u8]) -> Result<Footer, flatbuffers::InvalidFlatbuffer> {
434    flatbuffers::size_prefixed_root::<Footer>(buf)
435}
436#[inline]
437/// Verifies, with the given options, that a buffer of bytes
438/// contains a `Footer` and returns it.
439/// Note that verification is still experimental and may not
440/// catch every error, or be maximally performant. For the
441/// previous, unchecked, behavior use
442/// `root_as_footer_unchecked`.
443pub fn root_as_footer_with_opts<'b, 'o>(
444    opts: &'o flatbuffers::VerifierOptions,
445    buf: &'b [u8],
446) -> Result<Footer<'b>, flatbuffers::InvalidFlatbuffer> {
447    flatbuffers::root_with_opts::<Footer<'b>>(opts, buf)
448}
449#[inline]
450/// Verifies, with the given verifier options, that a buffer of
451/// bytes contains a size prefixed `Footer` and returns
452/// it. Note that verification is still experimental and may not
453/// catch every error, or be maximally performant. For the
454/// previous, unchecked, behavior use
455/// `root_as_footer_unchecked`.
456pub fn size_prefixed_root_as_footer_with_opts<'b, 'o>(
457    opts: &'o flatbuffers::VerifierOptions,
458    buf: &'b [u8],
459) -> Result<Footer<'b>, flatbuffers::InvalidFlatbuffer> {
460    flatbuffers::size_prefixed_root_with_opts::<Footer<'b>>(opts, buf)
461}
462#[inline]
463/// Assumes, without verification, that a buffer of bytes contains a Footer and returns it.
464/// # Safety
465/// Callers must trust the given bytes do indeed contain a valid `Footer`.
466pub unsafe fn root_as_footer_unchecked(buf: &[u8]) -> Footer {
467    flatbuffers::root_unchecked::<Footer>(buf)
468}
469#[inline]
470/// Assumes, without verification, that a buffer of bytes contains a size prefixed Footer and returns it.
471/// # Safety
472/// Callers must trust the given bytes do indeed contain a valid size prefixed `Footer`.
473pub unsafe fn size_prefixed_root_as_footer_unchecked(buf: &[u8]) -> Footer {
474    flatbuffers::size_prefixed_root_unchecked::<Footer>(buf)
475}
476#[inline]
477pub fn finish_footer_buffer<'a, 'b>(
478    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
479    root: flatbuffers::WIPOffset<Footer<'a>>,
480) {
481    fbb.finish(root, None);
482}
483
484#[inline]
485pub fn finish_size_prefixed_footer_buffer<'a, 'b>(
486    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
487    root: flatbuffers::WIPOffset<Footer<'a>>,
488) {
489    fbb.finish_size_prefixed(root, None);
490}