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