blob: 9ec573c7c3bf7accfc10f71d5c1058827c28f0ea [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001// automatically generated by the FlatBuffers compiler, do not modify
2
3
4pub 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;
14pub 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)]
28pub enum Color {
29 Red = 0,
30 Green = 1,
31 Blue = 2
32}
33
34const ENUM_MIN_COLOR: i8 = 0;
35const ENUM_MAX_COLOR: i8 = 2;
36
37impl<'a> flatbuffers::Follow<'a> for Color {
38 type Inner = Self;
39 #[inline]
40 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
41 flatbuffers::read_scalar_at::<Self>(buf, loc)
42 }
43}
44
45impl flatbuffers::EndianScalar for Color {
46 #[inline]
47 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]
53 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
60impl flatbuffers::Push for Color {
61 type Output = Color;
62 #[inline]
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)]
69const ENUM_VALUES_COLOR:[Color; 3] = [
70 Color::Red,
71 Color::Green,
72 Color::Blue
73];
74
75#[allow(non_camel_case_types)]
76const ENUM_NAMES_COLOR:[&'static str; 3] = [
77 "Red",
78 "Green",
79 "Blue"
80];
81
82pub 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)]
90pub enum Equipment {
91 NONE = 0,
92 Weapon = 1
93}
94
95const ENUM_MIN_EQUIPMENT: u8 = 0;
96const ENUM_MAX_EQUIPMENT: u8 = 1;
97
98impl<'a> flatbuffers::Follow<'a> for Equipment {
99 type Inner = Self;
100 #[inline]
101 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
102 flatbuffers::read_scalar_at::<Self>(buf, loc)
103 }
104}
105
106impl flatbuffers::EndianScalar for Equipment {
107 #[inline]
108 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]
114 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
121impl flatbuffers::Push for Equipment {
122 type Output = Equipment;
123 #[inline]
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)]
130const ENUM_VALUES_EQUIPMENT:[Equipment; 2] = [
131 Equipment::NONE,
132 Equipment::Weapon
133];
134
135#[allow(non_camel_case_types)]
136const ENUM_NAMES_EQUIPMENT:[&'static str; 2] = [
137 "NONE",
138 "Weapon"
139];
140
141pub fn enum_name_equipment(e: Equipment) -> &'static str {
142 let index: usize = e as usize;
143 ENUM_NAMES_EQUIPMENT[index]
144}
145
146pub struct EquipmentUnionTableOffset {}
147// struct Vec3, aligned to 4
148#[repr(C, align(4))]
149#[derive(Clone, Copy, Debug, PartialEq)]
150pub struct Vec3 {
151 x_: f32,
152 y_: f32,
153 z_: f32,
154} // pub struct Vec3
155impl flatbuffers::SafeSliceAccess for Vec3 {}
156impl<'a> flatbuffers::Follow<'a> for Vec3 {
157 type Inner = &'a Vec3;
158 #[inline]
159 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}
164impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
165 type Inner = &'a Vec3;
166 #[inline]
167 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
168 flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
169 }
170}
171impl<'b> flatbuffers::Push for Vec3 {
172 type Output = Vec3;
173 #[inline]
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}
181impl<'b> flatbuffers::Push for &'b Vec3 {
182 type Output = Vec3;
183
184 #[inline]
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
194impl Vec3 {
195 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 }
203 pub fn x<'a>(&'a self) -> f32 {
204 self.x_.from_little_endian()
205 }
206 pub fn y<'a>(&'a self) -> f32 {
207 self.y_.from_little_endian()
208 }
209 pub fn z<'a>(&'a self) -> f32 {
210 self.z_.from_little_endian()
211 }
212}
213
214pub enum MonsterOffset {}
215#[derive(Copy, Clone, Debug, PartialEq)]
216
217pub struct Monster<'a> {
218 pub _tab: flatbuffers::Table<'a>,
219}
220
221impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
222 type Inner = Monster<'a>;
223 #[inline]
224 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
225 Self {
226 _tab: flatbuffers::Table { buf: buf, loc: loc },
227 }
228 }
229}
230
231impl<'a> Monster<'a> {
232 #[inline]
233 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
234 Monster {
235 _tab: table,
236 }
237 }
238 #[allow(unused_mut)]
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]
266 pub fn pos(&'a self) -> Option<&'a Vec3> {
267 self._tab.get::<Vec3>(Monster::VT_POS, None)
268 }
269 #[inline]
270 pub fn mana(&'a self) -> i16 {
271 self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
272 }
273 #[inline]
274 pub fn hp(&'a self) -> i16 {
275 self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
276 }
277 #[inline]
278 pub fn name(&'a self) -> Option<&'a str> {
279 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)
280 }
281 #[inline]
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]
286 pub fn color(&'a self) -> Color {
287 self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
288 }
289 #[inline]
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]
294 pub fn equipped_type(&'a self) -> Equipment {
295 self._tab.get::<Equipment>(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()
296 }
297 #[inline]
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)]
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
313pub 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}
324impl<'a> Default for MonsterArgs<'a> {
325 #[inline]
326 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}
340pub struct MonsterBuilder<'a: 'b, 'b> {
341 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
342 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
343}
344impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> {
345 #[inline]
346 pub fn add_pos(&mut self, pos: &'b Vec3) {
347 self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos);
348 }
349 #[inline]
350 pub fn add_mana(&mut self, mana: i16) {
351 self.fbb_.push_slot::<i16>(Monster::VT_MANA, mana, 150);
352 }
353 #[inline]
354 pub fn add_hp(&mut self, hp: i16) {
355 self.fbb_.push_slot::<i16>(Monster::VT_HP, hp, 100);
356 }
357 #[inline]
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]
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]
366 pub fn add_color(&mut self, color: Color) {
367 self.fbb_.push_slot::<Color>(Monster::VT_COLOR, color, Color::Blue);
368 }
369 #[inline]
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]
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]
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]
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]
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
396pub enum WeaponOffset {}
397#[derive(Copy, Clone, Debug, PartialEq)]
398
399pub struct Weapon<'a> {
400 pub _tab: flatbuffers::Table<'a>,
401}
402
403impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
404 type Inner = Weapon<'a>;
405 #[inline]
406 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
407 Self {
408 _tab: flatbuffers::Table { buf: buf, loc: loc },
409 }
410 }
411}
412
413impl<'a> Weapon<'a> {
414 #[inline]
415 pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
416 Weapon {
417 _tab: table,
418 }
419 }
420 #[allow(unused_mut)]
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]
434 pub fn name(&'a self) -> Option<&'a str> {
435 self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)
436 }
437 #[inline]
438 pub fn damage(&'a self) -> i16 {
439 self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()
440 }
441}
442
443pub struct WeaponArgs<'a> {
444 pub name: Option<flatbuffers::WIPOffset<&'a str>>,
445 pub damage: i16,
446}
447impl<'a> Default for WeaponArgs<'a> {
448 #[inline]
449 fn default() -> Self {
450 WeaponArgs {
451 name: None,
452 damage: 0,
453 }
454 }
455}
456pub struct WeaponBuilder<'a: 'b, 'b> {
457 fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
458 start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
459}
460impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> {
461 #[inline]
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]
466 pub fn add_damage(&mut self, damage: i16) {
467 self.fbb_.push_slot::<i16>(Weapon::VT_DAMAGE, damage, 0);
468 }
469 #[inline]
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]
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]
485pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
486 flatbuffers::get_root::<Monster<'a>>(buf)
487}
488
489#[inline]
490pub 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]
495pub 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]
502pub 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