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 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 23 Self { _tab: flatbuffers::Table::new(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 unsafe 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, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, args: &'args WeaponArgs<'args> ) -> flatbuffers::WIPOffset<Weapon<'bldr>>40 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( 41 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, 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 // Safety: 64 // Created from valid Table for this object 65 // which contains a valid value in this slot 66 unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)} 67 } 68 #[inline] damage(&self) -> i1669 pub fn damage(&self) -> i16 { 70 // Safety: 71 // Created from valid Table for this object 72 // which contains a valid value in this slot 73 unsafe { self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()} 74 } 75 } 76 77 impl flatbuffers::Verifiable for Weapon<'_> { 78 #[inline] run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>79 fn run_verifier( 80 v: &mut flatbuffers::Verifier, pos: usize 81 ) -> Result<(), flatbuffers::InvalidFlatbuffer> { 82 use self::flatbuffers::Verifiable; 83 v.visit_table(pos)? 84 .visit_field::<flatbuffers::ForwardsUOffset<&str>>("name", Self::VT_NAME, false)? 85 .visit_field::<i16>("damage", Self::VT_DAMAGE, false)? 86 .finish(); 87 Ok(()) 88 } 89 } 90 pub struct WeaponArgs<'a> { 91 pub name: Option<flatbuffers::WIPOffset<&'a str>>, 92 pub damage: i16, 93 } 94 impl<'a> Default for WeaponArgs<'a> { 95 #[inline] default() -> Self96 fn default() -> Self { 97 WeaponArgs { 98 name: None, 99 damage: 0, 100 } 101 } 102 } 103 104 pub struct WeaponBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { 105 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, 106 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>, 107 } 108 impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> WeaponBuilder<'a, 'b, A> { 109 #[inline] add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>)110 pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) { 111 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Weapon::VT_NAME, name); 112 } 113 #[inline] add_damage(&mut self, damage: i16)114 pub fn add_damage(&mut self, damage: i16) { 115 self.fbb_.push_slot::<i16>(Weapon::VT_DAMAGE, damage, 0); 116 } 117 #[inline] new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> WeaponBuilder<'a, 'b, A>118 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> WeaponBuilder<'a, 'b, A> { 119 let start = _fbb.start_table(); 120 WeaponBuilder { 121 fbb_: _fbb, 122 start_: start, 123 } 124 } 125 #[inline] finish(self) -> flatbuffers::WIPOffset<Weapon<'a>>126 pub fn finish(self) -> flatbuffers::WIPOffset<Weapon<'a>> { 127 let o = self.fbb_.end_table(self.start_); 128 flatbuffers::WIPOffset::new(o.value()) 129 } 130 } 131 132 impl core::fmt::Debug for Weapon<'_> { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result133 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 134 let mut ds = f.debug_struct("Weapon"); 135 ds.field("name", &self.name()); 136 ds.field("damage", &self.damage()); 137 ds.finish() 138 } 139 } 140 #[non_exhaustive] 141 #[derive(Debug, Clone, PartialEq)] 142 pub struct WeaponT { 143 pub name: Option<String>, 144 pub damage: i16, 145 } 146 impl Default for WeaponT { default() -> Self147 fn default() -> Self { 148 Self { 149 name: None, 150 damage: 0, 151 } 152 } 153 } 154 impl WeaponT { pack<'b, A: flatbuffers::Allocator + 'b>( &self, _fbb: &mut flatbuffers::FlatBufferBuilder<'b, A> ) -> flatbuffers::WIPOffset<Weapon<'b>>155 pub fn pack<'b, A: flatbuffers::Allocator + 'b>( 156 &self, 157 _fbb: &mut flatbuffers::FlatBufferBuilder<'b, A> 158 ) -> flatbuffers::WIPOffset<Weapon<'b>> { 159 let name = self.name.as_ref().map(|x|{ 160 _fbb.create_string(x) 161 }); 162 let damage = self.damage; 163 Weapon::create(_fbb, &WeaponArgs{ 164 name, 165 damage, 166 }) 167 } 168 } 169