1 // automatically generated by the FlatBuffers compiler, do not modify
2
3
4 pub mod my_game {
5 #![allow(dead_code)]
6 #![allow(unused_imports)]
7
8 use std::mem;
9 use std::marker::PhantomData;
10 use std::cmp::Ordering;
11
12 extern crate flatbuffers;
13 use self::flatbuffers::EndianScalar;
14 pub mod sample {
15 #![allow(dead_code)]
16 #![allow(unused_imports)]
17
18 use std::mem;
19 use std::marker::PhantomData;
20 use std::cmp::Ordering;
21
22 extern crate flatbuffers;
23 use self::flatbuffers::EndianScalar;
24
25 #[allow(non_camel_case_types)]
26 #[repr(i8)]
27 #[derive(Clone, Copy, PartialEq, Debug)]
28 pub enum Color {
29 Red = 0,
30 Green = 1,
31 Blue = 2
32 }
33
34 const ENUM_MIN_COLOR: i8 = 0;
35 const ENUM_MAX_COLOR: i8 = 2;
36
37 impl<'a> flatbuffers::Follow<'a> for Color {
38 type Inner = Self;
39 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner40 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
41 flatbuffers::read_scalar_at::<Self>(buf, loc)
42 }
43 }
44
45 impl flatbuffers::EndianScalar for Color {
46 #[inline]
to_little_endian(self) -> Self47 fn to_little_endian(self) -> Self {
48 let n = i8::to_le(self as i8);
49 let p = &n as *const i8 as *const Color;
50 unsafe { *p }
51 }
52 #[inline]
from_little_endian(self) -> Self53 fn from_little_endian(self) -> Self {
54 let n = i8::from_le(self as i8);
55 let p = &n as *const i8 as *const Color;
56 unsafe { *p }
57 }
58 }
59
60 impl flatbuffers::Push for Color {
61 type Output = Color;
62 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])63 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
64 flatbuffers::emplace_scalar::<Color>(dst, *self);
65 }
66 }
67
68 #[allow(non_camel_case_types)]
69 const ENUM_VALUES_COLOR:[Color; 3] = [
70 Color::Red,
71 Color::Green,
72 Color::Blue
73 ];
74
75 #[allow(non_camel_case_types)]
76 const ENUM_NAMES_COLOR:[&'static str; 3] = [
77 "Red",
78 "Green",
79 "Blue"
80 ];
81
enum_name_color(e: Color) -> &'static str82 pub fn enum_name_color(e: Color) -> &'static str {
83 let index: usize = e as usize;
84 ENUM_NAMES_COLOR[index]
85 }
86
87 #[allow(non_camel_case_types)]
88 #[repr(u8)]
89 #[derive(Clone, Copy, PartialEq, Debug)]
90 pub enum Equipment {
91 NONE = 0,
92 Weapon = 1
93 }
94
95 const ENUM_MIN_EQUIPMENT: u8 = 0;
96 const ENUM_MAX_EQUIPMENT: u8 = 1;
97
98 impl<'a> flatbuffers::Follow<'a> for Equipment {
99 type Inner = Self;
100 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner101 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
102 flatbuffers::read_scalar_at::<Self>(buf, loc)
103 }
104 }
105
106 impl flatbuffers::EndianScalar for Equipment {
107 #[inline]
to_little_endian(self) -> Self108 fn to_little_endian(self) -> Self {
109 let n = u8::to_le(self as u8);
110 let p = &n as *const u8 as *const Equipment;
111 unsafe { *p }
112 }
113 #[inline]
from_little_endian(self) -> Self114 fn from_little_endian(self) -> Self {
115 let n = u8::from_le(self as u8);
116 let p = &n as *const u8 as *const Equipment;
117 unsafe { *p }
118 }
119 }
120
121 impl flatbuffers::Push for Equipment {
122 type Output = Equipment;
123 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])124 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
125 flatbuffers::emplace_scalar::<Equipment>(dst, *self);
126 }
127 }
128
129 #[allow(non_camel_case_types)]
130 const ENUM_VALUES_EQUIPMENT:[Equipment; 2] = [
131 Equipment::NONE,
132 Equipment::Weapon
133 ];
134
135 #[allow(non_camel_case_types)]
136 const ENUM_NAMES_EQUIPMENT:[&'static str; 2] = [
137 "NONE",
138 "Weapon"
139 ];
140
enum_name_equipment(e: Equipment) -> &'static str141 pub fn enum_name_equipment(e: Equipment) -> &'static str {
142 let index: usize = e as usize;
143 ENUM_NAMES_EQUIPMENT[index]
144 }
145
146 pub struct EquipmentUnionTableOffset {}
147 // struct Vec3, aligned to 4
148 #[repr(C, align(4))]
149 #[derive(Clone, Copy, Debug, PartialEq)]
150 pub struct Vec3 {
151 x_: f32,
152 y_: f32,
153 z_: f32,
154 } // pub struct Vec3
155 impl flatbuffers::SafeSliceAccess for Vec3 {}
156 impl<'a> flatbuffers::Follow<'a> for Vec3 {
157 type Inner = &'a Vec3;
158 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner159 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
160 <&'a Vec3>::follow(buf, loc)
161 //flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
162 }
163 }
164 impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
165 type Inner = &'a Vec3;
166 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner167 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
168 flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
169 }
170 }
171 impl<'b> flatbuffers::Push for Vec3 {
172 type Output = Vec3;
173 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])174 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
175 let src = unsafe {
176 ::std::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
177 };
178 dst.copy_from_slice(src);
179 }
180 }
181 impl<'b> flatbuffers::Push for &'b Vec3 {
182 type Output = Vec3;
183
184 #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])185 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
186 let src = unsafe {
187 ::std::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
188 };
189 dst.copy_from_slice(src);
190 }
191 }
192
193
194 impl Vec3 {
new<'a>(_x: f32, _y: f32, _z: f32) -> Self195 pub fn new<'a>(_x: f32, _y: f32, _z: f32) -> Self {
196 Vec3 {
197 x_: _x.to_little_endian(),
198 y_: _y.to_little_endian(),
199 z_: _z.to_little_endian(),
200
201 }
202 }
x<'a>(&'a self) -> f32203 pub fn x<'a>(&'a self) -> f32 {
204 self.x_.from_little_endian()
205 }
y<'a>(&'a self) -> f32206 pub fn y<'a>(&'a self) -> f32 {
207 self.y_.from_little_endian()
208 }
z<'a>(&'a self) -> f32209 pub fn z<'a>(&'a self) -> f32 {
210 self.z_.from_little_endian()
211 }
212 }
213
214 pub enum MonsterOffset {}
215 #[derive(Copy, Clone, Debug, PartialEq)]
216
217 pub struct Monster<'a> {
218 pub _tab: flatbuffers::Table<'a>,
219 }
220
221 impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
222 type Inner = Monster<'a>;
223 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner224 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
225 Self {
226 _tab: flatbuffers::Table { buf: buf, loc: loc },
227 }
228 }
229 }
230
231 impl<'a> Monster<'a> {
232 #[inline]
init_from_table(table: flatbuffers::Table<'a>) -> Self233 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
234 Monster {
235 _tab: table,
236 }
237 }
238 #[allow(unused_mut)]
create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, args: &'args MonsterArgs<'args>) -> flatbuffers::WIPOffset<Monster<'bldr>>239 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
240 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
241 args: &'args MonsterArgs<'args>) -> flatbuffers::WIPOffset<Monster<'bldr>> {
242 let mut builder = MonsterBuilder::new(_fbb);
243 if let Some(x) = args.equipped { builder.add_equipped(x); }
244 if let Some(x) = args.weapons { builder.add_weapons(x); }
245 if let Some(x) = args.inventory { builder.add_inventory(x); }
246 if let Some(x) = args.name { builder.add_name(x); }
247 if let Some(x) = args.pos { builder.add_pos(x); }
248 builder.add_hp(args.hp);
249 builder.add_mana(args.mana);
250 builder.add_equipped_type(args.equipped_type);
251 builder.add_color(args.color);
252 builder.finish()
253 }
254
255 pub const VT_POS: flatbuffers::VOffsetT = 4;
256 pub const VT_MANA: flatbuffers::VOffsetT = 6;
257 pub const VT_HP: flatbuffers::VOffsetT = 8;
258 pub const VT_NAME: flatbuffers::VOffsetT = 10;
259 pub const VT_INVENTORY: flatbuffers::VOffsetT = 14;
260 pub const VT_COLOR: flatbuffers::VOffsetT = 16;
261 pub const VT_WEAPONS: flatbuffers::VOffsetT = 18;
262 pub const VT_EQUIPPED_TYPE: flatbuffers::VOffsetT = 20;
263 pub const VT_EQUIPPED: flatbuffers::VOffsetT = 22;
264
265 #[inline]
pos(&'a self) -> Option<&'a Vec3>266 pub fn pos(&'a self) -> Option<&'a Vec3> {
267 self._tab.get::<Vec3>(Monster::VT_POS, None)
268 }
269 #[inline]
mana(&'a self) -> i16270 pub fn mana(&'a self) -> i16 {
271 self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
272 }
273 #[inline]
hp(&'a self) -> i16274 pub fn hp(&'a self) -> i16 {
275 self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
276 }
277 #[inline]
name(&'a self) -> Option<&'a str>278 pub fn name(&'a self) -> Option<&'a str> {
279 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)
280 }
281 #[inline]
inventory(&'a self) -> Option<&'a [u8]>282 pub fn inventory(&'a self) -> Option<&'a [u8]> {
283 self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
284 }
285 #[inline]
color(&'a self) -> Color286 pub fn color(&'a self) -> Color {
287 self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
288 }
289 #[inline]
weapons(&'a self) -> Option<flatbuffers::Vector<flatbuffers::ForwardsUOffset<Weapon<'a>>>>290 pub fn weapons(&'a self) -> Option<flatbuffers::Vector<flatbuffers::ForwardsUOffset<Weapon<'a>>>> {
291 self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<flatbuffers::ForwardsUOffset<Weapon<'a>>>>>(Monster::VT_WEAPONS, None)
292 }
293 #[inline]
equipped_type(&'a self) -> Equipment294 pub fn equipped_type(&'a self) -> Equipment {
295 self._tab.get::<Equipment>(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()
296 }
297 #[inline]
equipped(&'a self) -> Option<flatbuffers::Table<'a>>298 pub fn equipped(&'a self) -> Option<flatbuffers::Table<'a>> {
299 self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_EQUIPPED, None)
300 }
301 #[inline]
302 #[allow(non_snake_case)]
equipped_as_weapon(&'a self) -> Option<Weapon>303 pub fn equipped_as_weapon(&'a self) -> Option<Weapon> {
304 if self.equipped_type() == Equipment::Weapon {
305 self.equipped().map(|u| Weapon::init_from_table(u))
306 } else {
307 None
308 }
309 }
310
311 }
312
313 pub struct MonsterArgs<'a> {
314 pub pos: Option<&'a Vec3>,
315 pub mana: i16,
316 pub hp: i16,
317 pub name: Option<flatbuffers::WIPOffset<&'a str>>,
318 pub inventory: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a , u8>>>,
319 pub color: Color,
320 pub weapons: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a , flatbuffers::ForwardsUOffset<Weapon<'a >>>>>,
321 pub equipped_type: Equipment,
322 pub equipped: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
323 }
324 impl<'a> Default for MonsterArgs<'a> {
325 #[inline]
default() -> Self326 fn default() -> Self {
327 MonsterArgs {
328 pos: None,
329 mana: 150,
330 hp: 100,
331 name: None,
332 inventory: None,
333 color: Color::Blue,
334 weapons: None,
335 equipped_type: Equipment::NONE,
336 equipped: None,
337 }
338 }
339 }
340 pub struct MonsterBuilder<'a: 'b, 'b> {
341 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
342 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
343 }
344 impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> {
345 #[inline]
add_pos(&mut self, pos: &'b Vec3)346 pub fn add_pos(&mut self, pos: &'b Vec3) {
347 self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos);
348 }
349 #[inline]
add_mana(&mut self, mana: i16)350 pub fn add_mana(&mut self, mana: i16) {
351 self.fbb_.push_slot::<i16>(Monster::VT_MANA, mana, 150);
352 }
353 #[inline]
add_hp(&mut self, hp: i16)354 pub fn add_hp(&mut self, hp: i16) {
355 self.fbb_.push_slot::<i16>(Monster::VT_HP, hp, 100);
356 }
357 #[inline]
add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>)358 pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
359 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_NAME, name);
360 }
361 #[inline]
add_inventory(&mut self, inventory: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>)362 pub fn add_inventory(&mut self, inventory: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>) {
363 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_INVENTORY, inventory);
364 }
365 #[inline]
add_color(&mut self, color: Color)366 pub fn add_color(&mut self, color: Color) {
367 self.fbb_.push_slot::<Color>(Monster::VT_COLOR, color, Color::Blue);
368 }
369 #[inline]
add_weapons(&mut self, weapons: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Weapon<'b >>>>)370 pub fn add_weapons(&mut self, weapons: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Weapon<'b >>>>) {
371 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_WEAPONS, weapons);
372 }
373 #[inline]
add_equipped_type(&mut self, equipped_type: Equipment)374 pub fn add_equipped_type(&mut self, equipped_type: Equipment) {
375 self.fbb_.push_slot::<Equipment>(Monster::VT_EQUIPPED_TYPE, equipped_type, Equipment::NONE);
376 }
377 #[inline]
add_equipped(&mut self, equipped: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>)378 pub fn add_equipped(&mut self, equipped: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
379 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_EQUIPPED, equipped);
380 }
381 #[inline]
new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> MonsterBuilder<'a, 'b>382 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> MonsterBuilder<'a, 'b> {
383 let start = _fbb.start_table();
384 MonsterBuilder {
385 fbb_: _fbb,
386 start_: start,
387 }
388 }
389 #[inline]
finish(self) -> flatbuffers::WIPOffset<Monster<'a>>390 pub fn finish(self) -> flatbuffers::WIPOffset<Monster<'a>> {
391 let o = self.fbb_.end_table(self.start_);
392 flatbuffers::WIPOffset::new(o.value())
393 }
394 }
395
396 pub enum WeaponOffset {}
397 #[derive(Copy, Clone, Debug, PartialEq)]
398
399 pub struct Weapon<'a> {
400 pub _tab: flatbuffers::Table<'a>,
401 }
402
403 impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
404 type Inner = Weapon<'a>;
405 #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner406 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
407 Self {
408 _tab: flatbuffers::Table { buf: buf, loc: loc },
409 }
410 }
411 }
412
413 impl<'a> Weapon<'a> {
414 #[inline]
init_from_table(table: flatbuffers::Table<'a>) -> Self415 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
416 Weapon {
417 _tab: table,
418 }
419 }
420 #[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>>421 pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
422 _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
423 args: &'args WeaponArgs<'args>) -> flatbuffers::WIPOffset<Weapon<'bldr>> {
424 let mut builder = WeaponBuilder::new(_fbb);
425 if let Some(x) = args.name { builder.add_name(x); }
426 builder.add_damage(args.damage);
427 builder.finish()
428 }
429
430 pub const VT_NAME: flatbuffers::VOffsetT = 4;
431 pub const VT_DAMAGE: flatbuffers::VOffsetT = 6;
432
433 #[inline]
name(&'a self) -> Option<&'a str>434 pub fn name(&'a self) -> Option<&'a str> {
435 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)
436 }
437 #[inline]
damage(&'a self) -> i16438 pub fn damage(&'a self) -> i16 {
439 self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()
440 }
441 }
442
443 pub struct WeaponArgs<'a> {
444 pub name: Option<flatbuffers::WIPOffset<&'a str>>,
445 pub damage: i16,
446 }
447 impl<'a> Default for WeaponArgs<'a> {
448 #[inline]
default() -> Self449 fn default() -> Self {
450 WeaponArgs {
451 name: None,
452 damage: 0,
453 }
454 }
455 }
456 pub struct WeaponBuilder<'a: 'b, 'b> {
457 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
458 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
459 }
460 impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> {
461 #[inline]
add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>)462 pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
463 self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Weapon::VT_NAME, name);
464 }
465 #[inline]
add_damage(&mut self, damage: i16)466 pub fn add_damage(&mut self, damage: i16) {
467 self.fbb_.push_slot::<i16>(Weapon::VT_DAMAGE, damage, 0);
468 }
469 #[inline]
new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeaponBuilder<'a, 'b>470 pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeaponBuilder<'a, 'b> {
471 let start = _fbb.start_table();
472 WeaponBuilder {
473 fbb_: _fbb,
474 start_: start,
475 }
476 }
477 #[inline]
finish(self) -> flatbuffers::WIPOffset<Weapon<'a>>478 pub fn finish(self) -> flatbuffers::WIPOffset<Weapon<'a>> {
479 let o = self.fbb_.end_table(self.start_);
480 flatbuffers::WIPOffset::new(o.value())
481 }
482 }
483
484 #[inline]
get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a>485 pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
486 flatbuffers::get_root::<Monster<'a>>(buf)
487 }
488
489 #[inline]
get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a>490 pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
491 flatbuffers::get_size_prefixed_root::<Monster<'a>>(buf)
492 }
493
494 #[inline]
finish_monster_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Monster<'a>>)495 pub fn finish_monster_buffer<'a, 'b>(
496 fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
497 root: flatbuffers::WIPOffset<Monster<'a>>) {
498 fbb.finish(root, None);
499 }
500
501 #[inline]
finish_size_prefixed_monster_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Monster<'a>>)502 pub fn finish_size_prefixed_monster_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Monster<'a>>) {
503 fbb.finish_size_prefixed(root, None);
504 }
505 } // pub mod Sample
506 } // pub mod MyGame
507
508