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 extern crate serde; 11 use self::serde::ser::{Serialize, Serializer, SerializeStruct}; 12 use self::flatbuffers::{EndianScalar, Follow}; 13 use super::*; 14 // struct Test, aligned to 2 15 #[repr(transparent)] 16 #[derive(Clone, Copy, PartialEq)] 17 pub struct Test(pub [u8; 4]); 18 impl Default for Test { default() -> Self19 fn default() -> Self { 20 Self([0; 4]) 21 } 22 } 23 impl core::fmt::Debug for Test { fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result24 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 25 f.debug_struct("Test") 26 .field("a", &self.a()) 27 .field("b", &self.b()) 28 .finish() 29 } 30 } 31 32 impl flatbuffers::SimpleToVerifyInSlice for Test {} 33 impl flatbuffers::SafeSliceAccess for Test {} 34 impl<'a> flatbuffers::Follow<'a> for Test { 35 type Inner = &'a Test; 36 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner37 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 38 <&'a Test>::follow(buf, loc) 39 } 40 } 41 impl<'a> flatbuffers::Follow<'a> for &'a Test { 42 type Inner = &'a Test; 43 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner44 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 45 flatbuffers::follow_cast_ref::<Test>(buf, loc) 46 } 47 } 48 impl<'b> flatbuffers::Push for Test { 49 type Output = Test; 50 #[inline] push(&self, dst: &mut [u8], _rest: &[u8])51 fn push(&self, dst: &mut [u8], _rest: &[u8]) { 52 let src = unsafe { 53 ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size()) 54 }; 55 dst.copy_from_slice(src); 56 } 57 } 58 impl<'b> flatbuffers::Push for &'b Test { 59 type Output = Test; 60 61 #[inline] push(&self, dst: &mut [u8], _rest: &[u8])62 fn push(&self, dst: &mut [u8], _rest: &[u8]) { 63 let src = unsafe { 64 ::core::slice::from_raw_parts(*self as *const Test as *const u8, Self::size()) 65 }; 66 dst.copy_from_slice(src); 67 } 68 } 69 70 impl<'a> flatbuffers::Verifiable for Test { 71 #[inline] run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>72 fn run_verifier( 73 v: &mut flatbuffers::Verifier, pos: usize 74 ) -> Result<(), flatbuffers::InvalidFlatbuffer> { 75 use self::flatbuffers::Verifiable; 76 v.in_buffer::<Self>(pos) 77 } 78 } 79 80 impl Serialize for Test { serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer,81 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 82 where 83 S: Serializer, 84 { 85 let mut s = serializer.serialize_struct("Test", 2)?; 86 s.serialize_field("a", &self.a())?; 87 s.serialize_field("b", &self.b())?; 88 s.end() 89 } 90 } 91 92 impl<'a> Test { 93 #[allow(clippy::too_many_arguments)] new( a: i16, b: i8, ) -> Self94 pub fn new( 95 a: i16, 96 b: i8, 97 ) -> Self { 98 let mut s = Self([0; 4]); 99 s.set_a(a); 100 s.set_b(b); 101 s 102 } 103 get_fully_qualified_name() -> &'static str104 pub const fn get_fully_qualified_name() -> &'static str { 105 "MyGame.Example.Test" 106 } 107 a(&self) -> i16108 pub fn a(&self) -> i16 { 109 let mut mem = core::mem::MaybeUninit::<i16>::uninit(); 110 unsafe { 111 core::ptr::copy_nonoverlapping( 112 self.0[0..].as_ptr(), 113 mem.as_mut_ptr() as *mut u8, 114 core::mem::size_of::<i16>(), 115 ); 116 mem.assume_init() 117 }.from_little_endian() 118 } 119 set_a(&mut self, x: i16)120 pub fn set_a(&mut self, x: i16) { 121 let x_le = x.to_little_endian(); 122 unsafe { 123 core::ptr::copy_nonoverlapping( 124 &x_le as *const i16 as *const u8, 125 self.0[0..].as_mut_ptr(), 126 core::mem::size_of::<i16>(), 127 ); 128 } 129 } 130 b(&self) -> i8131 pub fn b(&self) -> i8 { 132 let mut mem = core::mem::MaybeUninit::<i8>::uninit(); 133 unsafe { 134 core::ptr::copy_nonoverlapping( 135 self.0[2..].as_ptr(), 136 mem.as_mut_ptr() as *mut u8, 137 core::mem::size_of::<i8>(), 138 ); 139 mem.assume_init() 140 }.from_little_endian() 141 } 142 set_b(&mut self, x: i8)143 pub fn set_b(&mut self, x: i8) { 144 let x_le = x.to_little_endian(); 145 unsafe { 146 core::ptr::copy_nonoverlapping( 147 &x_le as *const i8 as *const u8, 148 self.0[2..].as_mut_ptr(), 149 core::mem::size_of::<i8>(), 150 ); 151 } 152 } 153 unpack(&self) -> TestT154 pub fn unpack(&self) -> TestT { 155 TestT { 156 a: self.a(), 157 b: self.b(), 158 } 159 } 160 } 161 162 #[derive(Debug, Clone, PartialEq, Default)] 163 pub struct TestT { 164 pub a: i16, 165 pub b: i8, 166 } 167 impl TestT { pack(&self) -> Test168 pub fn pack(&self) -> Test { 169 Test::new( 170 self.a, 171 self.b, 172 ) 173 } 174 } 175 176