use ALIGN for Push::alignment in struct types (#8398)
* use ALIGN for Push::alignment in struct types * regenerate and add a test for struct alignment
This commit is contained in:
parent
807adb73b2
commit
49061f8c7c
|
@ -52,7 +52,7 @@ pub use crate::builder::{Allocator, DefaultAllocator, FlatBufferBuilder};
|
|||
pub use crate::endian_scalar::{emplace_scalar, read_scalar, read_scalar_at, EndianScalar};
|
||||
pub use crate::follow::{Follow, FollowStart};
|
||||
pub use crate::primitives::*;
|
||||
pub use crate::push::Push;
|
||||
pub use crate::push::{Push, PushAlignment};
|
||||
pub use crate::table::{buffer_has_identifier, Table};
|
||||
pub use crate::vector::{follow_cast_ref, Vector, VectorIter};
|
||||
pub use crate::verifier::{
|
||||
|
|
|
@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for Vec3 {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Vec3 {
|
||||
|
|
|
@ -2703,6 +2703,10 @@ class RustGenerator : public BaseGenerator {
|
|||
"{{STRUCT_TY}} as *const u8, Self::size());";
|
||||
code_ += " dst.copy_from_slice(src);";
|
||||
code_ += " }";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn alignment() -> flatbuffers::PushAlignment {";
|
||||
code_ += " flatbuffers::PushAlignment::new({{ALIGN}})";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
|
||||
|
|
|
@ -53,6 +53,10 @@ impl<'b> flatbuffers::Push for ArrayStruct {
|
|||
let src = ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(8)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for ArrayStruct {
|
||||
|
|
|
@ -51,6 +51,10 @@ impl<'b> flatbuffers::Push for NestedStruct {
|
|||
let src = ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(8)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for NestedStruct {
|
||||
|
|
|
@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Unused {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Unused {
|
||||
|
|
|
@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Unused {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Unused {
|
||||
|
|
|
@ -49,6 +49,10 @@ impl<'b> flatbuffers::Push for Ability {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Ability {
|
||||
|
|
|
@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for StructOfStructs {
|
|||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for StructOfStructs {
|
||||
|
|
|
@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
|
|||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for StructOfStructsOfStructs {
|
||||
|
|
|
@ -49,6 +49,10 @@ impl<'b> flatbuffers::Push for Test {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(2)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Test {
|
||||
|
|
|
@ -53,6 +53,10 @@ impl<'b> flatbuffers::Push for Vec3 {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(8)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Vec3 {
|
||||
|
|
|
@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Unused {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Unused {
|
||||
|
|
|
@ -51,6 +51,10 @@ impl<'b> flatbuffers::Push for Ability {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Ability {
|
||||
|
|
|
@ -52,6 +52,10 @@ impl<'b> flatbuffers::Push for StructOfStructs {
|
|||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for StructOfStructs {
|
||||
|
|
|
@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
|
|||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for StructOfStructsOfStructs {
|
||||
|
|
|
@ -51,6 +51,10 @@ impl<'b> flatbuffers::Push for Test {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(2)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Test {
|
||||
|
|
|
@ -55,6 +55,10 @@ impl<'b> flatbuffers::Push for Vec3 {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(8)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Vec3 {
|
||||
|
|
|
@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for Unused {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Unused {
|
||||
|
|
|
@ -49,6 +49,10 @@ impl<'b> flatbuffers::Push for StructInNestedNS {
|
|||
let src = ::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for StructInNestedNS {
|
||||
|
|
|
@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Object {
|
|||
let src = ::core::slice::from_raw_parts(self as *const Object as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Object {
|
||||
|
|
|
@ -2422,6 +2422,14 @@ mod push_impls {
|
|||
0, 0, 0, 0,
|
||||
0, 0, 0, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_u8_generated_struct_alignment() {
|
||||
let mut b = flatbuffers::FlatBufferBuilder::new();
|
||||
b.push(1u8);
|
||||
b.push(my_game::example::Test::new(10, 20));
|
||||
check(&b, &[10, 0, 20, 0, 0, 1]);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in New Issue