Skip to main content

arrow_ipc/gen/
Message.rs

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