Skip to main content

arrow_ipc/gen/
Message.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 crate::r#gen::SparseTensor::*;
23use crate::r#gen::Tensor::*;
24use flatbuffers::EndianScalar;
25use std::{cmp::Ordering, mem};
26// automatically generated by the FlatBuffers compiler, do not modify
27
28// @generated
29
30#[deprecated(
31    since = "2.0.0",
32    note = "Use associated constants instead. This will no longer be generated in 2021."
33)]
34pub const ENUM_MIN_COMPRESSION_TYPE: i8 = 0;
35#[deprecated(
36    since = "2.0.0",
37    note = "Use associated constants instead. This will no longer be generated in 2021."
38)]
39pub const ENUM_MAX_COMPRESSION_TYPE: i8 = 1;
40#[deprecated(
41    since = "2.0.0",
42    note = "Use associated constants instead. This will no longer be generated in 2021."
43)]
44#[allow(non_camel_case_types)]
45pub const ENUM_VALUES_COMPRESSION_TYPE: [CompressionType; 2] =
46    [CompressionType::LZ4_FRAME, CompressionType::ZSTD];
47
48#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
49#[repr(transparent)]
50pub struct CompressionType(pub i8);
51#[allow(non_upper_case_globals)]
52impl CompressionType {
53    /// LZ4 frame format, for portability, as provided by lz4frame.h or wrappers
54    /// thereof. Not to be confused with "raw" (also called "block") format
55    /// provided by lz4.h
56    pub const LZ4_FRAME: Self = Self(0);
57    /// Zstandard
58    pub const ZSTD: Self = Self(1);
59
60    pub const ENUM_MIN: i8 = 0;
61    pub const ENUM_MAX: i8 = 1;
62    pub const ENUM_VALUES: &'static [Self] = &[Self::LZ4_FRAME, Self::ZSTD];
63    /// Returns the variant's name or "" if unknown.
64    pub fn variant_name(self) -> Option<&'static str> {
65        match self {
66            Self::LZ4_FRAME => Some("LZ4_FRAME"),
67            Self::ZSTD => Some("ZSTD"),
68            _ => None,
69        }
70    }
71}
72impl core::fmt::Debug for CompressionType {
73    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
74        if let Some(name) = self.variant_name() {
75            f.write_str(name)
76        } else {
77            f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
78        }
79    }
80}
81impl<'a> flatbuffers::Follow<'a> for CompressionType {
82    type Inner = Self;
83    #[inline]
84    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
85        let b = unsafe { flatbuffers::read_scalar_at::<i8>(buf, loc) };
86        Self(b)
87    }
88}
89
90impl flatbuffers::Push for CompressionType {
91    type Output = CompressionType;
92    #[inline]
93    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
94        unsafe {
95            flatbuffers::emplace_scalar::<i8>(dst, self.0);
96        }
97    }
98}
99
100impl flatbuffers::EndianScalar for CompressionType {
101    type Scalar = i8;
102    #[inline]
103    fn to_little_endian(self) -> i8 {
104        self.0.to_le()
105    }
106    #[inline]
107    #[allow(clippy::wrong_self_convention)]
108    fn from_little_endian(v: i8) -> Self {
109        let b = i8::from_le(v);
110        Self(b)
111    }
112}
113
114impl<'a> flatbuffers::Verifiable for CompressionType {
115    #[inline]
116    fn run_verifier(
117        v: &mut flatbuffers::Verifier,
118        pos: usize,
119    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
120        use flatbuffers::Verifiable;
121        i8::run_verifier(v, pos)
122    }
123}
124
125impl flatbuffers::SimpleToVerifyInSlice for CompressionType {}
126#[deprecated(
127    since = "2.0.0",
128    note = "Use associated constants instead. This will no longer be generated in 2021."
129)]
130pub const ENUM_MIN_BODY_COMPRESSION_METHOD: i8 = 0;
131#[deprecated(
132    since = "2.0.0",
133    note = "Use associated constants instead. This will no longer be generated in 2021."
134)]
135pub const ENUM_MAX_BODY_COMPRESSION_METHOD: i8 = 0;
136#[deprecated(
137    since = "2.0.0",
138    note = "Use associated constants instead. This will no longer be generated in 2021."
139)]
140#[allow(non_camel_case_types)]
141pub const ENUM_VALUES_BODY_COMPRESSION_METHOD: [BodyCompressionMethod; 1] =
142    [BodyCompressionMethod::BUFFER];
143
144/// Provided for forward compatibility in case we need to support different
145/// strategies for compressing the IPC message body (like whole-body
146/// compression rather than buffer-level) in the future
147#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
148#[repr(transparent)]
149pub struct BodyCompressionMethod(pub i8);
150#[allow(non_upper_case_globals)]
151impl BodyCompressionMethod {
152    /// Each constituent buffer is first compressed with the indicated
153    /// compressor, and then written with the uncompressed length in the first 8
154    /// bytes as a 64-bit little-endian signed integer followed by the compressed
155    /// buffer bytes (and then padding as required by the protocol). The
156    /// uncompressed length may be set to -1 to indicate that the data that
157    /// follows is not compressed, which can be useful for cases where
158    /// compression does not yield appreciable savings.
159    /// Also, empty buffers can optionally be written out as 0-byte compressed
160    /// buffers, thereby omitting the 8-bytes length header.
161    pub const BUFFER: Self = Self(0);
162
163    pub const ENUM_MIN: i8 = 0;
164    pub const ENUM_MAX: i8 = 0;
165    pub const ENUM_VALUES: &'static [Self] = &[Self::BUFFER];
166    /// Returns the variant's name or "" if unknown.
167    pub fn variant_name(self) -> Option<&'static str> {
168        match self {
169            Self::BUFFER => Some("BUFFER"),
170            _ => None,
171        }
172    }
173}
174impl core::fmt::Debug for BodyCompressionMethod {
175    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
176        if let Some(name) = self.variant_name() {
177            f.write_str(name)
178        } else {
179            f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
180        }
181    }
182}
183impl<'a> flatbuffers::Follow<'a> for BodyCompressionMethod {
184    type Inner = Self;
185    #[inline]
186    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
187        let b = unsafe { flatbuffers::read_scalar_at::<i8>(buf, loc) };
188        Self(b)
189    }
190}
191
192impl flatbuffers::Push for BodyCompressionMethod {
193    type Output = BodyCompressionMethod;
194    #[inline]
195    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
196        unsafe {
197            flatbuffers::emplace_scalar::<i8>(dst, self.0);
198        }
199    }
200}
201
202impl flatbuffers::EndianScalar for BodyCompressionMethod {
203    type Scalar = i8;
204    #[inline]
205    fn to_little_endian(self) -> i8 {
206        self.0.to_le()
207    }
208    #[inline]
209    #[allow(clippy::wrong_self_convention)]
210    fn from_little_endian(v: i8) -> Self {
211        let b = i8::from_le(v);
212        Self(b)
213    }
214}
215
216impl<'a> flatbuffers::Verifiable for BodyCompressionMethod {
217    #[inline]
218    fn run_verifier(
219        v: &mut flatbuffers::Verifier,
220        pos: usize,
221    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
222        use flatbuffers::Verifiable;
223        i8::run_verifier(v, pos)
224    }
225}
226
227impl flatbuffers::SimpleToVerifyInSlice for BodyCompressionMethod {}
228#[deprecated(
229    since = "2.0.0",
230    note = "Use associated constants instead. This will no longer be generated in 2021."
231)]
232pub const ENUM_MIN_MESSAGE_HEADER: u8 = 0;
233#[deprecated(
234    since = "2.0.0",
235    note = "Use associated constants instead. This will no longer be generated in 2021."
236)]
237pub const ENUM_MAX_MESSAGE_HEADER: u8 = 5;
238#[deprecated(
239    since = "2.0.0",
240    note = "Use associated constants instead. This will no longer be generated in 2021."
241)]
242#[allow(non_camel_case_types)]
243pub const ENUM_VALUES_MESSAGE_HEADER: [MessageHeader; 6] = [
244    MessageHeader::NONE,
245    MessageHeader::Schema,
246    MessageHeader::DictionaryBatch,
247    MessageHeader::RecordBatch,
248    MessageHeader::Tensor,
249    MessageHeader::SparseTensor,
250];
251
252/// ----------------------------------------------------------------------
253/// The root Message type
254/// This union enables us to easily send different message types without
255/// redundant storage, and in the future we can easily add new message types.
256///
257/// Arrow implementations do not need to implement all of the message types,
258/// which may include experimental metadata types. For maximum compatibility,
259/// it is best to send data using RecordBatch.
260///
261/// Tensor and SparseTensor are DEPRECATED. The recommended way to pass dense
262/// tensors over Arrow IPC is a RecordBatch field with the `arrow.fixed_shape_tensor`
263/// canonical type. Sparse tensors currently do not have a recommended replacement.
264#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
265#[repr(transparent)]
266pub struct MessageHeader(pub u8);
267#[allow(non_upper_case_globals)]
268impl MessageHeader {
269    pub const NONE: Self = Self(0);
270    pub const Schema: Self = Self(1);
271    pub const DictionaryBatch: Self = Self(2);
272    pub const RecordBatch: Self = Self(3);
273    pub const Tensor: Self = Self(4);
274    pub const SparseTensor: Self = Self(5);
275
276    pub const ENUM_MIN: u8 = 0;
277    pub const ENUM_MAX: u8 = 5;
278    pub const ENUM_VALUES: &'static [Self] = &[
279        Self::NONE,
280        Self::Schema,
281        Self::DictionaryBatch,
282        Self::RecordBatch,
283        Self::Tensor,
284        Self::SparseTensor,
285    ];
286    /// Returns the variant's name or "" if unknown.
287    pub fn variant_name(self) -> Option<&'static str> {
288        match self {
289            Self::NONE => Some("NONE"),
290            Self::Schema => Some("Schema"),
291            Self::DictionaryBatch => Some("DictionaryBatch"),
292            Self::RecordBatch => Some("RecordBatch"),
293            Self::Tensor => Some("Tensor"),
294            Self::SparseTensor => Some("SparseTensor"),
295            _ => None,
296        }
297    }
298}
299impl core::fmt::Debug for MessageHeader {
300    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
301        if let Some(name) = self.variant_name() {
302            f.write_str(name)
303        } else {
304            f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
305        }
306    }
307}
308impl<'a> flatbuffers::Follow<'a> for MessageHeader {
309    type Inner = Self;
310    #[inline]
311    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
312        let b = unsafe { flatbuffers::read_scalar_at::<u8>(buf, loc) };
313        Self(b)
314    }
315}
316
317impl flatbuffers::Push for MessageHeader {
318    type Output = MessageHeader;
319    #[inline]
320    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
321        unsafe {
322            flatbuffers::emplace_scalar::<u8>(dst, self.0);
323        }
324    }
325}
326
327impl flatbuffers::EndianScalar for MessageHeader {
328    type Scalar = u8;
329    #[inline]
330    fn to_little_endian(self) -> u8 {
331        self.0.to_le()
332    }
333    #[inline]
334    #[allow(clippy::wrong_self_convention)]
335    fn from_little_endian(v: u8) -> Self {
336        let b = u8::from_le(v);
337        Self(b)
338    }
339}
340
341impl<'a> flatbuffers::Verifiable for MessageHeader {
342    #[inline]
343    fn run_verifier(
344        v: &mut flatbuffers::Verifier,
345        pos: usize,
346    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
347        use flatbuffers::Verifiable;
348        u8::run_verifier(v, pos)
349    }
350}
351
352impl flatbuffers::SimpleToVerifyInSlice for MessageHeader {}
353pub struct MessageHeaderUnionTableOffset {}
354
355/// ----------------------------------------------------------------------
356/// Data structures for describing a table row batch (a collection of
357/// equal-length Arrow arrays)
358/// Metadata about a field at some level of a nested type tree (but not
359/// its children).
360///
361/// For example, a `List<Int16>` with values `[[1, 2, 3], null, [4], [5, 6], null]`
362/// would have {length: 5, null_count: 2} for its List node, and {length: 6,
363/// null_count: 0} for its Int16 node, as separate FieldNode structs
364// struct FieldNode, aligned to 8
365#[repr(transparent)]
366#[derive(Clone, Copy, PartialEq)]
367pub struct FieldNode(pub [u8; 16]);
368impl Default for FieldNode {
369    fn default() -> Self {
370        Self([0; 16])
371    }
372}
373impl core::fmt::Debug for FieldNode {
374    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
375        f.debug_struct("FieldNode")
376            .field("length", &self.length())
377            .field("null_count", &self.null_count())
378            .finish()
379    }
380}
381
382impl flatbuffers::SimpleToVerifyInSlice for FieldNode {}
383impl<'a> flatbuffers::Follow<'a> for FieldNode {
384    type Inner = &'a FieldNode;
385    #[inline]
386    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
387        unsafe { <&'a FieldNode>::follow(buf, loc) }
388    }
389}
390impl<'a> flatbuffers::Follow<'a> for &'a FieldNode {
391    type Inner = &'a FieldNode;
392    #[inline]
393    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
394        unsafe { flatbuffers::follow_cast_ref::<FieldNode>(buf, loc) }
395    }
396}
397impl<'b> flatbuffers::Push for FieldNode {
398    type Output = FieldNode;
399    #[inline]
400    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
401        let src = unsafe {
402            ::core::slice::from_raw_parts(
403                self as *const FieldNode as *const u8,
404                <Self as flatbuffers::Push>::size(),
405            )
406        };
407        dst.copy_from_slice(src);
408    }
409    #[inline]
410    fn alignment() -> flatbuffers::PushAlignment {
411        flatbuffers::PushAlignment::new(8)
412    }
413}
414
415impl<'a> flatbuffers::Verifiable for FieldNode {
416    #[inline]
417    fn run_verifier(
418        v: &mut flatbuffers::Verifier,
419        pos: usize,
420    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
421        use flatbuffers::Verifiable;
422        v.in_buffer::<Self>(pos)
423    }
424}
425
426impl<'a> FieldNode {
427    #[allow(clippy::too_many_arguments)]
428    pub fn new(length: i64, null_count: i64) -> Self {
429        let mut s = Self([0; 16]);
430        s.set_length(length);
431        s.set_null_count(null_count);
432        s
433    }
434
435    /// The number of value slots in the Arrow array at this level of a nested
436    /// tree
437    pub fn length(&self) -> i64 {
438        let mut mem = core::mem::MaybeUninit::<<i64 as EndianScalar>::Scalar>::uninit();
439        // Safety:
440        // Created from a valid Table for this object
441        // Which contains a valid value in this slot
442        EndianScalar::from_little_endian(unsafe {
443            core::ptr::copy_nonoverlapping(
444                self.0[0..].as_ptr(),
445                mem.as_mut_ptr() as *mut u8,
446                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
447            );
448            mem.assume_init()
449        })
450    }
451
452    pub fn set_length(&mut self, x: i64) {
453        let x_le = x.to_little_endian();
454        // Safety:
455        // Created from a valid Table for this object
456        // Which contains a valid value in this slot
457        unsafe {
458            core::ptr::copy_nonoverlapping(
459                &x_le as *const _ as *const u8,
460                self.0[0..].as_mut_ptr(),
461                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
462            );
463        }
464    }
465
466    /// The number of observed nulls. Fields with null_count == 0 may choose not
467    /// to write their physical validity bitmap out as a materialized buffer,
468    /// instead setting the length of the bitmap buffer to 0.
469    pub fn null_count(&self) -> i64 {
470        let mut mem = core::mem::MaybeUninit::<<i64 as EndianScalar>::Scalar>::uninit();
471        // Safety:
472        // Created from a valid Table for this object
473        // Which contains a valid value in this slot
474        EndianScalar::from_little_endian(unsafe {
475            core::ptr::copy_nonoverlapping(
476                self.0[8..].as_ptr(),
477                mem.as_mut_ptr() as *mut u8,
478                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
479            );
480            mem.assume_init()
481        })
482    }
483
484    pub fn set_null_count(&mut self, x: i64) {
485        let x_le = x.to_little_endian();
486        // Safety:
487        // Created from a valid Table for this object
488        // Which contains a valid value in this slot
489        unsafe {
490            core::ptr::copy_nonoverlapping(
491                &x_le as *const _ as *const u8,
492                self.0[8..].as_mut_ptr(),
493                core::mem::size_of::<<i64 as EndianScalar>::Scalar>(),
494            );
495        }
496    }
497}
498
499pub enum BodyCompressionOffset {}
500#[derive(Copy, Clone, PartialEq)]
501
502/// Optional compression for the memory buffers constituting IPC message
503/// bodies. Intended for use with RecordBatch but could be used for other
504/// message types
505pub struct BodyCompression<'a> {
506    pub _tab: flatbuffers::Table<'a>,
507}
508
509impl<'a> flatbuffers::Follow<'a> for BodyCompression<'a> {
510    type Inner = BodyCompression<'a>;
511    #[inline]
512    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
513        Self {
514            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
515        }
516    }
517}
518
519impl<'a> BodyCompression<'a> {
520    pub const VT_CODEC: flatbuffers::VOffsetT = 4;
521    pub const VT_METHOD: flatbuffers::VOffsetT = 6;
522
523    #[inline]
524    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
525        BodyCompression { _tab: table }
526    }
527    #[allow(unused_mut)]
528    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
529        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
530        args: &'args BodyCompressionArgs,
531    ) -> flatbuffers::WIPOffset<BodyCompression<'bldr>> {
532        let mut builder = BodyCompressionBuilder::new(_fbb);
533        builder.add_method(args.method);
534        builder.add_codec(args.codec);
535        builder.finish()
536    }
537
538    /// Compressor library.
539    /// For LZ4_FRAME, each compressed buffer must consist of a single frame.
540    #[inline]
541    pub fn codec(&self) -> CompressionType {
542        // Safety:
543        // Created from valid Table for this object
544        // which contains a valid value in this slot
545        unsafe {
546            self._tab
547                .get::<CompressionType>(BodyCompression::VT_CODEC, Some(CompressionType::LZ4_FRAME))
548                .unwrap()
549        }
550    }
551    /// Indicates the way the record batch body was compressed
552    #[inline]
553    pub fn method(&self) -> BodyCompressionMethod {
554        // Safety:
555        // Created from valid Table for this object
556        // which contains a valid value in this slot
557        unsafe {
558            self._tab
559                .get::<BodyCompressionMethod>(
560                    BodyCompression::VT_METHOD,
561                    Some(BodyCompressionMethod::BUFFER),
562                )
563                .unwrap()
564        }
565    }
566}
567
568impl flatbuffers::Verifiable for BodyCompression<'_> {
569    #[inline]
570    fn run_verifier(
571        v: &mut flatbuffers::Verifier,
572        pos: usize,
573    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
574        use flatbuffers::Verifiable;
575        v.visit_table(pos)?
576            .visit_field::<CompressionType>("codec", Self::VT_CODEC, false)?
577            .visit_field::<BodyCompressionMethod>("method", Self::VT_METHOD, false)?
578            .finish();
579        Ok(())
580    }
581}
582pub struct BodyCompressionArgs {
583    pub codec: CompressionType,
584    pub method: BodyCompressionMethod,
585}
586impl<'a> Default for BodyCompressionArgs {
587    #[inline]
588    fn default() -> Self {
589        BodyCompressionArgs {
590            codec: CompressionType::LZ4_FRAME,
591            method: BodyCompressionMethod::BUFFER,
592        }
593    }
594}
595
596pub struct BodyCompressionBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
597    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
598    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
599}
600impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> BodyCompressionBuilder<'a, 'b, A> {
601    #[inline]
602    pub fn add_codec(&mut self, codec: CompressionType) {
603        self.fbb_.push_slot::<CompressionType>(
604            BodyCompression::VT_CODEC,
605            codec,
606            CompressionType::LZ4_FRAME,
607        );
608    }
609    #[inline]
610    pub fn add_method(&mut self, method: BodyCompressionMethod) {
611        self.fbb_.push_slot::<BodyCompressionMethod>(
612            BodyCompression::VT_METHOD,
613            method,
614            BodyCompressionMethod::BUFFER,
615        );
616    }
617    #[inline]
618    pub fn new(
619        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
620    ) -> BodyCompressionBuilder<'a, 'b, A> {
621        let start = _fbb.start_table();
622        BodyCompressionBuilder {
623            fbb_: _fbb,
624            start_: start,
625        }
626    }
627    #[inline]
628    pub fn finish(self) -> flatbuffers::WIPOffset<BodyCompression<'a>> {
629        let o = self.fbb_.end_table(self.start_);
630        flatbuffers::WIPOffset::new(o.value())
631    }
632}
633
634impl core::fmt::Debug for BodyCompression<'_> {
635    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
636        let mut ds = f.debug_struct("BodyCompression");
637        ds.field("codec", &self.codec());
638        ds.field("method", &self.method());
639        ds.finish()
640    }
641}
642pub enum RecordBatchOffset {}
643#[derive(Copy, Clone, PartialEq)]
644
645/// A data header describing the shared memory layout of a "record" or "row"
646/// batch. Some systems call this a "row batch" internally and others a "record
647/// batch".
648pub struct RecordBatch<'a> {
649    pub _tab: flatbuffers::Table<'a>,
650}
651
652impl<'a> flatbuffers::Follow<'a> for RecordBatch<'a> {
653    type Inner = RecordBatch<'a>;
654    #[inline]
655    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
656        Self {
657            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
658        }
659    }
660}
661
662impl<'a> RecordBatch<'a> {
663    pub const VT_LENGTH: flatbuffers::VOffsetT = 4;
664    pub const VT_NODES: flatbuffers::VOffsetT = 6;
665    pub const VT_BUFFERS: flatbuffers::VOffsetT = 8;
666    pub const VT_COMPRESSION: flatbuffers::VOffsetT = 10;
667    pub const VT_VARIADICBUFFERCOUNTS: flatbuffers::VOffsetT = 12;
668
669    #[inline]
670    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
671        RecordBatch { _tab: table }
672    }
673    #[allow(unused_mut)]
674    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
675        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
676        args: &'args RecordBatchArgs<'args>,
677    ) -> flatbuffers::WIPOffset<RecordBatch<'bldr>> {
678        let mut builder = RecordBatchBuilder::new(_fbb);
679        builder.add_length(args.length);
680        if let Some(x) = args.variadicBufferCounts {
681            builder.add_variadicBufferCounts(x);
682        }
683        if let Some(x) = args.compression {
684            builder.add_compression(x);
685        }
686        if let Some(x) = args.buffers {
687            builder.add_buffers(x);
688        }
689        if let Some(x) = args.nodes {
690            builder.add_nodes(x);
691        }
692        builder.finish()
693    }
694
695    /// number of records / rows. The arrays in the batch should all have this
696    /// length
697    #[inline]
698    pub fn length(&self) -> i64 {
699        // Safety:
700        // Created from valid Table for this object
701        // which contains a valid value in this slot
702        unsafe {
703            self._tab
704                .get::<i64>(RecordBatch::VT_LENGTH, Some(0))
705                .unwrap()
706        }
707    }
708    /// Nodes correspond to the pre-ordered flattened logical schema
709    #[inline]
710    pub fn nodes(&self) -> Option<flatbuffers::Vector<'a, FieldNode>> {
711        // Safety:
712        // Created from valid Table for this object
713        // which contains a valid value in this slot
714        unsafe {
715            self._tab
716                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, FieldNode>>>(
717                    RecordBatch::VT_NODES,
718                    None,
719                )
720        }
721    }
722    /// Buffers correspond to the pre-ordered flattened buffer tree
723    ///
724    /// The number of buffers appended to this list depends on the schema. For
725    /// example, most primitive arrays will have 2 buffers, 1 for the validity
726    /// bitmap and 1 for the values. For struct arrays, there will only be a
727    /// single buffer for the validity (nulls) bitmap
728    #[inline]
729    pub fn buffers(&self) -> Option<flatbuffers::Vector<'a, Buffer>> {
730        // Safety:
731        // Created from valid Table for this object
732        // which contains a valid value in this slot
733        unsafe {
734            self._tab
735                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Buffer>>>(
736                    RecordBatch::VT_BUFFERS,
737                    None,
738                )
739        }
740    }
741    /// Optional compression of the message body
742    #[inline]
743    pub fn compression(&self) -> Option<BodyCompression<'a>> {
744        // Safety:
745        // Created from valid Table for this object
746        // which contains a valid value in this slot
747        unsafe {
748            self._tab
749                .get::<flatbuffers::ForwardsUOffset<BodyCompression>>(
750                    RecordBatch::VT_COMPRESSION,
751                    None,
752                )
753        }
754    }
755    /// Some types such as Utf8View are represented using a variable number of buffers.
756    /// For each such Field in the pre-ordered flattened logical schema, there will be
757    /// an entry in variadicBufferCounts to indicate the number of variadic
758    /// buffers which belong to that Field in the current RecordBatch.
759    ///
760    /// For example, the schema
761    ///     col1: Struct<alpha: Int32, beta: BinaryView, gamma: Float64>
762    ///     col2: Utf8View
763    /// contains two Fields with variadic buffers so variadicBufferCounts will have
764    /// two entries, the first counting the variadic buffers of `col1.beta` and the
765    /// second counting `col2`'s.
766    ///
767    /// This field may be omitted if and only if the schema contains no Fields with
768    /// a variable number of buffers, such as BinaryView and Utf8View.
769    #[inline]
770    pub fn variadicBufferCounts(&self) -> Option<flatbuffers::Vector<'a, i64>> {
771        // Safety:
772        // Created from valid Table for this object
773        // which contains a valid value in this slot
774        unsafe {
775            self._tab
776                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(
777                    RecordBatch::VT_VARIADICBUFFERCOUNTS,
778                    None,
779                )
780        }
781    }
782}
783
784impl flatbuffers::Verifiable for RecordBatch<'_> {
785    #[inline]
786    fn run_verifier(
787        v: &mut flatbuffers::Verifier,
788        pos: usize,
789    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
790        use flatbuffers::Verifiable;
791        v.visit_table(pos)?
792            .visit_field::<i64>("length", Self::VT_LENGTH, false)?
793            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, FieldNode>>>(
794                "nodes",
795                Self::VT_NODES,
796                false,
797            )?
798            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Buffer>>>(
799                "buffers",
800                Self::VT_BUFFERS,
801                false,
802            )?
803            .visit_field::<flatbuffers::ForwardsUOffset<BodyCompression>>(
804                "compression",
805                Self::VT_COMPRESSION,
806                false,
807            )?
808            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, i64>>>(
809                "variadicBufferCounts",
810                Self::VT_VARIADICBUFFERCOUNTS,
811                false,
812            )?
813            .finish();
814        Ok(())
815    }
816}
817pub struct RecordBatchArgs<'a> {
818    pub length: i64,
819    pub nodes: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, FieldNode>>>,
820    pub buffers: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Buffer>>>,
821    pub compression: Option<flatbuffers::WIPOffset<BodyCompression<'a>>>,
822    pub variadicBufferCounts: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, i64>>>,
823}
824impl<'a> Default for RecordBatchArgs<'a> {
825    #[inline]
826    fn default() -> Self {
827        RecordBatchArgs {
828            length: 0,
829            nodes: None,
830            buffers: None,
831            compression: None,
832            variadicBufferCounts: None,
833        }
834    }
835}
836
837pub struct RecordBatchBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
838    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
839    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
840}
841impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> RecordBatchBuilder<'a, 'b, A> {
842    #[inline]
843    pub fn add_length(&mut self, length: i64) {
844        self.fbb_
845            .push_slot::<i64>(RecordBatch::VT_LENGTH, length, 0);
846    }
847    #[inline]
848    pub fn add_nodes(&mut self, nodes: flatbuffers::WIPOffset<flatbuffers::Vector<'b, FieldNode>>) {
849        self.fbb_
850            .push_slot_always::<flatbuffers::WIPOffset<_>>(RecordBatch::VT_NODES, nodes);
851    }
852    #[inline]
853    pub fn add_buffers(
854        &mut self,
855        buffers: flatbuffers::WIPOffset<flatbuffers::Vector<'b, Buffer>>,
856    ) {
857        self.fbb_
858            .push_slot_always::<flatbuffers::WIPOffset<_>>(RecordBatch::VT_BUFFERS, buffers);
859    }
860    #[inline]
861    pub fn add_compression(&mut self, compression: flatbuffers::WIPOffset<BodyCompression<'b>>) {
862        self.fbb_
863            .push_slot_always::<flatbuffers::WIPOffset<BodyCompression>>(
864                RecordBatch::VT_COMPRESSION,
865                compression,
866            );
867    }
868    #[inline]
869    pub fn add_variadicBufferCounts(
870        &mut self,
871        variadicBufferCounts: flatbuffers::WIPOffset<flatbuffers::Vector<'b, i64>>,
872    ) {
873        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
874            RecordBatch::VT_VARIADICBUFFERCOUNTS,
875            variadicBufferCounts,
876        );
877    }
878    #[inline]
879    pub fn new(
880        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
881    ) -> RecordBatchBuilder<'a, 'b, A> {
882        let start = _fbb.start_table();
883        RecordBatchBuilder {
884            fbb_: _fbb,
885            start_: start,
886        }
887    }
888    #[inline]
889    pub fn finish(self) -> flatbuffers::WIPOffset<RecordBatch<'a>> {
890        let o = self.fbb_.end_table(self.start_);
891        flatbuffers::WIPOffset::new(o.value())
892    }
893}
894
895impl core::fmt::Debug for RecordBatch<'_> {
896    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
897        let mut ds = f.debug_struct("RecordBatch");
898        ds.field("length", &self.length());
899        ds.field("nodes", &self.nodes());
900        ds.field("buffers", &self.buffers());
901        ds.field("compression", &self.compression());
902        ds.field("variadicBufferCounts", &self.variadicBufferCounts());
903        ds.finish()
904    }
905}
906pub enum DictionaryBatchOffset {}
907#[derive(Copy, Clone, PartialEq)]
908
909/// For sending dictionary encoding information. Any Field can be
910/// dictionary-encoded, but in this case none of its children may be
911/// dictionary-encoded.
912/// There is one vector / column per dictionary, but that vector / column
913/// may be spread across multiple dictionary batches by using the isDelta
914/// flag
915pub struct DictionaryBatch<'a> {
916    pub _tab: flatbuffers::Table<'a>,
917}
918
919impl<'a> flatbuffers::Follow<'a> for DictionaryBatch<'a> {
920    type Inner = DictionaryBatch<'a>;
921    #[inline]
922    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
923        Self {
924            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
925        }
926    }
927}
928
929impl<'a> DictionaryBatch<'a> {
930    pub const VT_ID: flatbuffers::VOffsetT = 4;
931    pub const VT_DATA: flatbuffers::VOffsetT = 6;
932    pub const VT_ISDELTA: flatbuffers::VOffsetT = 8;
933
934    #[inline]
935    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
936        DictionaryBatch { _tab: table }
937    }
938    #[allow(unused_mut)]
939    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
940        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
941        args: &'args DictionaryBatchArgs<'args>,
942    ) -> flatbuffers::WIPOffset<DictionaryBatch<'bldr>> {
943        let mut builder = DictionaryBatchBuilder::new(_fbb);
944        builder.add_id(args.id);
945        if let Some(x) = args.data {
946            builder.add_data(x);
947        }
948        builder.add_isDelta(args.isDelta);
949        builder.finish()
950    }
951
952    #[inline]
953    pub fn id(&self) -> i64 {
954        // Safety:
955        // Created from valid Table for this object
956        // which contains a valid value in this slot
957        unsafe {
958            self._tab
959                .get::<i64>(DictionaryBatch::VT_ID, Some(0))
960                .unwrap()
961        }
962    }
963    #[inline]
964    pub fn data(&self) -> Option<RecordBatch<'a>> {
965        // Safety:
966        // Created from valid Table for this object
967        // which contains a valid value in this slot
968        unsafe {
969            self._tab
970                .get::<flatbuffers::ForwardsUOffset<RecordBatch>>(DictionaryBatch::VT_DATA, None)
971        }
972    }
973    /// If isDelta is true the values in the dictionary are to be appended to a
974    /// dictionary with the indicated id. If isDelta is false this dictionary
975    /// should replace the existing dictionary.
976    #[inline]
977    pub fn isDelta(&self) -> bool {
978        // Safety:
979        // Created from valid Table for this object
980        // which contains a valid value in this slot
981        unsafe {
982            self._tab
983                .get::<bool>(DictionaryBatch::VT_ISDELTA, Some(false))
984                .unwrap()
985        }
986    }
987}
988
989impl flatbuffers::Verifiable for DictionaryBatch<'_> {
990    #[inline]
991    fn run_verifier(
992        v: &mut flatbuffers::Verifier,
993        pos: usize,
994    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
995        use flatbuffers::Verifiable;
996        v.visit_table(pos)?
997            .visit_field::<i64>("id", Self::VT_ID, false)?
998            .visit_field::<flatbuffers::ForwardsUOffset<RecordBatch>>("data", Self::VT_DATA, false)?
999            .visit_field::<bool>("isDelta", Self::VT_ISDELTA, false)?
1000            .finish();
1001        Ok(())
1002    }
1003}
1004pub struct DictionaryBatchArgs<'a> {
1005    pub id: i64,
1006    pub data: Option<flatbuffers::WIPOffset<RecordBatch<'a>>>,
1007    pub isDelta: bool,
1008}
1009impl<'a> Default for DictionaryBatchArgs<'a> {
1010    #[inline]
1011    fn default() -> Self {
1012        DictionaryBatchArgs {
1013            id: 0,
1014            data: None,
1015            isDelta: false,
1016        }
1017    }
1018}
1019
1020pub struct DictionaryBatchBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
1021    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1022    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
1023}
1024impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> DictionaryBatchBuilder<'a, 'b, A> {
1025    #[inline]
1026    pub fn add_id(&mut self, id: i64) {
1027        self.fbb_.push_slot::<i64>(DictionaryBatch::VT_ID, id, 0);
1028    }
1029    #[inline]
1030    pub fn add_data(&mut self, data: flatbuffers::WIPOffset<RecordBatch<'b>>) {
1031        self.fbb_
1032            .push_slot_always::<flatbuffers::WIPOffset<RecordBatch>>(
1033                DictionaryBatch::VT_DATA,
1034                data,
1035            );
1036    }
1037    #[inline]
1038    pub fn add_isDelta(&mut self, isDelta: bool) {
1039        self.fbb_
1040            .push_slot::<bool>(DictionaryBatch::VT_ISDELTA, isDelta, false);
1041    }
1042    #[inline]
1043    pub fn new(
1044        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1045    ) -> DictionaryBatchBuilder<'a, 'b, A> {
1046        let start = _fbb.start_table();
1047        DictionaryBatchBuilder {
1048            fbb_: _fbb,
1049            start_: start,
1050        }
1051    }
1052    #[inline]
1053    pub fn finish(self) -> flatbuffers::WIPOffset<DictionaryBatch<'a>> {
1054        let o = self.fbb_.end_table(self.start_);
1055        flatbuffers::WIPOffset::new(o.value())
1056    }
1057}
1058
1059impl core::fmt::Debug for DictionaryBatch<'_> {
1060    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1061        let mut ds = f.debug_struct("DictionaryBatch");
1062        ds.field("id", &self.id());
1063        ds.field("data", &self.data());
1064        ds.field("isDelta", &self.isDelta());
1065        ds.finish()
1066    }
1067}
1068pub enum MessageOffset {}
1069#[derive(Copy, Clone, PartialEq)]
1070
1071pub struct Message<'a> {
1072    pub _tab: flatbuffers::Table<'a>,
1073}
1074
1075impl<'a> flatbuffers::Follow<'a> for Message<'a> {
1076    type Inner = Message<'a>;
1077    #[inline]
1078    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
1079        Self {
1080            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
1081        }
1082    }
1083}
1084
1085impl<'a> Message<'a> {
1086    pub const VT_VERSION: flatbuffers::VOffsetT = 4;
1087    pub const VT_HEADER_TYPE: flatbuffers::VOffsetT = 6;
1088    pub const VT_HEADER: flatbuffers::VOffsetT = 8;
1089    pub const VT_BODYLENGTH: flatbuffers::VOffsetT = 10;
1090    pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 12;
1091
1092    #[inline]
1093    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
1094        Message { _tab: table }
1095    }
1096    #[allow(unused_mut)]
1097    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
1098        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
1099        args: &'args MessageArgs<'args>,
1100    ) -> flatbuffers::WIPOffset<Message<'bldr>> {
1101        let mut builder = MessageBuilder::new(_fbb);
1102        builder.add_bodyLength(args.bodyLength);
1103        if let Some(x) = args.custom_metadata {
1104            builder.add_custom_metadata(x);
1105        }
1106        if let Some(x) = args.header {
1107            builder.add_header(x);
1108        }
1109        builder.add_version(args.version);
1110        builder.add_header_type(args.header_type);
1111        builder.finish()
1112    }
1113
1114    #[inline]
1115    pub fn version(&self) -> MetadataVersion {
1116        // Safety:
1117        // Created from valid Table for this object
1118        // which contains a valid value in this slot
1119        unsafe {
1120            self._tab
1121                .get::<MetadataVersion>(Message::VT_VERSION, Some(MetadataVersion::V1))
1122                .unwrap()
1123        }
1124    }
1125    #[inline]
1126    pub fn header_type(&self) -> MessageHeader {
1127        // Safety:
1128        // Created from valid Table for this object
1129        // which contains a valid value in this slot
1130        unsafe {
1131            self._tab
1132                .get::<MessageHeader>(Message::VT_HEADER_TYPE, Some(MessageHeader::NONE))
1133                .unwrap()
1134        }
1135    }
1136    #[inline]
1137    pub fn header(&self) -> Option<flatbuffers::Table<'a>> {
1138        // Safety:
1139        // Created from valid Table for this object
1140        // which contains a valid value in this slot
1141        unsafe {
1142            self._tab
1143                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(
1144                    Message::VT_HEADER,
1145                    None,
1146                )
1147        }
1148    }
1149    #[inline]
1150    pub fn bodyLength(&self) -> i64 {
1151        // Safety:
1152        // Created from valid Table for this object
1153        // which contains a valid value in this slot
1154        unsafe {
1155            self._tab
1156                .get::<i64>(Message::VT_BODYLENGTH, Some(0))
1157                .unwrap()
1158        }
1159    }
1160    #[inline]
1161    pub fn custom_metadata(
1162        &self,
1163    ) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<KeyValue<'a>>>> {
1164        // Safety:
1165        // Created from valid Table for this object
1166        // which contains a valid value in this slot
1167        unsafe {
1168            self._tab.get::<flatbuffers::ForwardsUOffset<
1169                flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<KeyValue>>,
1170            >>(Message::VT_CUSTOM_METADATA, None)
1171        }
1172    }
1173    #[inline]
1174    #[allow(non_snake_case)]
1175    pub fn header_as_schema(&self) -> Option<Schema<'a>> {
1176        if self.header_type() == MessageHeader::Schema {
1177            self.header().map(|t| {
1178                // Safety:
1179                // Created from a valid Table for this object
1180                // Which contains a valid union in this slot
1181                unsafe { Schema::init_from_table(t) }
1182            })
1183        } else {
1184            None
1185        }
1186    }
1187
1188    #[inline]
1189    #[allow(non_snake_case)]
1190    pub fn header_as_dictionary_batch(&self) -> Option<DictionaryBatch<'a>> {
1191        if self.header_type() == MessageHeader::DictionaryBatch {
1192            self.header().map(|t| {
1193                // Safety:
1194                // Created from a valid Table for this object
1195                // Which contains a valid union in this slot
1196                unsafe { DictionaryBatch::init_from_table(t) }
1197            })
1198        } else {
1199            None
1200        }
1201    }
1202
1203    #[inline]
1204    #[allow(non_snake_case)]
1205    pub fn header_as_record_batch(&self) -> Option<RecordBatch<'a>> {
1206        if self.header_type() == MessageHeader::RecordBatch {
1207            self.header().map(|t| {
1208                // Safety:
1209                // Created from a valid Table for this object
1210                // Which contains a valid union in this slot
1211                unsafe { RecordBatch::init_from_table(t) }
1212            })
1213        } else {
1214            None
1215        }
1216    }
1217
1218    #[inline]
1219    #[allow(non_snake_case)]
1220    pub fn header_as_tensor(&self) -> Option<Tensor<'a>> {
1221        if self.header_type() == MessageHeader::Tensor {
1222            self.header().map(|t| {
1223                // Safety:
1224                // Created from a valid Table for this object
1225                // Which contains a valid union in this slot
1226                unsafe { Tensor::init_from_table(t) }
1227            })
1228        } else {
1229            None
1230        }
1231    }
1232
1233    #[inline]
1234    #[allow(non_snake_case)]
1235    pub fn header_as_sparse_tensor(&self) -> Option<SparseTensor<'a>> {
1236        if self.header_type() == MessageHeader::SparseTensor {
1237            self.header().map(|t| {
1238                // Safety:
1239                // Created from a valid Table for this object
1240                // Which contains a valid union in this slot
1241                unsafe { SparseTensor::init_from_table(t) }
1242            })
1243        } else {
1244            None
1245        }
1246    }
1247}
1248
1249impl flatbuffers::Verifiable for Message<'_> {
1250    #[inline]
1251    fn run_verifier(
1252        v: &mut flatbuffers::Verifier,
1253        pos: usize,
1254    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
1255        use flatbuffers::Verifiable;
1256        v.visit_table(pos)?
1257            .visit_field::<MetadataVersion>("version", Self::VT_VERSION, false)?
1258            .visit_union::<MessageHeader, _>(
1259                "header_type",
1260                Self::VT_HEADER_TYPE,
1261                "header",
1262                Self::VT_HEADER,
1263                false,
1264                |key, v, pos| match key {
1265                    MessageHeader::Schema => v
1266                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Schema>>(
1267                            "MessageHeader::Schema",
1268                            pos,
1269                        ),
1270                    MessageHeader::DictionaryBatch => v
1271                        .verify_union_variant::<flatbuffers::ForwardsUOffset<DictionaryBatch>>(
1272                            "MessageHeader::DictionaryBatch",
1273                            pos,
1274                        ),
1275                    MessageHeader::RecordBatch => v
1276                        .verify_union_variant::<flatbuffers::ForwardsUOffset<RecordBatch>>(
1277                            "MessageHeader::RecordBatch",
1278                            pos,
1279                        ),
1280                    MessageHeader::Tensor => v
1281                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Tensor>>(
1282                            "MessageHeader::Tensor",
1283                            pos,
1284                        ),
1285                    MessageHeader::SparseTensor => v
1286                        .verify_union_variant::<flatbuffers::ForwardsUOffset<SparseTensor>>(
1287                            "MessageHeader::SparseTensor",
1288                            pos,
1289                        ),
1290                    _ => Ok(()),
1291                },
1292            )?
1293            .visit_field::<i64>("bodyLength", Self::VT_BODYLENGTH, false)?
1294            .visit_field::<flatbuffers::ForwardsUOffset<
1295                flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<KeyValue>>,
1296            >>("custom_metadata", Self::VT_CUSTOM_METADATA, false)?
1297            .finish();
1298        Ok(())
1299    }
1300}
1301pub struct MessageArgs<'a> {
1302    pub version: MetadataVersion,
1303    pub header_type: MessageHeader,
1304    pub header: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
1305    pub bodyLength: i64,
1306    pub custom_metadata: Option<
1307        flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<KeyValue<'a>>>>,
1308    >,
1309}
1310impl<'a> Default for MessageArgs<'a> {
1311    #[inline]
1312    fn default() -> Self {
1313        MessageArgs {
1314            version: MetadataVersion::V1,
1315            header_type: MessageHeader::NONE,
1316            header: None,
1317            bodyLength: 0,
1318            custom_metadata: None,
1319        }
1320    }
1321}
1322
1323pub struct MessageBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
1324    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1325    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
1326}
1327impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> MessageBuilder<'a, 'b, A> {
1328    #[inline]
1329    pub fn add_version(&mut self, version: MetadataVersion) {
1330        self.fbb_
1331            .push_slot::<MetadataVersion>(Message::VT_VERSION, version, MetadataVersion::V1);
1332    }
1333    #[inline]
1334    pub fn add_header_type(&mut self, header_type: MessageHeader) {
1335        self.fbb_.push_slot::<MessageHeader>(
1336            Message::VT_HEADER_TYPE,
1337            header_type,
1338            MessageHeader::NONE,
1339        );
1340    }
1341    #[inline]
1342    pub fn add_header(&mut self, header: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
1343        self.fbb_
1344            .push_slot_always::<flatbuffers::WIPOffset<_>>(Message::VT_HEADER, header);
1345    }
1346    #[inline]
1347    pub fn add_bodyLength(&mut self, bodyLength: i64) {
1348        self.fbb_
1349            .push_slot::<i64>(Message::VT_BODYLENGTH, bodyLength, 0);
1350    }
1351    #[inline]
1352    pub fn add_custom_metadata(
1353        &mut self,
1354        custom_metadata: flatbuffers::WIPOffset<
1355            flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset<KeyValue<'b>>>,
1356        >,
1357    ) {
1358        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
1359            Message::VT_CUSTOM_METADATA,
1360            custom_metadata,
1361        );
1362    }
1363    #[inline]
1364    pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> MessageBuilder<'a, 'b, A> {
1365        let start = _fbb.start_table();
1366        MessageBuilder {
1367            fbb_: _fbb,
1368            start_: start,
1369        }
1370    }
1371    #[inline]
1372    pub fn finish(self) -> flatbuffers::WIPOffset<Message<'a>> {
1373        let o = self.fbb_.end_table(self.start_);
1374        flatbuffers::WIPOffset::new(o.value())
1375    }
1376}
1377
1378impl core::fmt::Debug for Message<'_> {
1379    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1380        let mut ds = f.debug_struct("Message");
1381        ds.field("version", &self.version());
1382        ds.field("header_type", &self.header_type());
1383        match self.header_type() {
1384            MessageHeader::Schema => {
1385                if let Some(x) = self.header_as_schema() {
1386                    ds.field("header", &x)
1387                } else {
1388                    ds.field(
1389                        "header",
1390                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1391                    )
1392                }
1393            }
1394            MessageHeader::DictionaryBatch => {
1395                if let Some(x) = self.header_as_dictionary_batch() {
1396                    ds.field("header", &x)
1397                } else {
1398                    ds.field(
1399                        "header",
1400                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1401                    )
1402                }
1403            }
1404            MessageHeader::RecordBatch => {
1405                if let Some(x) = self.header_as_record_batch() {
1406                    ds.field("header", &x)
1407                } else {
1408                    ds.field(
1409                        "header",
1410                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1411                    )
1412                }
1413            }
1414            MessageHeader::Tensor => {
1415                if let Some(x) = self.header_as_tensor() {
1416                    ds.field("header", &x)
1417                } else {
1418                    ds.field(
1419                        "header",
1420                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1421                    )
1422                }
1423            }
1424            MessageHeader::SparseTensor => {
1425                if let Some(x) = self.header_as_sparse_tensor() {
1426                    ds.field("header", &x)
1427                } else {
1428                    ds.field(
1429                        "header",
1430                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1431                    )
1432                }
1433            }
1434            _ => {
1435                let x: Option<()> = None;
1436                ds.field("header", &x)
1437            }
1438        };
1439        ds.field("bodyLength", &self.bodyLength());
1440        ds.field("custom_metadata", &self.custom_metadata());
1441        ds.finish()
1442    }
1443}
1444#[inline]
1445/// Verifies that a buffer of bytes contains a `Message`
1446/// and returns it.
1447/// Note that verification is still experimental and may not
1448/// catch every error, or be maximally performant. For the
1449/// previous, unchecked, behavior use
1450/// `root_as_message_unchecked`.
1451pub fn root_as_message(buf: &[u8]) -> Result<Message, flatbuffers::InvalidFlatbuffer> {
1452    flatbuffers::root::<Message>(buf)
1453}
1454#[inline]
1455/// Verifies that a buffer of bytes contains a size prefixed
1456/// `Message` and returns it.
1457/// Note that verification is still experimental and may not
1458/// catch every error, or be maximally performant. For the
1459/// previous, unchecked, behavior use
1460/// `size_prefixed_root_as_message_unchecked`.
1461pub fn size_prefixed_root_as_message(
1462    buf: &[u8],
1463) -> Result<Message, flatbuffers::InvalidFlatbuffer> {
1464    flatbuffers::size_prefixed_root::<Message>(buf)
1465}
1466#[inline]
1467/// Verifies, with the given options, that a buffer of bytes
1468/// contains a `Message` and returns it.
1469/// Note that verification is still experimental and may not
1470/// catch every error, or be maximally performant. For the
1471/// previous, unchecked, behavior use
1472/// `root_as_message_unchecked`.
1473pub fn root_as_message_with_opts<'b, 'o>(
1474    opts: &'o flatbuffers::VerifierOptions,
1475    buf: &'b [u8],
1476) -> Result<Message<'b>, flatbuffers::InvalidFlatbuffer> {
1477    flatbuffers::root_with_opts::<Message<'b>>(opts, buf)
1478}
1479#[inline]
1480/// Verifies, with the given verifier options, that a buffer of
1481/// bytes contains a size prefixed `Message` and returns
1482/// it. Note that verification is still experimental and may not
1483/// catch every error, or be maximally performant. For the
1484/// previous, unchecked, behavior use
1485/// `root_as_message_unchecked`.
1486pub fn size_prefixed_root_as_message_with_opts<'b, 'o>(
1487    opts: &'o flatbuffers::VerifierOptions,
1488    buf: &'b [u8],
1489) -> Result<Message<'b>, flatbuffers::InvalidFlatbuffer> {
1490    flatbuffers::size_prefixed_root_with_opts::<Message<'b>>(opts, buf)
1491}
1492#[inline]
1493/// Assumes, without verification, that a buffer of bytes contains a Message and returns it.
1494/// # Safety
1495/// Callers must trust the given bytes do indeed contain a valid `Message`.
1496pub unsafe fn root_as_message_unchecked(buf: &[u8]) -> Message {
1497    unsafe { flatbuffers::root_unchecked::<Message>(buf) }
1498}
1499#[inline]
1500/// Assumes, without verification, that a buffer of bytes contains a size prefixed Message and returns it.
1501/// # Safety
1502/// Callers must trust the given bytes do indeed contain a valid size prefixed `Message`.
1503pub unsafe fn size_prefixed_root_as_message_unchecked(buf: &[u8]) -> Message {
1504    unsafe { flatbuffers::size_prefixed_root_unchecked::<Message>(buf) }
1505}
1506#[inline]
1507pub fn finish_message_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
1508    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1509    root: flatbuffers::WIPOffset<Message<'a>>,
1510) {
1511    fbb.finish(root, None);
1512}
1513
1514#[inline]
1515pub fn finish_size_prefixed_message_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
1516    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1517    root: flatbuffers::WIPOffset<Message<'a>>,
1518) {
1519    fbb.finish_size_prefixed(root, None);
1520}