mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-24 13:16:10 +00:00
Started implementation for private flags in rust (#7269)
Adds flag to the cpp to fix bad annotations in all the languages Addresses comments to the PR, and fixes logic for leaking annotations
This commit is contained in:
131
tests/private_annotation_test/object_generated.rs
Normal file
131
tests/private_annotation_test/object_generated.rs
Normal file
@@ -0,0 +1,131 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
// struct Object, aligned to 4
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub(crate) struct Object(pub [u8; 4]);
|
||||
impl Default for Object {
|
||||
fn default() -> Self {
|
||||
Self([0; 4])
|
||||
}
|
||||
}
|
||||
impl core::fmt::Debug for Object {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.debug_struct("Object")
|
||||
.field("value", &self.value())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Object {}
|
||||
impl flatbuffers::SafeSliceAccess for Object {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Object {
|
||||
type Inner = &'a Object;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Object>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Object {
|
||||
type Inner = &'a Object;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Object>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Object {
|
||||
type Output = Object;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Object as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Object {
|
||||
type Output = Object;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Object as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Object {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Object {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
value: i32,
|
||||
) -> Self {
|
||||
let mut s = Self([0; 4]);
|
||||
s.set_value(value);
|
||||
s
|
||||
}
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"Object"
|
||||
}
|
||||
|
||||
pub fn value(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
}
|
||||
|
||||
pub fn set_value(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> ObjectT {
|
||||
ObjectT {
|
||||
value: self.value(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub(crate) struct ObjectT {
|
||||
pub value: i32,
|
||||
}
|
||||
impl ObjectT {
|
||||
pub fn pack(&self) -> Object {
|
||||
Object::new(
|
||||
self.value,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user