• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
25     Self { _tab: flatbuffers::Table::new(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 unsafe 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, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, args: &'args StatArgs<'args> ) -> flatbuffers::WIPOffset<Stat<'bldr>>43   pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
44     _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
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     // Safety:
70     // Created from valid Table for this object
71     // which contains a valid value in this slot
72     unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)}
73   }
74   #[inline]
val(&self) -> i6475   pub fn val(&self) -> i64 {
76     // Safety:
77     // Created from valid Table for this object
78     // which contains a valid value in this slot
79     unsafe { self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()}
80   }
81   #[inline]
count(&self) -> u1682   pub fn count(&self) -> u16 {
83     // Safety:
84     // Created from valid Table for this object
85     // which contains a valid value in this slot
86     unsafe { self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()}
87   }
88   #[inline]
key_compare_less_than(&self, o: &Stat) -> bool89   pub fn key_compare_less_than(&self, o: &Stat) -> bool {
90     self.count() < o.count()
91   }
92 
93   #[inline]
key_compare_with_value(&self, val: u16) -> ::core::cmp::Ordering94   pub fn key_compare_with_value(&self, val: u16) -> ::core::cmp::Ordering {
95     let key = self.count();
96     key.cmp(&val)
97   }
98 }
99 
100 impl flatbuffers::Verifiable for Stat<'_> {
101   #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>102   fn run_verifier(
103     v: &mut flatbuffers::Verifier, pos: usize
104   ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
105     use self::flatbuffers::Verifiable;
106     v.visit_table(pos)?
107      .visit_field::<flatbuffers::ForwardsUOffset<&str>>("id", Self::VT_ID, false)?
108      .visit_field::<i64>("val", Self::VT_VAL, false)?
109      .visit_field::<u16>("count", Self::VT_COUNT, false)?
110      .finish();
111     Ok(())
112   }
113 }
114 pub struct StatArgs<'a> {
115     pub id: Option<flatbuffers::WIPOffset<&'a str>>,
116     pub val: i64,
117     pub count: u16,
118 }
119 impl<'a> Default for StatArgs<'a> {
120   #[inline]
default() -> Self121   fn default() -> Self {
122     StatArgs {
123       id: None,
124       val: 0,
125       count: 0,
126     }
127   }
128 }
129 
130 impl Serialize for Stat<'_> {
serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer,131   fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
132   where
133     S: Serializer,
134   {
135     let mut s = serializer.serialize_struct("Stat", 3)?;
136       if let Some(f) = self.id() {
137         s.serialize_field("id", &f)?;
138       } else {
139         s.skip_field("id")?;
140       }
141       s.serialize_field("val", &self.val())?;
142       s.serialize_field("count", &self.count())?;
143     s.end()
144   }
145 }
146 
147 pub struct StatBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
148   fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
149   start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
150 }
151 impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> StatBuilder<'a, 'b, A> {
152   #[inline]
add_id(&mut self, id: flatbuffers::WIPOffset<&'b str>)153   pub fn add_id(&mut self, id: flatbuffers::WIPOffset<&'b  str>) {
154     self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Stat::VT_ID, id);
155   }
156   #[inline]
add_val(&mut self, val: i64)157   pub fn add_val(&mut self, val: i64) {
158     self.fbb_.push_slot::<i64>(Stat::VT_VAL, val, 0);
159   }
160   #[inline]
add_count(&mut self, count: u16)161   pub fn add_count(&mut self, count: u16) {
162     self.fbb_.push_slot::<u16>(Stat::VT_COUNT, count, 0);
163   }
164   #[inline]
new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> StatBuilder<'a, 'b, A>165   pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> StatBuilder<'a, 'b, A> {
166     let start = _fbb.start_table();
167     StatBuilder {
168       fbb_: _fbb,
169       start_: start,
170     }
171   }
172   #[inline]
finish(self) -> flatbuffers::WIPOffset<Stat<'a>>173   pub fn finish(self) -> flatbuffers::WIPOffset<Stat<'a>> {
174     let o = self.fbb_.end_table(self.start_);
175     flatbuffers::WIPOffset::new(o.value())
176   }
177 }
178 
179 impl core::fmt::Debug for Stat<'_> {
fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result180   fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
181     let mut ds = f.debug_struct("Stat");
182       ds.field("id", &self.id());
183       ds.field("val", &self.val());
184       ds.field("count", &self.count());
185       ds.finish()
186   }
187 }
188 #[non_exhaustive]
189 #[derive(Debug, Clone, PartialEq)]
190 pub struct StatT {
191   pub id: Option<String>,
192   pub val: i64,
193   pub count: u16,
194 }
195 impl Default for StatT {
default() -> Self196   fn default() -> Self {
197     Self {
198       id: None,
199       val: 0,
200       count: 0,
201     }
202   }
203 }
204 impl StatT {
pack<'b, A: flatbuffers::Allocator + 'b>( &self, _fbb: &mut flatbuffers::FlatBufferBuilder<'b, A> ) -> flatbuffers::WIPOffset<Stat<'b>>205   pub fn pack<'b, A: flatbuffers::Allocator + 'b>(
206     &self,
207     _fbb: &mut flatbuffers::FlatBufferBuilder<'b, A>
208   ) -> flatbuffers::WIPOffset<Stat<'b>> {
209     let id = self.id.as_ref().map(|x|{
210       _fbb.create_string(x)
211     });
212     let val = self.val;
213     let count = self.count;
214     Stat::create(_fbb, &StatArgs{
215       id,
216       val,
217       count,
218     })
219   }
220 }
221