1 // automatically generated by the FlatBuffers compiler, do not modify
2
3
4
5 use std::mem;
6 use std::cmp::Ordering;
7
8 extern crate flatbuffers;
9 use self::flatbuffers::{EndianScalar, Follow};
10
11 #[allow(unused_imports, dead_code)]
12 pub mod my_game {
13
14 use std::mem;
15 use std::cmp::Ordering;
16
17 extern crate flatbuffers;
18 use self::flatbuffers::{EndianScalar, Follow};
19 #[allow(unused_imports, dead_code)]
20 pub mod sample {
21
22 use std::mem;
23 use std::cmp::Ordering;
24
25 extern crate flatbuffers;
26 use self::flatbuffers::{EndianScalar, Follow};
27
28 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
29 pub const ENUM_MIN_COLOR: i8 = 0;
30 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
31 pub const ENUM_MAX_COLOR: i8 = 2;
32 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
33 #[allow(non_camel_case_types)]
34 pub const ENUM_VALUES_COLOR: [Color; 3] = [
35 Color::Red,
36 Color::Green,
37 Color::Blue,
38 ];
39
40 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
41 #[repr(transparent)]
42 pub struct Color(pub i8);
43 #[allow(non_upper_case_globals)]
44 impl Color {
45 pub const Red: Self = Self(0);
46 pub const Green: Self = Self(1);
47 pub const Blue: Self = Self(2);
48
49 pub const ENUM_MIN: i8 = 0;
50 pub const ENUM_MAX: i8 = 2;
51 pub const ENUM_VALUES: &'static [Self] = &[
52 Self::Red,
53 Self::Green,
54 Self::Blue,
55 ];
56 /// Returns the variant's name or "" if unknown.
variant_name(self) -> Option<&'static str>57 pub fn variant_name(self) -> Option<&'static str> {
58 match self {
59 Self::Red => Some("Red"),
60 Self::Green => Some("Green"),
61 Self::Blue => Some("Blue"),
62 _ => None,
63 }
64 }
65 }
66 impl std::fmt::Debug for Color {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result67 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68 if let Some(name) = self.variant_name() {
69 f.write_str(name)
70 } else {
71 f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
72 }
73 }
74 }
75 impl<'a> flatbuffers::Follow<'a> for Color {
76 type Inner = Self;
77 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner78 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
79 let b = unsafe {
80 flatbuffers::read_scalar_at::<i8>(buf, loc)
81 };
82 Self(b)
83 }
84 }
85
86 impl flatbuffers::Push for Color {
87 type Output = Color;
88 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])89 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
90 unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
91 }
92 }
93
94 impl flatbuffers::EndianScalar for Color {
95 #[inline]
to_little_endian(self) -> Self96 fn to_little_endian(self) -> Self {
97 let b = i8::to_le(self.0);
98 Self(b)
99 }
100 #[inline]
101 #[allow(clippy::wrong_self_convention)]
from_little_endian(self) -> Self102 fn from_little_endian(self) -> Self {
103 let b = i8::from_le(self.0);
104 Self(b)
105 }
106 }
107
108 impl<'a> flatbuffers::Verifiable for Color {
109 #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>110 fn run_verifier(
111 v: &mut flatbuffers::Verifier, pos: usize
112 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
113 use self::flatbuffers::Verifiable;
114 i8::run_verifier(v, pos)
115 }
116 }
117
118 impl flatbuffers::SimpleToVerifyInSlice for Color {}
119 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
120 pub const ENUM_MIN_EQUIPMENT: u8 = 0;
121 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
122 pub const ENUM_MAX_EQUIPMENT: u8 = 1;
123 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
124 #[allow(non_camel_case_types)]
125 pub const ENUM_VALUES_EQUIPMENT: [Equipment; 2] = [
126 Equipment::NONE,
127 Equipment::Weapon,
128 ];
129
130 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
131 #[repr(transparent)]
132 pub struct Equipment(pub u8);
133 #[allow(non_upper_case_globals)]
134 impl Equipment {
135 pub const NONE: Self = Self(0);
136 pub const Weapon: Self = Self(1);
137
138 pub const ENUM_MIN: u8 = 0;
139 pub const ENUM_MAX: u8 = 1;
140 pub const ENUM_VALUES: &'static [Self] = &[
141 Self::NONE,
142 Self::Weapon,
143 ];
144 /// Returns the variant's name or "" if unknown.
variant_name(self) -> Option<&'static str>145 pub fn variant_name(self) -> Option<&'static str> {
146 match self {
147 Self::NONE => Some("NONE"),
148 Self::Weapon => Some("Weapon"),
149 _ => None,
150 }
151 }
152 }
153 impl std::fmt::Debug for Equipment {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result154 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155 if let Some(name) = self.variant_name() {
156 f.write_str(name)
157 } else {
158 f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
159 }
160 }
161 }
162 impl<'a> flatbuffers::Follow<'a> for Equipment {
163 type Inner = Self;
164 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner165 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
166 let b = unsafe {
167 flatbuffers::read_scalar_at::<u8>(buf, loc)
168 };
169 Self(b)
170 }
171 }
172
173 impl flatbuffers::Push for Equipment {
174 type Output = Equipment;
175 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])176 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
177 unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
178 }
179 }
180
181 impl flatbuffers::EndianScalar for Equipment {
182 #[inline]
to_little_endian(self) -> Self183 fn to_little_endian(self) -> Self {
184 let b = u8::to_le(self.0);
185 Self(b)
186 }
187 #[inline]
188 #[allow(clippy::wrong_self_convention)]
from_little_endian(self) -> Self189 fn from_little_endian(self) -> Self {
190 let b = u8::from_le(self.0);
191 Self(b)
192 }
193 }
194
195 impl<'a> flatbuffers::Verifiable for Equipment {
196 #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>197 fn run_verifier(
198 v: &mut flatbuffers::Verifier, pos: usize
199 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
200 use self::flatbuffers::Verifiable;
201 u8::run_verifier(v, pos)
202 }
203 }
204
205 impl flatbuffers::SimpleToVerifyInSlice for Equipment {}
206 pub struct EquipmentUnionTableOffset {}
207
208 #[non_exhaustive]
209 #[derive(Debug, Clone, PartialEq)]
210 pub enum EquipmentT {
211 NONE,
212 Weapon(Box<WeaponT>),
213 }
214 impl Default for EquipmentT {
default() -> Self215 fn default() -> Self {
216 Self::NONE
217 }
218 }
219 impl EquipmentT {
equipment_type(&self) -> Equipment220 pub fn equipment_type(&self) -> Equipment {
221 match self {
222 Self::NONE => Equipment::NONE,
223 Self::Weapon(_) => Equipment::Weapon,
224 }
225 }
pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>226 pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
227 match self {
228 Self::NONE => None,
229 Self::Weapon(v) => Some(v.pack(fbb).as_union_value()),
230 }
231 }
232 /// If the union variant matches, return the owned WeaponT, setting the union to NONE.
take_weapon(&mut self) -> Option<Box<WeaponT>>233 pub fn take_weapon(&mut self) -> Option<Box<WeaponT>> {
234 if let Self::Weapon(_) = self {
235 let v = std::mem::replace(self, Self::NONE);
236 if let Self::Weapon(w) = v {
237 Some(w)
238 } else {
239 unreachable!()
240 }
241 } else {
242 None
243 }
244 }
245 /// If the union variant matches, return a reference to the WeaponT.
as_weapon(&self) -> Option<&WeaponT>246 pub fn as_weapon(&self) -> Option<&WeaponT> {
247 if let Self::Weapon(v) = self { Some(v.as_ref()) } else { None }
248 }
249 /// If the union variant matches, return a mutable reference to the WeaponT.
as_weapon_mut(&mut self) -> Option<&mut WeaponT>250 pub fn as_weapon_mut(&mut self) -> Option<&mut WeaponT> {
251 if let Self::Weapon(v) = self { Some(v.as_mut()) } else { None }
252 }
253 }
254 // struct Vec3, aligned to 4
255 #[repr(transparent)]
256 #[derive(Clone, Copy, PartialEq)]
257 pub struct Vec3(pub [u8; 12]);
258 impl Default for Vec3 {
default() -> Self259 fn default() -> Self {
260 Self([0; 12])
261 }
262 }
263 impl std::fmt::Debug for Vec3 {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result264 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
265 f.debug_struct("Vec3")
266 .field("x", &self.x())
267 .field("y", &self.y())
268 .field("z", &self.z())
269 .finish()
270 }
271 }
272
273 impl flatbuffers::SimpleToVerifyInSlice for Vec3 {}
274 impl flatbuffers::SafeSliceAccess for Vec3 {}
275 impl<'a> flatbuffers::Follow<'a> for Vec3 {
276 type Inner = &'a Vec3;
277 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner278 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
279 <&'a Vec3>::follow(buf, loc)
280 }
281 }
282 impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
283 type Inner = &'a Vec3;
284 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner285 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
286 flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
287 }
288 }
289 impl<'b> flatbuffers::Push for Vec3 {
290 type Output = Vec3;
291 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])292 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
293 let src = unsafe {
294 ::std::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
295 };
296 dst.copy_from_slice(src);
297 }
298 }
299 impl<'b> flatbuffers::Push for &'b Vec3 {
300 type Output = Vec3;
301
302 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])303 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
304 let src = unsafe {
305 ::std::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
306 };
307 dst.copy_from_slice(src);
308 }
309 }
310
311 impl<'a> flatbuffers::Verifiable for Vec3 {
312 #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>313 fn run_verifier(
314 v: &mut flatbuffers::Verifier, pos: usize
315 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
316 use self::flatbuffers::Verifiable;
317 v.in_buffer::<Self>(pos)
318 }
319 }
320 impl<'a> Vec3 {
321 #[allow(clippy::too_many_arguments)]
new( x: f32, y: f32, z: f32, ) -> Self322 pub fn new(
323 x: f32,
324 y: f32,
325 z: f32,
326 ) -> Self {
327 let mut s = Self([0; 12]);
328 s.set_x(x);
329 s.set_y(y);
330 s.set_z(z);
331 s
332 }
333
x(&self) -> f32334 pub fn x(&self) -> f32 {
335 let mut mem = core::mem::MaybeUninit::<f32>::uninit();
336 unsafe {
337 core::ptr::copy_nonoverlapping(
338 self.0[0..].as_ptr(),
339 mem.as_mut_ptr() as *mut u8,
340 core::mem::size_of::<f32>(),
341 );
342 mem.assume_init()
343 }.from_little_endian()
344 }
345
set_x(&mut self, x: f32)346 pub fn set_x(&mut self, x: f32) {
347 let x_le = x.to_little_endian();
348 unsafe {
349 core::ptr::copy_nonoverlapping(
350 &x_le as *const f32 as *const u8,
351 self.0[0..].as_mut_ptr(),
352 core::mem::size_of::<f32>(),
353 );
354 }
355 }
356
y(&self) -> f32357 pub fn y(&self) -> f32 {
358 let mut mem = core::mem::MaybeUninit::<f32>::uninit();
359 unsafe {
360 core::ptr::copy_nonoverlapping(
361 self.0[4..].as_ptr(),
362 mem.as_mut_ptr() as *mut u8,
363 core::mem::size_of::<f32>(),
364 );
365 mem.assume_init()
366 }.from_little_endian()
367 }
368
set_y(&mut self, x: f32)369 pub fn set_y(&mut self, x: f32) {
370 let x_le = x.to_little_endian();
371 unsafe {
372 core::ptr::copy_nonoverlapping(
373 &x_le as *const f32 as *const u8,
374 self.0[4..].as_mut_ptr(),
375 core::mem::size_of::<f32>(),
376 );
377 }
378 }
379
z(&self) -> f32380 pub fn z(&self) -> f32 {
381 let mut mem = core::mem::MaybeUninit::<f32>::uninit();
382 unsafe {
383 core::ptr::copy_nonoverlapping(
384 self.0[8..].as_ptr(),
385 mem.as_mut_ptr() as *mut u8,
386 core::mem::size_of::<f32>(),
387 );
388 mem.assume_init()
389 }.from_little_endian()
390 }
391
set_z(&mut self, x: f32)392 pub fn set_z(&mut self, x: f32) {
393 let x_le = x.to_little_endian();
394 unsafe {
395 core::ptr::copy_nonoverlapping(
396 &x_le as *const f32 as *const u8,
397 self.0[8..].as_mut_ptr(),
398 core::mem::size_of::<f32>(),
399 );
400 }
401 }
402
unpack(&self) -> Vec3T403 pub fn unpack(&self) -> Vec3T {
404 Vec3T {
405 x: self.x(),
406 y: self.y(),
407 z: self.z(),
408 }
409 }
410 }
411
412 #[derive(Debug, Clone, PartialEq, Default)]
413 pub struct Vec3T {
414 pub x: f32,
415 pub y: f32,
416 pub z: f32,
417 }
418 impl Vec3T {
pack(&self) -> Vec3419 pub fn pack(&self) -> Vec3 {
420 Vec3::new(
421 self.x,
422 self.y,
423 self.z,
424 )
425 }
426 }
427
428 pub enum MonsterOffset {}
429 #[derive(Copy, Clone, PartialEq)]
430
431 pub struct Monster<'a> {
432 pub _tab: flatbuffers::Table<'a>,
433 }
434
435 impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
436 type Inner = Monster<'a>;
437 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner438 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
439 Self { _tab: flatbuffers::Table { buf, loc } }
440 }
441 }
442
443 impl<'a> Monster<'a> {
444 #[inline]
init_from_table(table: flatbuffers::Table<'a>) -> Self445 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
446 Monster { _tab: table }
447 }
448 #[allow(unused_mut)]
create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, args: &'args MonsterArgs<'args>) -> flatbuffers::WIPOffset<Monster<'bldr>>449 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
450 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
451 args: &'args MonsterArgs<'args>) -> flatbuffers::WIPOffset<Monster<'bldr>> {
452 let mut builder = MonsterBuilder::new(_fbb);
453 if let Some(x) = args.path { builder.add_path(x); }
454 if let Some(x) = args.equipped { builder.add_equipped(x); }
455 if let Some(x) = args.weapons { builder.add_weapons(x); }
456 if let Some(x) = args.inventory { builder.add_inventory(x); }
457 if let Some(x) = args.name { builder.add_name(x); }
458 if let Some(x) = args.pos { builder.add_pos(x); }
459 builder.add_hp(args.hp);
460 builder.add_mana(args.mana);
461 builder.add_equipped_type(args.equipped_type);
462 builder.add_color(args.color);
463 builder.finish()
464 }
465
unpack(&self) -> MonsterT466 pub fn unpack(&self) -> MonsterT {
467 let pos = self.pos().map(|x| {
468 x.unpack()
469 });
470 let mana = self.mana();
471 let hp = self.hp();
472 let name = self.name().map(|x| {
473 x.to_string()
474 });
475 let inventory = self.inventory().map(|x| {
476 x.to_vec()
477 });
478 let color = self.color();
479 let weapons = self.weapons().map(|x| {
480 x.iter().map(|t| t.unpack()).collect()
481 });
482 let equipped = match self.equipped_type() {
483 Equipment::NONE => EquipmentT::NONE,
484 Equipment::Weapon => EquipmentT::Weapon(Box::new(
485 self.equipped_as_weapon()
486 .expect("Invalid union table, expected `Equipment::Weapon`.")
487 .unpack()
488 )),
489 _ => EquipmentT::NONE,
490 };
491 let path = self.path().map(|x| {
492 x.iter().map(|t| t.unpack()).collect()
493 });
494 MonsterT {
495 pos,
496 mana,
497 hp,
498 name,
499 inventory,
500 color,
501 weapons,
502 equipped,
503 path,
504 }
505 }
506 pub const VT_POS: flatbuffers::VOffsetT = 4;
507 pub const VT_MANA: flatbuffers::VOffsetT = 6;
508 pub const VT_HP: flatbuffers::VOffsetT = 8;
509 pub const VT_NAME: flatbuffers::VOffsetT = 10;
510 pub const VT_INVENTORY: flatbuffers::VOffsetT = 14;
511 pub const VT_COLOR: flatbuffers::VOffsetT = 16;
512 pub const VT_WEAPONS: flatbuffers::VOffsetT = 18;
513 pub const VT_EQUIPPED_TYPE: flatbuffers::VOffsetT = 20;
514 pub const VT_EQUIPPED: flatbuffers::VOffsetT = 22;
515 pub const VT_PATH: flatbuffers::VOffsetT = 24;
516
517 #[inline]
pos(&self) -> Option<&'a Vec3>518 pub fn pos(&self) -> Option<&'a Vec3> {
519 self._tab.get::<Vec3>(Monster::VT_POS, None)
520 }
521 #[inline]
mana(&self) -> i16522 pub fn mana(&self) -> i16 {
523 self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
524 }
525 #[inline]
hp(&self) -> i16526 pub fn hp(&self) -> i16 {
527 self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
528 }
529 #[inline]
name(&self) -> Option<&'a str>530 pub fn name(&self) -> Option<&'a str> {
531 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)
532 }
533 #[inline]
inventory(&self) -> Option<&'a [u8]>534 pub fn inventory(&self) -> Option<&'a [u8]> {
535 self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
536 }
537 #[inline]
color(&self) -> Color538 pub fn color(&self) -> Color {
539 self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
540 }
541 #[inline]
weapons(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon<'a>>>>542 pub fn weapons(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon<'a>>>> {
543 self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon>>>>(Monster::VT_WEAPONS, None)
544 }
545 #[inline]
equipped_type(&self) -> Equipment546 pub fn equipped_type(&self) -> Equipment {
547 self._tab.get::<Equipment>(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()
548 }
549 #[inline]
equipped(&self) -> Option<flatbuffers::Table<'a>>550 pub fn equipped(&self) -> Option<flatbuffers::Table<'a>> {
551 self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_EQUIPPED, None)
552 }
553 #[inline]
path(&self) -> Option<&'a [Vec3]>554 pub fn path(&self) -> Option<&'a [Vec3]> {
555 self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Vec3>>>(Monster::VT_PATH, None).map(|v| v.safe_slice())
556 }
557 #[inline]
558 #[allow(non_snake_case)]
equipped_as_weapon(&self) -> Option<Weapon<'a>>559 pub fn equipped_as_weapon(&self) -> Option<Weapon<'a>> {
560 if self.equipped_type() == Equipment::Weapon {
561 self.equipped().map(Weapon::init_from_table)
562 } else {
563 None
564 }
565 }
566
567 }
568
569 impl flatbuffers::Verifiable for Monster<'_> {
570 #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>571 fn run_verifier(
572 v: &mut flatbuffers::Verifier, pos: usize
573 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
574 use self::flatbuffers::Verifiable;
575 v.visit_table(pos)?
576 .visit_field::<Vec3>(&"pos", Self::VT_POS, false)?
577 .visit_field::<i16>(&"mana", Self::VT_MANA, false)?
578 .visit_field::<i16>(&"hp", Self::VT_HP, false)?
579 .visit_field::<flatbuffers::ForwardsUOffset<&str>>(&"name", Self::VT_NAME, false)?
580 .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>(&"inventory", Self::VT_INVENTORY, false)?
581 .visit_field::<Color>(&"color", Self::VT_COLOR, false)?
582 .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<Weapon>>>>(&"weapons", Self::VT_WEAPONS, false)?
583 .visit_union::<Equipment, _>(&"equipped_type", Self::VT_EQUIPPED_TYPE, &"equipped", Self::VT_EQUIPPED, false, |key, v, pos| {
584 match key {
585 Equipment::Weapon => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Weapon>>("Equipment::Weapon", pos),
586 _ => Ok(()),
587 }
588 })?
589 .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Vec3>>>(&"path", Self::VT_PATH, false)?
590 .finish();
591 Ok(())
592 }
593 }
594 pub struct MonsterArgs<'a> {
595 pub pos: Option<&'a Vec3>,
596 pub mana: i16,
597 pub hp: i16,
598 pub name: Option<flatbuffers::WIPOffset<&'a str>>,
599 pub inventory: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, u8>>>,
600 pub color: Color,
601 pub weapons: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon<'a>>>>>,
602 pub equipped_type: Equipment,
603 pub equipped: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
604 pub path: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Vec3>>>,
605 }
606 impl<'a> Default for MonsterArgs<'a> {
607 #[inline]
default() -> Self608 fn default() -> Self {
609 MonsterArgs {
610 pos: None,
611 mana: 150,
612 hp: 100,
613 name: None,
614 inventory: None,
615 color: Color::Blue,
616 weapons: None,
617 equipped_type: Equipment::NONE,
618 equipped: None,
619 path: None,
620 }
621 }
622 }
623 pub struct MonsterBuilder<'a: 'b, 'b> {
624 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
625 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
626 }
627 impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> {
628 #[inline]
add_pos(&mut self, pos: &Vec3)629 pub fn add_pos(&mut self, pos: &Vec3) {
630 self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos);
631 }
632 #[inline]
add_mana(&mut self, mana: i16)633 pub fn add_mana(&mut self, mana: i16) {
634 self.fbb_.push_slot::<i16>(Monster::VT_MANA, mana, 150);
635 }
636 #[inline]
add_hp(&mut self, hp: i16)637 pub fn add_hp(&mut self, hp: i16) {
638 self.fbb_.push_slot::<i16>(Monster::VT_HP, hp, 100);
639 }
640 #[inline]
add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>)641 pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
642 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_NAME, name);
643 }
644 #[inline]
add_inventory(&mut self, inventory: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>)645 pub fn add_inventory(&mut self, inventory: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>) {
646 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_INVENTORY, inventory);
647 }
648 #[inline]
add_color(&mut self, color: Color)649 pub fn add_color(&mut self, color: Color) {
650 self.fbb_.push_slot::<Color>(Monster::VT_COLOR, color, Color::Blue);
651 }
652 #[inline]
add_weapons(&mut self, weapons: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Weapon<'b >>>>)653 pub fn add_weapons(&mut self, weapons: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Weapon<'b >>>>) {
654 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_WEAPONS, weapons);
655 }
656 #[inline]
add_equipped_type(&mut self, equipped_type: Equipment)657 pub fn add_equipped_type(&mut self, equipped_type: Equipment) {
658 self.fbb_.push_slot::<Equipment>(Monster::VT_EQUIPPED_TYPE, equipped_type, Equipment::NONE);
659 }
660 #[inline]
add_equipped(&mut self, equipped: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>)661 pub fn add_equipped(&mut self, equipped: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
662 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_EQUIPPED, equipped);
663 }
664 #[inline]
add_path(&mut self, path: flatbuffers::WIPOffset<flatbuffers::Vector<'b , Vec3>>)665 pub fn add_path(&mut self, path: flatbuffers::WIPOffset<flatbuffers::Vector<'b , Vec3>>) {
666 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_PATH, path);
667 }
668 #[inline]
new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> MonsterBuilder<'a, 'b>669 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> MonsterBuilder<'a, 'b> {
670 let start = _fbb.start_table();
671 MonsterBuilder {
672 fbb_: _fbb,
673 start_: start,
674 }
675 }
676 #[inline]
finish(self) -> flatbuffers::WIPOffset<Monster<'a>>677 pub fn finish(self) -> flatbuffers::WIPOffset<Monster<'a>> {
678 let o = self.fbb_.end_table(self.start_);
679 flatbuffers::WIPOffset::new(o.value())
680 }
681 }
682
683 impl std::fmt::Debug for Monster<'_> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result684 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
685 let mut ds = f.debug_struct("Monster");
686 ds.field("pos", &self.pos());
687 ds.field("mana", &self.mana());
688 ds.field("hp", &self.hp());
689 ds.field("name", &self.name());
690 ds.field("inventory", &self.inventory());
691 ds.field("color", &self.color());
692 ds.field("weapons", &self.weapons());
693 ds.field("equipped_type", &self.equipped_type());
694 match self.equipped_type() {
695 Equipment::Weapon => {
696 if let Some(x) = self.equipped_as_weapon() {
697 ds.field("equipped", &x)
698 } else {
699 ds.field("equipped", &"InvalidFlatbuffer: Union discriminant does not match value.")
700 }
701 },
702 _ => {
703 let x: Option<()> = None;
704 ds.field("equipped", &x)
705 },
706 };
707 ds.field("path", &self.path());
708 ds.finish()
709 }
710 }
711 #[non_exhaustive]
712 #[derive(Debug, Clone, PartialEq)]
713 pub struct MonsterT {
714 pub pos: Option<Vec3T>,
715 pub mana: i16,
716 pub hp: i16,
717 pub name: Option<String>,
718 pub inventory: Option<Vec<u8>>,
719 pub color: Color,
720 pub weapons: Option<Vec<WeaponT>>,
721 pub equipped: EquipmentT,
722 pub path: Option<Vec<Vec3T>>,
723 }
724 impl Default for MonsterT {
default() -> Self725 fn default() -> Self {
726 Self {
727 pos: None,
728 mana: 150,
729 hp: 100,
730 name: None,
731 inventory: None,
732 color: Color::Blue,
733 weapons: None,
734 equipped: EquipmentT::NONE,
735 path: None,
736 }
737 }
738 }
739 impl MonsterT {
pack<'b>( &self, _fbb: &mut flatbuffers::FlatBufferBuilder<'b> ) -> flatbuffers::WIPOffset<Monster<'b>>740 pub fn pack<'b>(
741 &self,
742 _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
743 ) -> flatbuffers::WIPOffset<Monster<'b>> {
744 let pos_tmp = self.pos.as_ref().map(|x| x.pack());
745 let pos = pos_tmp.as_ref();
746 let mana = self.mana;
747 let hp = self.hp;
748 let name = self.name.as_ref().map(|x|{
749 _fbb.create_string(x)
750 });
751 let inventory = self.inventory.as_ref().map(|x|{
752 _fbb.create_vector(x)
753 });
754 let color = self.color;
755 let weapons = self.weapons.as_ref().map(|x|{
756 let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
757 });
758 let equipped_type = self.equipped.equipment_type();
759 let equipped = self.equipped.pack(_fbb);
760 let path = self.path.as_ref().map(|x|{
761 let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
762 });
763 Monster::create(_fbb, &MonsterArgs{
764 pos,
765 mana,
766 hp,
767 name,
768 inventory,
769 color,
770 weapons,
771 equipped_type,
772 equipped,
773 path,
774 })
775 }
776 }
777 pub enum WeaponOffset {}
778 #[derive(Copy, Clone, PartialEq)]
779
780 pub struct Weapon<'a> {
781 pub _tab: flatbuffers::Table<'a>,
782 }
783
784 impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
785 type Inner = Weapon<'a>;
786 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner787 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
788 Self { _tab: flatbuffers::Table { buf, loc } }
789 }
790 }
791
792 impl<'a> Weapon<'a> {
793 #[inline]
init_from_table(table: flatbuffers::Table<'a>) -> Self794 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
795 Weapon { _tab: table }
796 }
797 #[allow(unused_mut)]
create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, args: &'args WeaponArgs<'args>) -> flatbuffers::WIPOffset<Weapon<'bldr>>798 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
799 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
800 args: &'args WeaponArgs<'args>) -> flatbuffers::WIPOffset<Weapon<'bldr>> {
801 let mut builder = WeaponBuilder::new(_fbb);
802 if let Some(x) = args.name { builder.add_name(x); }
803 builder.add_damage(args.damage);
804 builder.finish()
805 }
806
unpack(&self) -> WeaponT807 pub fn unpack(&self) -> WeaponT {
808 let name = self.name().map(|x| {
809 x.to_string()
810 });
811 let damage = self.damage();
812 WeaponT {
813 name,
814 damage,
815 }
816 }
817 pub const VT_NAME: flatbuffers::VOffsetT = 4;
818 pub const VT_DAMAGE: flatbuffers::VOffsetT = 6;
819
820 #[inline]
name(&self) -> Option<&'a str>821 pub fn name(&self) -> Option<&'a str> {
822 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)
823 }
824 #[inline]
damage(&self) -> i16825 pub fn damage(&self) -> i16 {
826 self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()
827 }
828 }
829
830 impl flatbuffers::Verifiable for Weapon<'_> {
831 #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>832 fn run_verifier(
833 v: &mut flatbuffers::Verifier, pos: usize
834 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
835 use self::flatbuffers::Verifiable;
836 v.visit_table(pos)?
837 .visit_field::<flatbuffers::ForwardsUOffset<&str>>(&"name", Self::VT_NAME, false)?
838 .visit_field::<i16>(&"damage", Self::VT_DAMAGE, false)?
839 .finish();
840 Ok(())
841 }
842 }
843 pub struct WeaponArgs<'a> {
844 pub name: Option<flatbuffers::WIPOffset<&'a str>>,
845 pub damage: i16,
846 }
847 impl<'a> Default for WeaponArgs<'a> {
848 #[inline]
default() -> Self849 fn default() -> Self {
850 WeaponArgs {
851 name: None,
852 damage: 0,
853 }
854 }
855 }
856 pub struct WeaponBuilder<'a: 'b, 'b> {
857 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
858 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
859 }
860 impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> {
861 #[inline]
add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>)862 pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
863 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Weapon::VT_NAME, name);
864 }
865 #[inline]
add_damage(&mut self, damage: i16)866 pub fn add_damage(&mut self, damage: i16) {
867 self.fbb_.push_slot::<i16>(Weapon::VT_DAMAGE, damage, 0);
868 }
869 #[inline]
new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeaponBuilder<'a, 'b>870 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeaponBuilder<'a, 'b> {
871 let start = _fbb.start_table();
872 WeaponBuilder {
873 fbb_: _fbb,
874 start_: start,
875 }
876 }
877 #[inline]
finish(self) -> flatbuffers::WIPOffset<Weapon<'a>>878 pub fn finish(self) -> flatbuffers::WIPOffset<Weapon<'a>> {
879 let o = self.fbb_.end_table(self.start_);
880 flatbuffers::WIPOffset::new(o.value())
881 }
882 }
883
884 impl std::fmt::Debug for Weapon<'_> {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result885 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
886 let mut ds = f.debug_struct("Weapon");
887 ds.field("name", &self.name());
888 ds.field("damage", &self.damage());
889 ds.finish()
890 }
891 }
892 #[non_exhaustive]
893 #[derive(Debug, Clone, PartialEq)]
894 pub struct WeaponT {
895 pub name: Option<String>,
896 pub damage: i16,
897 }
898 impl Default for WeaponT {
default() -> Self899 fn default() -> Self {
900 Self {
901 name: None,
902 damage: 0,
903 }
904 }
905 }
906 impl WeaponT {
pack<'b>( &self, _fbb: &mut flatbuffers::FlatBufferBuilder<'b> ) -> flatbuffers::WIPOffset<Weapon<'b>>907 pub fn pack<'b>(
908 &self,
909 _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
910 ) -> flatbuffers::WIPOffset<Weapon<'b>> {
911 let name = self.name.as_ref().map(|x|{
912 _fbb.create_string(x)
913 });
914 let damage = self.damage;
915 Weapon::create(_fbb, &WeaponArgs{
916 name,
917 damage,
918 })
919 }
920 }
921 #[inline]
922 #[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a>923 pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
924 unsafe { flatbuffers::root_unchecked::<Monster<'a>>(buf) }
925 }
926
927 #[inline]
928 #[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a>929 pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
930 unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster<'a>>(buf) }
931 }
932
933 #[inline]
934 /// Verifies that a buffer of bytes contains a `Monster`
935 /// and returns it.
936 /// Note that verification is still experimental and may not
937 /// catch every error, or be maximally performant. For the
938 /// previous, unchecked, behavior use
939 /// `root_as_monster_unchecked`.
root_as_monster(buf: &[u8]) -> Result<Monster, flatbuffers::InvalidFlatbuffer>940 pub fn root_as_monster(buf: &[u8]) -> Result<Monster, flatbuffers::InvalidFlatbuffer> {
941 flatbuffers::root::<Monster>(buf)
942 }
943 #[inline]
944 /// Verifies that a buffer of bytes contains a size prefixed
945 /// `Monster` and returns it.
946 /// Note that verification is still experimental and may not
947 /// catch every error, or be maximally performant. For the
948 /// previous, unchecked, behavior use
949 /// `size_prefixed_root_as_monster_unchecked`.
size_prefixed_root_as_monster(buf: &[u8]) -> Result<Monster, flatbuffers::InvalidFlatbuffer>950 pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result<Monster, flatbuffers::InvalidFlatbuffer> {
951 flatbuffers::size_prefixed_root::<Monster>(buf)
952 }
953 #[inline]
954 /// Verifies, with the given options, that a buffer of bytes
955 /// contains a `Monster` and returns it.
956 /// Note that verification is still experimental and may not
957 /// catch every error, or be maximally performant. For the
958 /// previous, unchecked, behavior use
959 /// `root_as_monster_unchecked`.
root_as_monster_with_opts<'b, 'o>( opts: &'o flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result<Monster<'b>, flatbuffers::InvalidFlatbuffer>960 pub fn root_as_monster_with_opts<'b, 'o>(
961 opts: &'o flatbuffers::VerifierOptions,
962 buf: &'b [u8],
963 ) -> Result<Monster<'b>, flatbuffers::InvalidFlatbuffer> {
964 flatbuffers::root_with_opts::<Monster<'b>>(opts, buf)
965 }
966 #[inline]
967 /// Verifies, with the given verifier options, that a buffer of
968 /// bytes contains a size prefixed `Monster` and returns
969 /// it. Note that verification is still experimental and may not
970 /// catch every error, or be maximally performant. For the
971 /// previous, unchecked, behavior use
972 /// `root_as_monster_unchecked`.
size_prefixed_root_as_monster_with_opts<'b, 'o>( opts: &'o flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result<Monster<'b>, flatbuffers::InvalidFlatbuffer>973 pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>(
974 opts: &'o flatbuffers::VerifierOptions,
975 buf: &'b [u8],
976 ) -> Result<Monster<'b>, flatbuffers::InvalidFlatbuffer> {
977 flatbuffers::size_prefixed_root_with_opts::<Monster<'b>>(opts, buf)
978 }
979 #[inline]
980 /// Assumes, without verification, that a buffer of bytes contains a Monster and returns it.
981 /// # Safety
982 /// Callers must trust the given bytes do indeed contain a valid `Monster`.
root_as_monster_unchecked(buf: &[u8]) -> Monster983 pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster {
984 flatbuffers::root_unchecked::<Monster>(buf)
985 }
986 #[inline]
987 /// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it.
988 /// # Safety
989 /// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`.
size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster990 pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster {
991 flatbuffers::size_prefixed_root_unchecked::<Monster>(buf)
992 }
993 #[inline]
finish_monster_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Monster<'a>>)994 pub fn finish_monster_buffer<'a, 'b>(
995 fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
996 root: flatbuffers::WIPOffset<Monster<'a>>) {
997 fbb.finish(root, None);
998 }
999
1000 #[inline]
finish_size_prefixed_monster_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Monster<'a>>)1001 pub fn finish_size_prefixed_monster_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Monster<'a>>) {
1002 fbb.finish_size_prefixed(root, None);
1003 }
1004 } // pub mod Sample
1005 } // pub mod MyGame
1006
1007