...
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::*;
12// struct Test, aligned to 2
13#[repr(transparent)]
14#[derive(Clone, Copy, PartialEq)]
15pub struct Test(pub [u8; 4]);
16impl Default for Test {
17 fn default() -> Self {
18 Self([0; 4])
19 }
20}
21impl core::fmt::Debug for Test {
22 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
23 f.debug_struct("Test")
24 .field("a", &self.a())
25 .field("b", &self.b())
26 .finish()
27 }
28}
29
30impl flatbuffers::SimpleToVerifyInSlice for Test {}
31impl<'a> flatbuffers::Follow<'a> for Test {
32 type Inner = &'a Test;
33 #[inline]
34 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
35 <&'a Test>::follow(buf, loc)
36 }
37}
38impl<'a> flatbuffers::Follow<'a> for &'a Test {
39 type Inner = &'a Test;
40 #[inline]
41 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
42 flatbuffers::follow_cast_ref::<Test>(buf, loc)
43 }
44}
45impl<'b> flatbuffers::Push for Test {
46 type Output = Test;
47 #[inline]
48 unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
49 let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
50 dst.copy_from_slice(src);
51 }
52}
53
54impl<'a> flatbuffers::Verifiable for Test {
55 #[inline]
56 fn run_verifier(
57 v: &mut flatbuffers::Verifier, pos: usize
58 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
59 use self::flatbuffers::Verifiable;
60 v.in_buffer::<Self>(pos)
61 }
62}
63
64impl<'a> Test {
65 #[allow(clippy::too_many_arguments)]
66 pub fn new(
67 a: i16,
68 b: i8,
69 ) -> Self {
70 let mut s = Self([0; 4]);
71 s.set_a(a);
72 s.set_b(b);
73 s
74 }
75
76 pub const fn get_fully_qualified_name() -> &'static str {
77 "MyGame.Example.Test"
78 }
79
80 pub fn a(&self) -> i16 {
81 let mut mem = core::mem::MaybeUninit::<<i16 as EndianScalar>::Scalar>::uninit();
82 // Safety:
83 // Created from a valid Table for this object
84 // Which contains a valid value in this slot
85 EndianScalar::from_little_endian(unsafe {
86 core::ptr::copy_nonoverlapping(
87 self.0[0..].as_ptr(),
88 mem.as_mut_ptr() as *mut u8,
89 core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
90 );
91 mem.assume_init()
92 })
93 }
94
95 pub fn set_a(&mut self, x: i16) {
96 let x_le = x.to_little_endian();
97 // Safety:
98 // Created from a valid Table for this object
99 // Which contains a valid value in this slot
100 unsafe {
101 core::ptr::copy_nonoverlapping(
102 &x_le as *const _ as *const u8,
103 self.0[0..].as_mut_ptr(),
104 core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
105 );
106 }
107 }
108
109 pub fn b(&self) -> i8 {
110 let mut mem = core::mem::MaybeUninit::<<i8 as EndianScalar>::Scalar>::uninit();
111 // Safety:
112 // Created from a valid Table for this object
113 // Which contains a valid value in this slot
114 EndianScalar::from_little_endian(unsafe {
115 core::ptr::copy_nonoverlapping(
116 self.0[2..].as_ptr(),
117 mem.as_mut_ptr() as *mut u8,
118 core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
119 );
120 mem.assume_init()
121 })
122 }
123
124 pub fn set_b(&mut self, x: i8) {
125 let x_le = x.to_little_endian();
126 // Safety:
127 // Created from a valid Table for this object
128 // Which contains a valid value in this slot
129 unsafe {
130 core::ptr::copy_nonoverlapping(
131 &x_le as *const _ as *const u8,
132 self.0[2..].as_mut_ptr(),
133 core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
134 );
135 }
136 }
137
138 pub fn unpack(&self) -> TestT {
139 TestT {
140 a: self.a(),
141 b: self.b(),
142 }
143 }
144}
145
146#[derive(Debug, Clone, PartialEq, Default)]
147pub struct TestT {
148 pub a: i16,
149 pub b: i8,
150}
151impl TestT {
152 pub fn pack(&self) -> Test {
153 Test::new(
154 self.a,
155 self.b,
156 )
157 }
158}
159
View as plain text