Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 1 | // automatically generated by the FlatBuffers compiler, do not modify |
| 2 | // @generated |
| 3 | extern crate alloc; |
| 4 | extern crate flatbuffers; |
| 5 | use alloc::boxed::Box; |
| 6 | use alloc::string::{String, ToString}; |
| 7 | use alloc::vec::Vec; |
| 8 | use core::mem; |
| 9 | use core::cmp::Ordering; |
| 10 | use self::flatbuffers::{EndianScalar, Follow}; |
| 11 | use super::*; |
| 12 | #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] |
| 13 | pub const ENUM_MIN_ANY: u8 = 0; |
| 14 | #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] |
| 15 | pub const ENUM_MAX_ANY: u8 = 2; |
| 16 | #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] |
| 17 | #[allow(non_camel_case_types)] |
| 18 | pub const ENUM_VALUES_ANY: [Any; 3] = [ |
| 19 | Any::NONE, |
| 20 | Any::Game, |
| 21 | Any::Annotations, |
| 22 | ]; |
| 23 | |
| 24 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] |
| 25 | #[repr(transparent)] |
| 26 | pub(crate) struct Any(pub u8); |
| 27 | #[allow(non_upper_case_globals)] |
| 28 | impl Any { |
| 29 | pub const NONE: Self = Self(0); |
| 30 | pub const Game: Self = Self(1); |
| 31 | pub const Annotations: Self = Self(2); |
| 32 | |
| 33 | pub const ENUM_MIN: u8 = 0; |
| 34 | pub const ENUM_MAX: u8 = 2; |
| 35 | pub const ENUM_VALUES: &'static [Self] = &[ |
| 36 | Self::NONE, |
| 37 | Self::Game, |
| 38 | Self::Annotations, |
| 39 | ]; |
| 40 | /// Returns the variant's name or "" if unknown. |
| 41 | pub fn variant_name(self) -> Option<&'static str> { |
| 42 | match self { |
| 43 | Self::NONE => Some("NONE"), |
| 44 | Self::Game => Some("Game"), |
| 45 | Self::Annotations => Some("Annotations"), |
| 46 | _ => None, |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | impl core::fmt::Debug for Any { |
| 51 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 52 | if let Some(name) = self.variant_name() { |
| 53 | f.write_str(name) |
| 54 | } else { |
| 55 | f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0)) |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | impl<'a> flatbuffers::Follow<'a> for Any { |
| 60 | type Inner = Self; |
| 61 | #[inline] |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 62 | unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { |
| 63 | let b = flatbuffers::read_scalar_at::<u8>(buf, loc); |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 64 | Self(b) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | impl flatbuffers::Push for Any { |
| 69 | type Output = Any; |
| 70 | #[inline] |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 71 | unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { |
| 72 | flatbuffers::emplace_scalar::<u8>(dst, self.0); |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | impl flatbuffers::EndianScalar for Any { |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 77 | type Scalar = u8; |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 78 | #[inline] |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 79 | fn to_little_endian(self) -> u8 { |
| 80 | self.0.to_le() |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 81 | } |
| 82 | #[inline] |
| 83 | #[allow(clippy::wrong_self_convention)] |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 84 | fn from_little_endian(v: u8) -> Self { |
| 85 | let b = u8::from_le(v); |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 86 | Self(b) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | impl<'a> flatbuffers::Verifiable for Any { |
| 91 | #[inline] |
| 92 | fn run_verifier( |
| 93 | v: &mut flatbuffers::Verifier, pos: usize |
| 94 | ) -> Result<(), flatbuffers::InvalidFlatbuffer> { |
| 95 | use self::flatbuffers::Verifiable; |
| 96 | u8::run_verifier(v, pos) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | impl flatbuffers::SimpleToVerifyInSlice for Any {} |
| 101 | pub(crate) struct AnyUnionTableOffset {} |
| 102 | |
| 103 | #[allow(clippy::upper_case_acronyms)] |
| 104 | #[non_exhaustive] |
| 105 | #[derive(Debug, Clone, PartialEq)] |
| 106 | pub(crate) enum AnyT { |
| 107 | NONE, |
| 108 | Game(Box<GameT>), |
| 109 | Annotations(Box<AnnotationsT>), |
| 110 | } |
| 111 | impl Default for AnyT { |
| 112 | fn default() -> Self { |
| 113 | Self::NONE |
| 114 | } |
| 115 | } |
| 116 | impl AnyT { |
| 117 | pub fn any_type(&self) -> Any { |
| 118 | match self { |
| 119 | Self::NONE => Any::NONE, |
| 120 | Self::Game(_) => Any::Game, |
| 121 | Self::Annotations(_) => Any::Annotations, |
| 122 | } |
| 123 | } |
| 124 | pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> { |
| 125 | match self { |
| 126 | Self::NONE => None, |
| 127 | Self::Game(v) => Some(v.pack(fbb).as_union_value()), |
| 128 | Self::Annotations(v) => Some(v.pack(fbb).as_union_value()), |
| 129 | } |
| 130 | } |
| 131 | /// If the union variant matches, return the owned GameT, setting the union to NONE. |
| 132 | pub fn take_game(&mut self) -> Option<Box<GameT>> { |
| 133 | if let Self::Game(_) = self { |
| 134 | let v = core::mem::replace(self, Self::NONE); |
| 135 | if let Self::Game(w) = v { |
| 136 | Some(w) |
| 137 | } else { |
| 138 | unreachable!() |
| 139 | } |
| 140 | } else { |
| 141 | None |
| 142 | } |
| 143 | } |
| 144 | /// If the union variant matches, return a reference to the GameT. |
| 145 | pub fn as_game(&self) -> Option<&GameT> { |
| 146 | if let Self::Game(v) = self { Some(v.as_ref()) } else { None } |
| 147 | } |
| 148 | /// If the union variant matches, return a mutable reference to the GameT. |
| 149 | pub fn as_game_mut(&mut self) -> Option<&mut GameT> { |
| 150 | if let Self::Game(v) = self { Some(v.as_mut()) } else { None } |
| 151 | } |
| 152 | /// If the union variant matches, return the owned AnnotationsT, setting the union to NONE. |
| 153 | pub fn take_annotations(&mut self) -> Option<Box<AnnotationsT>> { |
| 154 | if let Self::Annotations(_) = self { |
| 155 | let v = core::mem::replace(self, Self::NONE); |
| 156 | if let Self::Annotations(w) = v { |
| 157 | Some(w) |
| 158 | } else { |
| 159 | unreachable!() |
| 160 | } |
| 161 | } else { |
| 162 | None |
| 163 | } |
| 164 | } |
| 165 | /// If the union variant matches, return a reference to the AnnotationsT. |
| 166 | pub fn as_annotations(&self) -> Option<&AnnotationsT> { |
| 167 | if let Self::Annotations(v) = self { Some(v.as_ref()) } else { None } |
| 168 | } |
| 169 | /// If the union variant matches, return a mutable reference to the AnnotationsT. |
| 170 | pub fn as_annotations_mut(&mut self) -> Option<&mut AnnotationsT> { |
| 171 | if let Self::Annotations(v) = self { Some(v.as_mut()) } else { None } |
| 172 | } |
| 173 | } |