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 pub enum WeaponOffset {} 13 #[derive(Copy, Clone, PartialEq)] 14 15 pub struct Weapon<'a> { 16 pub _tab: flatbuffers::Table<'a>, 17 } 18 19 impl<'a> flatbuffers::Follow<'a> for Weapon<'a> { 20 type Inner = Weapon<'a>; 21 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner22 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 23 Self { _tab: flatbuffers::Table { buf, loc } } 24 } 25 } 26 27 impl<'a> Weapon<'a> { 28 pub const VT_NAME: flatbuffers::VOffsetT = 4; 29 pub const VT_DAMAGE: flatbuffers::VOffsetT = 6; 30 get_fully_qualified_name() -> &'static str31 pub const fn get_fully_qualified_name() -> &'static str { 32 "MyGame.Sample.Weapon" 33 } 34 35 #[inline] init_from_table(table: flatbuffers::Table<'a>) -> Self36 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { 37 Weapon { _tab: table } 38 } 39 #[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>>40 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( 41 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, 42 args: &'args WeaponArgs<'args> 43 ) -> flatbuffers::WIPOffset<Weapon<'bldr>> { 44 let mut builder = WeaponBuilder::new(_fbb); 45 if let Some(x) = args.name { builder.add_name(x); } 46 builder.add_damage(args.damage); 47 builder.finish() 48 } 49 unpack(&self) -> WeaponT50 pub fn unpack(&self) -> WeaponT { 51 let name = self.name().map(|x| { 52 x.to_string() 53 }); 54 let damage = self.damage(); 55 WeaponT { 56 name, 57 damage, 58 } 59 } 60 61 #[inline] name(&self) -> Option<&'a str>62 pub fn name(&self) -> Option<&'a str> { 63 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None) 64 } 65 #[inline] damage(&self) -> i1666 pub fn damage(&self) -> i16 { 67 self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap() 68 } 69 } 70 71 impl flatbuffers::Verifiable for Weapon<'_> { 72 #[inline] run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>73 fn run_verifier( 74 v: &mut flatbuffers::Verifier, pos: usize 75 ) -> Result<(), flatbuffers::InvalidFlatbuffer> { 76 use self::flatbuffers::Verifiable; 77 v.visit_table(pos)? 78 .visit_field::<flatbuffers::ForwardsUOffset<&str>>("name", Self::VT_NAME, false)? 79 .visit_field::<i16>("damage", Self::VT_DAMAGE, false)? 80 .finish(); 81 Ok(()) 82 } 83 } 84 pub struct WeaponArgs<'a> { 85 pub name: Option<flatbuffers::WIPOffset<&'a str>>, 86 pub damage: i16, 87 } 88 impl<'a> Default for WeaponArgs<'a> { 89 #[inline] default() -> Self90 fn default() -> Self { 91 WeaponArgs { 92 name: None, 93 damage: 0, 94 } 95 } 96 } 97 98 pub struct WeaponBuilder<'a: 'b, 'b> { 99 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, 100 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>, 101 } 102 impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> { 103 #[inline] add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>)104 pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) { 105 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Weapon::VT_NAME, name); 106 } 107 #[inline] add_damage(&mut self, damage: i16)108 pub fn add_damage(&mut self, damage: i16) { 109 self.fbb_.push_slot::<i16>(Weapon::VT_DAMAGE, damage, 0); 110 } 111 #[inline] new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeaponBuilder<'a, 'b>112 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeaponBuilder<'a, 'b> { 113 let start = _fbb.start_table(); 114 WeaponBuilder { 115 fbb_: _fbb, 116 start_: start, 117 } 118 } 119 #[inline] finish(self) -> flatbuffers::WIPOffset<Weapon<'a>>120 pub fn finish(self) -> flatbuffers::WIPOffset<Weapon<'a>> { 121 let o = self.fbb_.end_table(self.start_); 122 flatbuffers::WIPOffset::new(o.value()) 123 } 124 } 125 126 impl core::fmt::Debug for Weapon<'_> { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result127 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 128 let mut ds = f.debug_struct("Weapon"); 129 ds.field("name", &self.name()); 130 ds.field("damage", &self.damage()); 131 ds.finish() 132 } 133 } 134 #[non_exhaustive] 135 #[derive(Debug, Clone, PartialEq)] 136 pub struct WeaponT { 137 pub name: Option<String>, 138 pub damage: i16, 139 } 140 impl Default for WeaponT { default() -> Self141 fn default() -> Self { 142 Self { 143 name: None, 144 damage: 0, 145 } 146 } 147 } 148 impl WeaponT { pack<'b>( &self, _fbb: &mut flatbuffers::FlatBufferBuilder<'b> ) -> flatbuffers::WIPOffset<Weapon<'b>>149 pub fn pack<'b>( 150 &self, 151 _fbb: &mut flatbuffers::FlatBufferBuilder<'b> 152 ) -> flatbuffers::WIPOffset<Weapon<'b>> { 153 let name = self.name.as_ref().map(|x|{ 154 _fbb.create_string(x) 155 }); 156 let damage = self.damage; 157 Weapon::create(_fbb, &WeaponArgs{ 158 name, 159 damage, 160 }) 161 } 162 } 163