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