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