1 // automatically generated by the FlatBuffers compiler, do not modify 2 // @generated 3 extern crate alloc; 4 extern crate flatbuffers; 5 use alloc::boxed::Box; 6 use alloc::string::{String, ToString}; 7 use alloc::vec::Vec; 8 use core::mem; 9 use core::cmp::Ordering; 10 use self::flatbuffers::{EndianScalar, Follow}; 11 use super::*; 12 // struct Test, aligned to 2 13 #[repr(transparent)] 14 #[derive(Clone, Copy, PartialEq)] 15 pub struct Test(pub [u8; 4]); 16 impl Default for Test { default() -> Self17 fn default() -> Self { 18 Self([0; 4]) 19 } 20 } 21 impl core::fmt::Debug for Test { fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result22 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 30 impl flatbuffers::SimpleToVerifyInSlice for Test {} 31 impl<'a> flatbuffers::Follow<'a> for Test { 32 type Inner = &'a Test; 33 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner34 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 35 <&'a Test>::follow(buf, loc) 36 } 37 } 38 impl<'a> flatbuffers::Follow<'a> for &'a Test { 39 type Inner = &'a Test; 40 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner41 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 42 flatbuffers::follow_cast_ref::<Test>(buf, loc) 43 } 44 } 45 impl<'b> flatbuffers::Push for Test { 46 type Output = Test; 47 #[inline] push(&self, dst: &mut [u8], _written_len: usize)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 as flatbuffers::Push>::size()); 50 dst.copy_from_slice(src); 51 } 52 #[inline] alignment() -> flatbuffers::PushAlignment53 fn alignment() -> flatbuffers::PushAlignment { 54 flatbuffers::PushAlignment::new(2) 55 } 56 } 57 58 impl<'a> flatbuffers::Verifiable for Test { 59 #[inline] run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>60 fn run_verifier( 61 v: &mut flatbuffers::Verifier, pos: usize 62 ) -> Result<(), flatbuffers::InvalidFlatbuffer> { 63 use self::flatbuffers::Verifiable; 64 v.in_buffer::<Self>(pos) 65 } 66 } 67 68 impl<'a> Test { 69 #[allow(clippy::too_many_arguments)] new( a: i16, b: i8, ) -> Self70 pub fn new( 71 a: i16, 72 b: i8, 73 ) -> Self { 74 let mut s = Self([0; 4]); 75 s.set_a(a); 76 s.set_b(b); 77 s 78 } 79 get_fully_qualified_name() -> &'static str80 pub const fn get_fully_qualified_name() -> &'static str { 81 "MyGame.Example.Test" 82 } 83 a(&self) -> i1684 pub fn a(&self) -> i16 { 85 let mut mem = core::mem::MaybeUninit::<<i16 as EndianScalar>::Scalar>::uninit(); 86 // Safety: 87 // Created from a valid Table for this object 88 // Which contains a valid value in this slot 89 EndianScalar::from_little_endian(unsafe { 90 core::ptr::copy_nonoverlapping( 91 self.0[0..].as_ptr(), 92 mem.as_mut_ptr() as *mut u8, 93 core::mem::size_of::<<i16 as EndianScalar>::Scalar>(), 94 ); 95 mem.assume_init() 96 }) 97 } 98 set_a(&mut self, x: i16)99 pub fn set_a(&mut self, x: i16) { 100 let x_le = x.to_little_endian(); 101 // Safety: 102 // Created from a valid Table for this object 103 // Which contains a valid value in this slot 104 unsafe { 105 core::ptr::copy_nonoverlapping( 106 &x_le as *const _ as *const u8, 107 self.0[0..].as_mut_ptr(), 108 core::mem::size_of::<<i16 as EndianScalar>::Scalar>(), 109 ); 110 } 111 } 112 b(&self) -> i8113 pub fn b(&self) -> i8 { 114 let mut mem = core::mem::MaybeUninit::<<i8 as EndianScalar>::Scalar>::uninit(); 115 // Safety: 116 // Created from a valid Table for this object 117 // Which contains a valid value in this slot 118 EndianScalar::from_little_endian(unsafe { 119 core::ptr::copy_nonoverlapping( 120 self.0[2..].as_ptr(), 121 mem.as_mut_ptr() as *mut u8, 122 core::mem::size_of::<<i8 as EndianScalar>::Scalar>(), 123 ); 124 mem.assume_init() 125 }) 126 } 127 set_b(&mut self, x: i8)128 pub fn set_b(&mut self, x: i8) { 129 let x_le = x.to_little_endian(); 130 // Safety: 131 // Created from a valid Table for this object 132 // Which contains a valid value in this slot 133 unsafe { 134 core::ptr::copy_nonoverlapping( 135 &x_le as *const _ as *const u8, 136 self.0[2..].as_mut_ptr(), 137 core::mem::size_of::<<i8 as EndianScalar>::Scalar>(), 138 ); 139 } 140 } 141 unpack(&self) -> TestT142 pub fn unpack(&self) -> TestT { 143 TestT { 144 a: self.a(), 145 b: self.b(), 146 } 147 } 148 } 149 150 #[derive(Debug, Clone, PartialEq, Default)] 151 pub struct TestT { 152 pub a: i16, 153 pub b: i8, 154 } 155 impl TestT { pack(&self) -> Test156 pub fn pack(&self) -> Test { 157 Test::new( 158 self.a, 159 self.b, 160 ) 161 } 162 } 163 164