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 extern crate serde; 11 use self::serde::ser::{Serialize, Serializer, SerializeStruct}; 12 use self::flatbuffers::{EndianScalar, Follow}; 13 use super::*; 14 pub enum StatOffset {} 15 #[derive(Copy, Clone, PartialEq)] 16 17 pub struct Stat<'a> { 18 pub _tab: flatbuffers::Table<'a>, 19 } 20 21 impl<'a> flatbuffers::Follow<'a> for Stat<'a> { 22 type Inner = Stat<'a>; 23 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner24 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 25 Self { _tab: flatbuffers::Table { buf, loc } } 26 } 27 } 28 29 impl<'a> Stat<'a> { 30 pub const VT_ID: flatbuffers::VOffsetT = 4; 31 pub const VT_VAL: flatbuffers::VOffsetT = 6; 32 pub const VT_COUNT: flatbuffers::VOffsetT = 8; 33 get_fully_qualified_name() -> &'static str34 pub const fn get_fully_qualified_name() -> &'static str { 35 "MyGame.Example.Stat" 36 } 37 38 #[inline] init_from_table(table: flatbuffers::Table<'a>) -> Self39 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { 40 Stat { _tab: table } 41 } 42 #[allow(unused_mut)] create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, args: &'args StatArgs<'args> ) -> flatbuffers::WIPOffset<Stat<'bldr>>43 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( 44 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, 45 args: &'args StatArgs<'args> 46 ) -> flatbuffers::WIPOffset<Stat<'bldr>> { 47 let mut builder = StatBuilder::new(_fbb); 48 builder.add_val(args.val); 49 if let Some(x) = args.id { builder.add_id(x); } 50 builder.add_count(args.count); 51 builder.finish() 52 } 53 unpack(&self) -> StatT54 pub fn unpack(&self) -> StatT { 55 let id = self.id().map(|x| { 56 x.to_string() 57 }); 58 let val = self.val(); 59 let count = self.count(); 60 StatT { 61 id, 62 val, 63 count, 64 } 65 } 66 67 #[inline] id(&self) -> Option<&'a str>68 pub fn id(&self) -> Option<&'a str> { 69 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None) 70 } 71 #[inline] val(&self) -> i6472 pub fn val(&self) -> i64 { 73 self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap() 74 } 75 #[inline] count(&self) -> u1676 pub fn count(&self) -> u16 { 77 self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap() 78 } 79 #[inline] key_compare_less_than(&self, o: &Stat) -> bool80 pub fn key_compare_less_than(&self, o: &Stat) -> bool { 81 self.count() < o.count() 82 } 83 84 #[inline] key_compare_with_value(&self, val: u16) -> ::core::cmp::Ordering85 pub fn key_compare_with_value(&self, val: u16) -> ::core::cmp::Ordering { 86 let key = self.count(); 87 key.cmp(&val) 88 } 89 } 90 91 impl flatbuffers::Verifiable for Stat<'_> { 92 #[inline] run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>93 fn run_verifier( 94 v: &mut flatbuffers::Verifier, pos: usize 95 ) -> Result<(), flatbuffers::InvalidFlatbuffer> { 96 use self::flatbuffers::Verifiable; 97 v.visit_table(pos)? 98 .visit_field::<flatbuffers::ForwardsUOffset<&str>>("id", Self::VT_ID, false)? 99 .visit_field::<i64>("val", Self::VT_VAL, false)? 100 .visit_field::<u16>("count", Self::VT_COUNT, false)? 101 .finish(); 102 Ok(()) 103 } 104 } 105 pub struct StatArgs<'a> { 106 pub id: Option<flatbuffers::WIPOffset<&'a str>>, 107 pub val: i64, 108 pub count: u16, 109 } 110 impl<'a> Default for StatArgs<'a> { 111 #[inline] default() -> Self112 fn default() -> Self { 113 StatArgs { 114 id: None, 115 val: 0, 116 count: 0, 117 } 118 } 119 } 120 121 impl Serialize for Stat<'_> { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer,122 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 123 where 124 S: Serializer, 125 { 126 let mut s = serializer.serialize_struct("Stat", 3)?; 127 if let Some(f) = self.id() { 128 s.serialize_field("id", &f)?; 129 } else { 130 s.skip_field("id")?; 131 } 132 s.serialize_field("val", &self.val())?; 133 s.serialize_field("count", &self.count())?; 134 s.end() 135 } 136 } 137 138 pub struct StatBuilder<'a: 'b, 'b> { 139 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, 140 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>, 141 } 142 impl<'a: 'b, 'b> StatBuilder<'a, 'b> { 143 #[inline] add_id(&mut self, id: flatbuffers::WIPOffset<&'b str>)144 pub fn add_id(&mut self, id: flatbuffers::WIPOffset<&'b str>) { 145 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Stat::VT_ID, id); 146 } 147 #[inline] add_val(&mut self, val: i64)148 pub fn add_val(&mut self, val: i64) { 149 self.fbb_.push_slot::<i64>(Stat::VT_VAL, val, 0); 150 } 151 #[inline] add_count(&mut self, count: u16)152 pub fn add_count(&mut self, count: u16) { 153 self.fbb_.push_slot::<u16>(Stat::VT_COUNT, count, 0); 154 } 155 #[inline] new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> StatBuilder<'a, 'b>156 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> StatBuilder<'a, 'b> { 157 let start = _fbb.start_table(); 158 StatBuilder { 159 fbb_: _fbb, 160 start_: start, 161 } 162 } 163 #[inline] finish(self) -> flatbuffers::WIPOffset<Stat<'a>>164 pub fn finish(self) -> flatbuffers::WIPOffset<Stat<'a>> { 165 let o = self.fbb_.end_table(self.start_); 166 flatbuffers::WIPOffset::new(o.value()) 167 } 168 } 169 170 impl core::fmt::Debug for Stat<'_> { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result171 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 172 let mut ds = f.debug_struct("Stat"); 173 ds.field("id", &self.id()); 174 ds.field("val", &self.val()); 175 ds.field("count", &self.count()); 176 ds.finish() 177 } 178 } 179 #[non_exhaustive] 180 #[derive(Debug, Clone, PartialEq)] 181 pub struct StatT { 182 pub id: Option<String>, 183 pub val: i64, 184 pub count: u16, 185 } 186 impl Default for StatT { default() -> Self187 fn default() -> Self { 188 Self { 189 id: None, 190 val: 0, 191 count: 0, 192 } 193 } 194 } 195 impl StatT { pack<'b>( &self, _fbb: &mut flatbuffers::FlatBufferBuilder<'b> ) -> flatbuffers::WIPOffset<Stat<'b>>196 pub fn pack<'b>( 197 &self, 198 _fbb: &mut flatbuffers::FlatBufferBuilder<'b> 199 ) -> flatbuffers::WIPOffset<Stat<'b>> { 200 let id = self.id.as_ref().map(|x|{ 201 _fbb.create_string(x) 202 }); 203 let val = self.val; 204 let count = self.count; 205 Stat::create(_fbb, &StatArgs{ 206 id, 207 val, 208 count, 209 }) 210 } 211 } 212