1// automatically generated by the FlatBuffers compiler, do not modify
2// @generated
3extern crate alloc;
4extern crate flatbuffers;
5use alloc::boxed::Box;
6use alloc::string::{String, ToString};
7use alloc::vec::Vec;
8use core::mem;
9use core::cmp::Ordering;
10use self::flatbuffers::{EndianScalar, Follow};
11use super::*;
12pub enum StatOffset {}
13#[derive(Copy, Clone, PartialEq)]
14
15pub struct Stat<'a> {
16 pub _tab: flatbuffers::Table<'a>,
17}
18
19impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
20 type Inner = Stat<'a>;
21 #[inline]
22 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
23 Self { _tab: flatbuffers::Table::new(buf, loc) }
24 }
25}
26
27impl<'a> Stat<'a> {
28 pub const VT_ID: flatbuffers::VOffsetT = 4;
29 pub const VT_VAL: flatbuffers::VOffsetT = 6;
30 pub const VT_COUNT: flatbuffers::VOffsetT = 8;
31
32 pub const fn get_fully_qualified_name() -> &'static str {
33 "MyGame.Example.Stat"
34 }
35
36 #[inline]
37 pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
38 Stat { _tab: table }
39 }
40 #[allow(unused_mut)]
41 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
42 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
43 args: &'args StatArgs<'args>
44 ) -> flatbuffers::WIPOffset<Stat<'bldr>> {
45 let mut builder = StatBuilder::new(_fbb);
46 builder.add_val(args.val);
47 if let Some(x) = args.id { builder.add_id(x); }
48 builder.add_count(args.count);
49 builder.finish()
50 }
51
52 pub fn unpack(&self) -> StatT {
53 let id = self.id().map(|x| {
54 x.to_string()
55 });
56 let val = self.val();
57 let count = self.count();
58 StatT {
59 id,
60 val,
61 count,
62 }
63 }
64
65 #[inline]
66 pub fn id(&self) -> Option<&'a str> {
67 // Safety:
68 // Created from valid Table for this object
69 // which contains a valid value in this slot
70 unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)}
71 }
72 #[inline]
73 pub fn val(&self) -> i64 {
74 // Safety:
75 // Created from valid Table for this object
76 // which contains a valid value in this slot
77 unsafe { self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()}
78 }
79 #[inline]
80 pub fn count(&self) -> u16 {
81 // Safety:
82 // Created from valid Table for this object
83 // which contains a valid value in this slot
84 unsafe { self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()}
85 }
86 #[inline]
87 pub fn key_compare_less_than(&self, o: &Stat) -> bool {
88 self.count() < o.count()
89 }
90
91 #[inline]
92 pub fn key_compare_with_value(&self, val: u16) -> ::core::cmp::Ordering {
93 let key = self.count();
94 key.cmp(&val)
95 }
96}
97
98impl flatbuffers::Verifiable for Stat<'_> {
99 #[inline]
100 fn run_verifier(
101 v: &mut flatbuffers::Verifier, pos: usize
102 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
103 use self::flatbuffers::Verifiable;
104 v.visit_table(pos)?
105 .visit_field::<flatbuffers::ForwardsUOffset<&str>>("id", Self::VT_ID, false)?
106 .visit_field::<i64>("val", Self::VT_VAL, false)?
107 .visit_field::<u16>("count", Self::VT_COUNT, false)?
108 .finish();
109 Ok(())
110 }
111}
112pub struct StatArgs<'a> {
113 pub id: Option<flatbuffers::WIPOffset<&'a str>>,
114 pub val: i64,
115 pub count: u16,
116}
117impl<'a> Default for StatArgs<'a> {
118 #[inline]
119 fn default() -> Self {
120 StatArgs {
121 id: None,
122 val: 0,
123 count: 0,
124 }
125 }
126}
127
128pub struct StatBuilder<'a: 'b, 'b> {
129 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
130 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
131}
132impl<'a: 'b, 'b> StatBuilder<'a, 'b> {
133 #[inline]
134 pub fn add_id(&mut self, id: flatbuffers::WIPOffset<&'b str>) {
135 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Stat::VT_ID, id);
136 }
137 #[inline]
138 pub fn add_val(&mut self, val: i64) {
139 self.fbb_.push_slot::<i64>(Stat::VT_VAL, val, 0);
140 }
141 #[inline]
142 pub fn add_count(&mut self, count: u16) {
143 self.fbb_.push_slot::<u16>(Stat::VT_COUNT, count, 0);
144 }
145 #[inline]
146 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> StatBuilder<'a, 'b> {
147 let start = _fbb.start_table();
148 StatBuilder {
149 fbb_: _fbb,
150 start_: start,
151 }
152 }
153 #[inline]
154 pub fn finish(self) -> flatbuffers::WIPOffset<Stat<'a>> {
155 let o = self.fbb_.end_table(self.start_);
156 flatbuffers::WIPOffset::new(o.value())
157 }
158}
159
160impl core::fmt::Debug for Stat<'_> {
161 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
162 let mut ds = f.debug_struct("Stat");
163 ds.field("id", &self.id());
164 ds.field("val", &self.val());
165 ds.field("count", &self.count());
166 ds.finish()
167 }
168}
169#[non_exhaustive]
170#[derive(Debug, Clone, PartialEq)]
171pub struct StatT {
172 pub id: Option<String>,
173 pub val: i64,
174 pub count: u16,
175}
176impl Default for StatT {
177 fn default() -> Self {
178 Self {
179 id: None,
180 val: 0,
181 count: 0,
182 }
183 }
184}
185impl StatT {
186 pub fn pack<'b>(
187 &self,
188 _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
189 ) -> flatbuffers::WIPOffset<Stat<'b>> {
190 let id = self.id.as_ref().map(|x|{
191 _fbb.create_string(x)
192 });
193 let val = self.val;
194 let count = self.count;
195 Stat::create(_fbb, &StatArgs{
196 id,
197 val,
198 count,
199 })
200 }
201}
View as plain text