Skip to main content

arrow_ipc/gen/
File.rs

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