forked from BigfootDev/flatbuffers
Rust soundness fixes (#7518)
* Rust soundness fixes * Second pass * Make init_from_table unsafe * Remove SafeSliceAccess * Clippy * Remove create_vector_of_strings * More clippy * Remove deprecated root type accessors * More soundness fixes * Fix EndianScalar for bool * Add TriviallyTransmutable * Add debug assertions * Review comments * Review feedback
This commit is contained in:
committed by
GitHub
parent
dadbff5714
commit
374f8fb5fb
@@ -17,7 +17,6 @@ no_std = ["core2", "thiserror_core2"]
|
||||
serialize = ["serde"]
|
||||
|
||||
[dependencies]
|
||||
smallvec = "1.6.1"
|
||||
bitflags = "1.2.1"
|
||||
serde = { version = "1.0", optional = true }
|
||||
thiserror = { version = "1.0.30", optional = true }
|
||||
|
||||
@@ -37,14 +37,18 @@ where
|
||||
#[allow(clippy::len_without_is_empty)]
|
||||
#[allow(clippy::from_over_into)] // TODO(caspern): Go from From to Into.
|
||||
impl<'a, T: 'a, const N: usize> Array<'a, T, N> {
|
||||
/// # Safety
|
||||
///
|
||||
/// buf must be a contiguous array of `T`
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `buf.len()` is not `size_of::<T>() * N`
|
||||
#[inline(always)]
|
||||
pub fn new(buf: &'a [u8]) -> Self {
|
||||
assert!(size_of::<T>() * N == buf.len());
|
||||
pub unsafe fn new(buf: &'a [u8]) -> Self {
|
||||
assert_eq!(size_of::<T>() * N, buf.len());
|
||||
|
||||
Array {
|
||||
0: buf,
|
||||
1: PhantomData,
|
||||
}
|
||||
Array(buf, PhantomData)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -61,34 +65,39 @@ impl<'a, T: Follow<'a> + 'a, const N: usize> Array<'a, T, N> {
|
||||
pub fn get(&self, idx: usize) -> T::Inner {
|
||||
assert!(idx < N);
|
||||
let sz = size_of::<T>();
|
||||
T::follow(self.0, sz * idx)
|
||||
// Safety:
|
||||
// self.0 was valid for length `N` on construction and have verified `idx < N`
|
||||
unsafe { T::follow(self.0, sz * idx) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn iter(&self) -> VectorIter<'a, T> {
|
||||
VectorIter::from_slice(self.0, self.len())
|
||||
// Safety:
|
||||
// self.0 was valid for length N on construction
|
||||
unsafe { VectorIter::from_slice(self.0, self.len()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Follow<'a> + Debug, const N: usize> Into<[T::Inner; N]> for Array<'a, T, N> {
|
||||
#[inline(always)]
|
||||
fn into(self) -> [T::Inner; N] {
|
||||
array_init(|i| self.get(i))
|
||||
impl<'a, T: Follow<'a> + Debug, const N: usize> From<Array<'a, T, N>> for [T::Inner; N] {
|
||||
fn from(array: Array<'a, T, N>) -> Self {
|
||||
array_init(|i| array.get(i))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(caspern): Implement some future safe version of SafeSliceAccess.
|
||||
|
||||
/// Implement Follow for all possible Arrays that have Follow-able elements.
|
||||
impl<'a, T: Follow<'a> + 'a, const N: usize> Follow<'a> for Array<'a, T, N> {
|
||||
type Inner = Array<'a, T, N>;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Array::new(&buf[loc..loc + N * size_of::<T>()])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn emplace_scalar_array<T: EndianScalar, const N: usize>(
|
||||
/// Place an array of EndianScalar into the provided mutable byte slice. Performs
|
||||
/// endian conversion, if necessary.
|
||||
/// # Safety
|
||||
/// Caller must ensure `s.len() >= size_of::<[T; N]>()`
|
||||
pub unsafe fn emplace_scalar_array<T: EndianScalar, const N: usize>(
|
||||
buf: &mut [u8],
|
||||
loc: usize,
|
||||
src: &[T; N],
|
||||
@@ -96,14 +105,12 @@ pub fn emplace_scalar_array<T: EndianScalar, const N: usize>(
|
||||
let mut buf_ptr = buf[loc..].as_mut_ptr();
|
||||
for item in src.iter() {
|
||||
let item_le = item.to_little_endian();
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&item_le as *const T as *const u8,
|
||||
buf_ptr,
|
||||
size_of::<T>(),
|
||||
);
|
||||
buf_ptr = buf_ptr.add(size_of::<T>());
|
||||
}
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&item_le as *const T::Scalar as *const u8,
|
||||
buf_ptr,
|
||||
size_of::<T::Scalar>(),
|
||||
);
|
||||
buf_ptr = buf_ptr.add(size_of::<T::Scalar>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +131,8 @@ where
|
||||
let mut array: core::mem::MaybeUninit<[T; N]> = core::mem::MaybeUninit::uninit();
|
||||
let mut ptr_i = array.as_mut_ptr() as *mut T;
|
||||
|
||||
// Safety:
|
||||
// array is aligned by T, and has length N
|
||||
unsafe {
|
||||
for i in 0..N {
|
||||
let value_i = initializer(i);
|
||||
@@ -134,7 +143,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="serialize")]
|
||||
#[cfg(feature = "serialize")]
|
||||
impl<'a, T: 'a, const N: usize> serde::ser::Serialize for Array<'a, T, N>
|
||||
where
|
||||
T: 'a + Follow<'a>,
|
||||
|
||||
@@ -14,26 +14,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
extern crate smallvec;
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
use alloc::{vec, vec::Vec};
|
||||
use core::cmp::max;
|
||||
use core::iter::{DoubleEndedIterator, ExactSizeIterator};
|
||||
use core::marker::PhantomData;
|
||||
use core::ptr::write_bytes;
|
||||
use core::slice::from_raw_parts;
|
||||
#[cfg(feature = "no_std")]
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
use crate::endian_scalar::{emplace_scalar, read_scalar_at};
|
||||
use crate::endian_scalar::emplace_scalar;
|
||||
use crate::primitives::*;
|
||||
use crate::push::{Push, PushAlignment};
|
||||
use crate::read_scalar;
|
||||
use crate::table::Table;
|
||||
use crate::vector::{SafeSliceAccess, Vector};
|
||||
use crate::vector::Vector;
|
||||
use crate::vtable::{field_index_to_field_offset, VTable};
|
||||
use crate::vtable_writer::VTableWriter;
|
||||
|
||||
pub const N_SMALLVEC_STRING_VECTOR_CAPACITY: usize = 16;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
struct FieldLoc {
|
||||
off: UOffsetT,
|
||||
@@ -121,6 +117,8 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
{
|
||||
let to_clear = self.owned_buf.len() - self.head;
|
||||
let ptr = (&mut self.owned_buf[self.head..]).as_mut_ptr();
|
||||
// Safety:
|
||||
// Verified ptr is valid for `to_clear` above
|
||||
unsafe {
|
||||
write_bytes(ptr, 0, to_clear);
|
||||
}
|
||||
@@ -153,7 +151,9 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
self.make_space(sz);
|
||||
{
|
||||
let (dst, rest) = (&mut self.owned_buf[self.head..]).split_at_mut(sz);
|
||||
x.push(dst, rest);
|
||||
// Safety:
|
||||
// Called make_space above
|
||||
unsafe { x.push(dst, rest.len()) };
|
||||
}
|
||||
WIPOffset::new(self.used_space() as UOffsetT)
|
||||
}
|
||||
@@ -309,73 +309,32 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
WIPOffset::new(self.used_space() as UOffsetT)
|
||||
}
|
||||
|
||||
/// Create a vector by memcpy'ing. This is much faster than calling
|
||||
/// `create_vector`, but the underlying type must be represented as
|
||||
/// little-endian on the host machine. This property is encoded in the
|
||||
/// type system through the SafeSliceAccess trait. The following types are
|
||||
/// always safe, on any platform: bool, u8, i8, and any
|
||||
/// FlatBuffers-generated struct.
|
||||
#[inline]
|
||||
pub fn create_vector_direct<'a: 'b, 'b, T: SafeSliceAccess + Push + Sized + 'b>(
|
||||
&'a mut self,
|
||||
items: &'b [T],
|
||||
) -> WIPOffset<Vector<'fbb, T>> {
|
||||
self.assert_not_nested(
|
||||
"create_vector_direct can not be called when a table or vector is under construction",
|
||||
);
|
||||
let elem_size = T::size();
|
||||
self.align(items.len() * elem_size, T::alignment().max_of(SIZE_UOFFSET));
|
||||
|
||||
let bytes = {
|
||||
let ptr = items.as_ptr() as *const T as *const u8;
|
||||
unsafe { from_raw_parts(ptr, items.len() * elem_size) }
|
||||
};
|
||||
self.push_bytes_unprefixed(bytes);
|
||||
self.push(items.len() as UOffsetT);
|
||||
|
||||
WIPOffset::new(self.used_space() as UOffsetT)
|
||||
}
|
||||
|
||||
/// Create a vector of strings.
|
||||
///
|
||||
/// Speed-sensitive users may wish to reduce memory usage by creating the
|
||||
/// vector manually: use `start_vector`, `push`, and `end_vector`.
|
||||
#[inline]
|
||||
pub fn create_vector_of_strings<'a, 'b>(
|
||||
&'a mut self,
|
||||
xs: &'b [&'b str],
|
||||
) -> WIPOffset<Vector<'fbb, ForwardsUOffset<&'fbb str>>> {
|
||||
self.assert_not_nested("create_vector_of_strings can not be called when a table or vector is under construction");
|
||||
// internally, smallvec can be a stack-allocated or heap-allocated vector:
|
||||
// if xs.len() > N_SMALLVEC_STRING_VECTOR_CAPACITY then it will overflow to the heap.
|
||||
let mut offsets: smallvec::SmallVec<[WIPOffset<&str>; N_SMALLVEC_STRING_VECTOR_CAPACITY]> =
|
||||
smallvec::SmallVec::with_capacity(xs.len());
|
||||
unsafe {
|
||||
offsets.set_len(xs.len());
|
||||
}
|
||||
|
||||
// note that this happens in reverse, because the buffer is built back-to-front:
|
||||
for (i, &s) in xs.iter().enumerate().rev() {
|
||||
let o = self.create_string(s);
|
||||
offsets[i] = o;
|
||||
}
|
||||
self.create_vector(&offsets[..])
|
||||
}
|
||||
|
||||
/// Create a vector of Push-able objects.
|
||||
///
|
||||
/// Speed-sensitive users may wish to reduce memory usage by creating the
|
||||
/// vector manually: use `start_vector`, `push`, and `end_vector`.
|
||||
#[inline]
|
||||
pub fn create_vector<'a: 'b, 'b, T: Push + Copy + 'b>(
|
||||
pub fn create_vector<'a: 'b, 'b, T: Push + 'b>(
|
||||
&'a mut self,
|
||||
items: &'b [T],
|
||||
) -> WIPOffset<Vector<'fbb, T::Output>> {
|
||||
let elem_size = T::size();
|
||||
self.align(items.len() * elem_size, T::alignment().max_of(SIZE_UOFFSET));
|
||||
for i in (0..items.len()).rev() {
|
||||
self.push(items[i]);
|
||||
let slice_size = items.len() * elem_size;
|
||||
self.align(slice_size, T::alignment().max_of(SIZE_UOFFSET));
|
||||
self.ensure_capacity(slice_size + UOffsetT::size());
|
||||
|
||||
self.head -= slice_size;
|
||||
let mut written_len = self.owned_buf.len() - self.head;
|
||||
|
||||
let buf = &mut self.owned_buf[self.head..self.head + slice_size];
|
||||
for (item, out) in items.iter().zip(buf.chunks_exact_mut(elem_size)) {
|
||||
written_len -= elem_size;
|
||||
|
||||
// Safety:
|
||||
// Called ensure_capacity and aligned to T above
|
||||
unsafe { item.push(out, written_len) };
|
||||
}
|
||||
|
||||
WIPOffset::new(self.push::<UOffsetT>(items.len() as UOffsetT).value())
|
||||
}
|
||||
|
||||
@@ -384,17 +343,18 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
/// Speed-sensitive users may wish to reduce memory usage by creating the
|
||||
/// vector manually: use `start_vector`, `push`, and `end_vector`.
|
||||
#[inline]
|
||||
pub fn create_vector_from_iter<T: Push + Copy>(
|
||||
pub fn create_vector_from_iter<T: Push>(
|
||||
&mut self,
|
||||
items: impl ExactSizeIterator<Item = T> + DoubleEndedIterator,
|
||||
) -> WIPOffset<Vector<'fbb, T::Output>> {
|
||||
let elem_size = T::size();
|
||||
let len = items.len();
|
||||
self.align(len * elem_size, T::alignment().max_of(SIZE_UOFFSET));
|
||||
self.align(items.len() * elem_size, T::alignment().max_of(SIZE_UOFFSET));
|
||||
let mut actual = 0;
|
||||
for item in items.rev() {
|
||||
self.push(item);
|
||||
actual += 1;
|
||||
}
|
||||
WIPOffset::new(self.push::<UOffsetT>(len as UOffsetT).value())
|
||||
WIPOffset::new(self.push::<UOffsetT>(actual).value())
|
||||
}
|
||||
|
||||
/// Set whether default values are stored.
|
||||
@@ -443,7 +403,15 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
assert_msg_name: &'static str,
|
||||
) {
|
||||
let idx = self.used_space() - tab_revloc.value() as usize;
|
||||
let tab = Table::new(&self.owned_buf[self.head..], idx);
|
||||
|
||||
// Safety:
|
||||
// The value of TableFinishedWIPOffset is the offset from the end of owned_buf
|
||||
// to an SOffsetT pointing to a valid VTable
|
||||
//
|
||||
// `self.owned_buf.len() = self.used_space() + self.head`
|
||||
// `self.owned_buf.len() - tab_revloc = self.used_space() - tab_revloc + self.head`
|
||||
// `self.owned_buf.len() - tab_revloc = idx + self.head`
|
||||
let tab = unsafe { Table::new(&self.owned_buf[self.head..], idx) };
|
||||
let o = tab.vtable().get(slot_byte_loc) as usize;
|
||||
assert!(o != 0, "missing required field {}", assert_msg_name);
|
||||
}
|
||||
@@ -560,11 +528,15 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
}
|
||||
}
|
||||
let new_vt_bytes = &self.owned_buf[vt_start_pos..vt_end_pos];
|
||||
let found = self.written_vtable_revpos.binary_search_by(|old_vtable_revpos: &UOffsetT| {
|
||||
let old_vtable_pos = self.owned_buf.len() - *old_vtable_revpos as usize;
|
||||
let old_vtable = VTable::init(&self.owned_buf, old_vtable_pos);
|
||||
new_vt_bytes.cmp(old_vtable.as_bytes())
|
||||
});
|
||||
let found = self
|
||||
.written_vtable_revpos
|
||||
.binary_search_by(|old_vtable_revpos: &UOffsetT| {
|
||||
let old_vtable_pos = self.owned_buf.len() - *old_vtable_revpos as usize;
|
||||
// Safety:
|
||||
// Already written vtables are valid by construction
|
||||
let old_vtable = unsafe { VTable::init(&self.owned_buf, old_vtable_pos) };
|
||||
new_vt_bytes.cmp(old_vtable.as_bytes())
|
||||
});
|
||||
let final_vtable_revpos = match found {
|
||||
Ok(i) => {
|
||||
// The new vtable is a duplicate so clear it.
|
||||
@@ -581,12 +553,22 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
};
|
||||
// Write signed offset from table to its vtable.
|
||||
let table_pos = self.owned_buf.len() - object_revloc_to_vtable.value() as usize;
|
||||
let tmp_soffset_to_vt = unsafe { read_scalar_at::<UOffsetT>(&self.owned_buf, table_pos) };
|
||||
debug_assert_eq!(tmp_soffset_to_vt, 0xF0F0_F0F0);
|
||||
if cfg!(debug_assertions) {
|
||||
// Safety:
|
||||
// Verified slice length
|
||||
let tmp_soffset_to_vt = unsafe {
|
||||
read_scalar::<UOffsetT>(&self.owned_buf[table_pos..table_pos + SIZE_UOFFSET])
|
||||
};
|
||||
assert_eq!(tmp_soffset_to_vt, 0xF0F0_F0F0);
|
||||
}
|
||||
|
||||
let buf = &mut self.owned_buf[table_pos..table_pos + SIZE_SOFFSET];
|
||||
// Safety:
|
||||
// Verified length of buf above
|
||||
unsafe {
|
||||
emplace_scalar::<SOffsetT>(
|
||||
&mut self.owned_buf[table_pos..table_pos + SIZE_SOFFSET],
|
||||
final_vtable_revpos as SOffsetT - object_revloc_to_vtable.value() as SOffsetT
|
||||
buf,
|
||||
final_vtable_revpos as SOffsetT - object_revloc_to_vtable.value() as SOffsetT,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -624,6 +606,8 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
|
||||
// finally, zero out the old end data.
|
||||
{
|
||||
let ptr = (&mut self.owned_buf[..middle]).as_mut_ptr();
|
||||
// Safety:
|
||||
// ptr is byte aligned and of length middle
|
||||
unsafe {
|
||||
write_bytes(ptr, 0, middle);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,24 @@
|
||||
|
||||
use core::mem::size_of;
|
||||
|
||||
mod private {
|
||||
/// Types that are trivially transmutable are those where any combination of bits
|
||||
/// represents a valid value of that type
|
||||
///
|
||||
/// For example integral types are TriviallyTransmutable as all bit patterns are valid,
|
||||
/// however, `bool` is not trivially transmutable as only `0` and `1` are valid
|
||||
pub trait TriviallyTransmutable {}
|
||||
|
||||
impl TriviallyTransmutable for i8 {}
|
||||
impl TriviallyTransmutable for i16 {}
|
||||
impl TriviallyTransmutable for i32 {}
|
||||
impl TriviallyTransmutable for i64 {}
|
||||
impl TriviallyTransmutable for u8 {}
|
||||
impl TriviallyTransmutable for u16 {}
|
||||
impl TriviallyTransmutable for u32 {}
|
||||
impl TriviallyTransmutable for u64 {}
|
||||
}
|
||||
|
||||
/// Trait for values that must be stored in little-endian byte order, but
|
||||
/// might be represented in memory as big-endian. Every type that implements
|
||||
/// EndianScalar is a valid FlatBuffers scalar value.
|
||||
@@ -28,144 +46,118 @@ use core::mem::size_of;
|
||||
/// "too much". For example, num-traits provides i128 support, but that is an
|
||||
/// invalid FlatBuffers type.
|
||||
pub trait EndianScalar: Sized + PartialEq + Copy + Clone {
|
||||
fn to_little_endian(self) -> Self;
|
||||
fn from_little_endian(self) -> Self;
|
||||
}
|
||||
type Scalar: private::TriviallyTransmutable;
|
||||
|
||||
/// Macro for implementing a no-op endian conversion. This is used for types
|
||||
/// that are one byte wide.
|
||||
macro_rules! impl_endian_scalar_noop {
|
||||
($ty:ident) => {
|
||||
impl EndianScalar for $ty {
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
};
|
||||
fn to_little_endian(self) -> Self::Scalar;
|
||||
|
||||
fn from_little_endian(v: Self::Scalar) -> Self;
|
||||
}
|
||||
|
||||
/// Macro for implementing an endian conversion using the stdlib `to_le` and
|
||||
/// `from_le` functions. This is used for integer types. It is not used for
|
||||
/// floats, because the `to_le` and `from_le` are not implemented for them in
|
||||
/// the stdlib.
|
||||
macro_rules! impl_endian_scalar_stdlib_le_conversion {
|
||||
macro_rules! impl_endian_scalar {
|
||||
($ty:ident) => {
|
||||
impl EndianScalar for $ty {
|
||||
type Scalar = Self;
|
||||
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
fn to_little_endian(self) -> Self::Scalar {
|
||||
Self::to_le(self)
|
||||
}
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
Self::from_le(self)
|
||||
fn from_little_endian(v: Self::Scalar) -> Self {
|
||||
Self::from_le(v)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_endian_scalar_noop!(bool);
|
||||
impl_endian_scalar_noop!(u8);
|
||||
impl_endian_scalar_noop!(i8);
|
||||
impl_endian_scalar!(u8);
|
||||
impl_endian_scalar!(i8);
|
||||
impl_endian_scalar!(u16);
|
||||
impl_endian_scalar!(u32);
|
||||
impl_endian_scalar!(u64);
|
||||
impl_endian_scalar!(i16);
|
||||
impl_endian_scalar!(i32);
|
||||
impl_endian_scalar!(i64);
|
||||
|
||||
impl_endian_scalar_stdlib_le_conversion!(u16);
|
||||
impl_endian_scalar_stdlib_le_conversion!(u32);
|
||||
impl_endian_scalar_stdlib_le_conversion!(u64);
|
||||
impl_endian_scalar_stdlib_le_conversion!(i16);
|
||||
impl_endian_scalar_stdlib_le_conversion!(i32);
|
||||
impl_endian_scalar_stdlib_le_conversion!(i64);
|
||||
impl EndianScalar for bool {
|
||||
type Scalar = u8;
|
||||
|
||||
fn to_little_endian(self) -> Self::Scalar {
|
||||
self as u8
|
||||
}
|
||||
|
||||
fn from_little_endian(v: Self::Scalar) -> Self {
|
||||
v != 0
|
||||
}
|
||||
}
|
||||
|
||||
impl EndianScalar for f32 {
|
||||
type Scalar = u32;
|
||||
/// Convert f32 from host endian-ness to little-endian.
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
#[cfg(target_endian = "little")]
|
||||
{
|
||||
self
|
||||
}
|
||||
#[cfg(not(target_endian = "little"))]
|
||||
{
|
||||
byte_swap_f32(self)
|
||||
}
|
||||
fn to_little_endian(self) -> u32 {
|
||||
// Floats and Ints have the same endianness on all supported platforms.
|
||||
// <https://doc.rust-lang.org/std/primitive.f32.html#method.from_bits>
|
||||
self.to_bits().to_le()
|
||||
}
|
||||
/// Convert f32 from little-endian to host endian-ness.
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
#[cfg(target_endian = "little")]
|
||||
{
|
||||
self
|
||||
}
|
||||
#[cfg(not(target_endian = "little"))]
|
||||
{
|
||||
byte_swap_f32(self)
|
||||
}
|
||||
fn from_little_endian(v: u32) -> Self {
|
||||
// Floats and Ints have the same endianness on all supported platforms.
|
||||
// <https://doc.rust-lang.org/std/primitive.f32.html#method.from_bits>
|
||||
f32::from_bits(u32::from_le(v))
|
||||
}
|
||||
}
|
||||
|
||||
impl EndianScalar for f64 {
|
||||
type Scalar = u64;
|
||||
|
||||
/// Convert f64 from host endian-ness to little-endian.
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
#[cfg(target_endian = "little")]
|
||||
{
|
||||
self
|
||||
}
|
||||
#[cfg(not(target_endian = "little"))]
|
||||
{
|
||||
byte_swap_f64(self)
|
||||
}
|
||||
fn to_little_endian(self) -> u64 {
|
||||
// Floats and Ints have the same endianness on all supported platforms.
|
||||
// <https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits>
|
||||
self.to_bits().to_le()
|
||||
}
|
||||
/// Convert f64 from little-endian to host endian-ness.
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
#[cfg(target_endian = "little")]
|
||||
{
|
||||
self
|
||||
}
|
||||
#[cfg(not(target_endian = "little"))]
|
||||
{
|
||||
byte_swap_f64(self)
|
||||
}
|
||||
fn from_little_endian(v: u64) -> Self {
|
||||
// Floats and Ints have the same endianness on all supported platforms.
|
||||
// <https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits>
|
||||
f64::from_bits(u64::from_le(v))
|
||||
}
|
||||
}
|
||||
|
||||
/// Swaps the bytes of an f32.
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn byte_swap_f32(x: f32) -> f32 {
|
||||
f32::from_bits(x.to_bits().swap_bytes())
|
||||
}
|
||||
|
||||
/// Swaps the bytes of an f64.
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn byte_swap_f64(x: f64) -> f64 {
|
||||
f64::from_bits(x.to_bits().swap_bytes())
|
||||
}
|
||||
|
||||
/// Place an EndianScalar into the provided mutable byte slice. Performs
|
||||
/// endian conversion, if necessary.
|
||||
/// # Safety
|
||||
/// Caller must ensure `s.len() > size_of::<T>()`
|
||||
/// and `x` does not overlap with `s`.
|
||||
/// Caller must ensure `s.len() >= size_of::<T>()`
|
||||
#[inline]
|
||||
pub unsafe fn emplace_scalar<T: EndianScalar>(s: &mut [u8], x: T) {
|
||||
let size = size_of::<T::Scalar>();
|
||||
debug_assert!(
|
||||
s.len() >= size,
|
||||
"insufficient capacity for emplace_scalar, needed {} got {}",
|
||||
size,
|
||||
s.len()
|
||||
);
|
||||
|
||||
let x_le = x.to_little_endian();
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const T as *const u8,
|
||||
&x_le as *const T::Scalar as *const u8,
|
||||
s.as_mut_ptr() as *mut u8,
|
||||
size_of::<T>(),
|
||||
size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Read an EndianScalar from the provided byte slice at the specified location.
|
||||
/// Performs endian conversion, if necessary.
|
||||
/// # Safety
|
||||
/// Caller must ensure `s.len() > loc + size_of::<T>()`.
|
||||
/// Caller must ensure `s.len() >= loc + size_of::<T>()`.
|
||||
#[inline]
|
||||
pub unsafe fn read_scalar_at<T: EndianScalar>(s: &[u8], loc: usize) -> T {
|
||||
read_scalar(&s[loc..])
|
||||
@@ -177,8 +169,20 @@ pub unsafe fn read_scalar_at<T: EndianScalar>(s: &[u8], loc: usize) -> T {
|
||||
/// Caller must ensure `s.len() > size_of::<T>()`.
|
||||
#[inline]
|
||||
pub unsafe fn read_scalar<T: EndianScalar>(s: &[u8]) -> T {
|
||||
let mut mem = core::mem::MaybeUninit::<T>::uninit();
|
||||
let size = size_of::<T::Scalar>();
|
||||
debug_assert!(
|
||||
s.len() >= size,
|
||||
"insufficient capacity for emplace_scalar, needed {} got {}",
|
||||
size,
|
||||
s.len()
|
||||
);
|
||||
|
||||
let mut mem = core::mem::MaybeUninit::<T::Scalar>::uninit();
|
||||
// Since [u8] has alignment 1, we copy it into T which may have higher alignment.
|
||||
core::ptr::copy_nonoverlapping(s.as_ptr(), mem.as_mut_ptr() as *mut u8, size_of::<T>());
|
||||
mem.assume_init().from_little_endian()
|
||||
core::ptr::copy_nonoverlapping(
|
||||
s.as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
size,
|
||||
);
|
||||
T::from_little_endian(mem.assume_init())
|
||||
}
|
||||
|
||||
@@ -29,7 +29,11 @@ use core::marker::PhantomData;
|
||||
/// continue traversing the FlatBuffer.
|
||||
pub trait Follow<'buf> {
|
||||
type Inner;
|
||||
fn follow(buf: &'buf [u8], loc: usize) -> Self::Inner;
|
||||
/// # Safety
|
||||
///
|
||||
/// `buf[loc..]` must contain a valid value of `Self` and anything it
|
||||
/// transitively refers to by offset must also be valid
|
||||
unsafe fn follow(buf: &'buf [u8], loc: usize) -> Self::Inner;
|
||||
}
|
||||
|
||||
/// FollowStart wraps a Follow impl in a struct type. This can make certain
|
||||
@@ -39,17 +43,21 @@ pub struct FollowStart<T>(PhantomData<T>);
|
||||
impl<'a, T: Follow<'a> + 'a> FollowStart<T> {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Self { 0: PhantomData }
|
||||
Self(PhantomData)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// `buf[loc..]` must contain a valid value of `T`
|
||||
#[inline]
|
||||
pub fn self_follow(&'a self, buf: &'a [u8], loc: usize) -> T::Inner {
|
||||
pub unsafe fn self_follow(&'a self, buf: &'a [u8], loc: usize) -> T::Inner {
|
||||
T::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a, T: Follow<'a>> Follow<'a> for FollowStart<T> {
|
||||
type Inner = T::Inner;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
T::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ where
|
||||
{
|
||||
let mut v = Verifier::new(opts, data);
|
||||
<ForwardsUOffset<T>>::run_verifier(&mut v, 0)?;
|
||||
// Safety:
|
||||
// Run verifier above
|
||||
Ok(unsafe { root_unchecked::<T>(data) })
|
||||
}
|
||||
|
||||
@@ -75,6 +77,8 @@ where
|
||||
{
|
||||
let mut v = Verifier::new(opts, data);
|
||||
<SkipSizePrefix<ForwardsUOffset<T>>>::run_verifier(&mut v, 0)?;
|
||||
// Safety:
|
||||
// Run verifier above
|
||||
Ok(unsafe { size_prefixed_root_unchecked::<T>(data) })
|
||||
}
|
||||
|
||||
|
||||
@@ -48,14 +48,12 @@ mod vtable_writer;
|
||||
|
||||
pub use crate::array::{array_init, emplace_scalar_array, Array};
|
||||
pub use crate::builder::FlatBufferBuilder;
|
||||
pub use crate::endian_scalar::{
|
||||
byte_swap_f32, byte_swap_f64, emplace_scalar, read_scalar, read_scalar_at, EndianScalar,
|
||||
};
|
||||
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::table::{buffer_has_identifier, Table};
|
||||
pub use crate::vector::{follow_cast_ref, SafeSliceAccess, Vector, VectorIter};
|
||||
pub use crate::vector::{follow_cast_ref, Vector, VectorIter};
|
||||
pub use crate::verifier::{
|
||||
ErrorTraceDetail, InvalidFlatbuffer, SimpleToVerifyInSlice, Verifiable, Verifier,
|
||||
VerifierOptions,
|
||||
@@ -64,6 +62,4 @@ pub use crate::vtable::field_index_to_field_offset;
|
||||
pub use bitflags;
|
||||
pub use get_root::*;
|
||||
|
||||
// TODO(rw): Unify `create_vector` and `create_vector_direct` by using
|
||||
// `Into<Vector<...>>`.
|
||||
// TODO(rw): Split fill ops in builder into fill_small, fill_big like in C++.
|
||||
|
||||
@@ -112,10 +112,7 @@ impl<'a, T: 'a> WIPOffset<T> {
|
||||
/// Create a new WIPOffset.
|
||||
#[inline]
|
||||
pub fn new(o: UOffsetT) -> WIPOffset<T> {
|
||||
WIPOffset {
|
||||
0: o,
|
||||
1: PhantomData,
|
||||
}
|
||||
WIPOffset(o, PhantomData)
|
||||
}
|
||||
|
||||
/// Return a wrapped value that brings its meaning as a union WIPOffset
|
||||
@@ -135,11 +132,9 @@ impl<T> Push for WIPOffset<T> {
|
||||
type Output = ForwardsUOffset<T>;
|
||||
|
||||
#[inline(always)]
|
||||
fn push(&self, dst: &mut [u8], rest: &[u8]) {
|
||||
let n = (SIZE_UOFFSET + rest.len() - self.value() as usize) as UOffsetT;
|
||||
unsafe {
|
||||
emplace_scalar::<UOffsetT>(dst, n);
|
||||
}
|
||||
unsafe fn push(&self, dst: &mut [u8], written_len: usize) {
|
||||
let n = (SIZE_UOFFSET + written_len - self.value() as usize) as UOffsetT;
|
||||
emplace_scalar::<UOffsetT>(dst, n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,8 +142,8 @@ impl<T> Push for ForwardsUOffset<T> {
|
||||
type Output = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn push(&self, dst: &mut [u8], rest: &[u8]) {
|
||||
self.value().push(dst, rest);
|
||||
unsafe fn push(&self, dst: &mut [u8], written_len: usize) {
|
||||
self.value().push(dst, written_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,9 +174,9 @@ impl<T> ForwardsUOffset<T> {
|
||||
impl<'a, T: Follow<'a>> Follow<'a> for ForwardsUOffset<T> {
|
||||
type Inner = T::Inner;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let slice = &buf[loc..loc + SIZE_UOFFSET];
|
||||
let off = unsafe { read_scalar::<u32>(slice) as usize };
|
||||
let off = read_scalar::<u32>(slice) as usize;
|
||||
T::follow(buf, loc + off)
|
||||
}
|
||||
}
|
||||
@@ -200,9 +195,9 @@ impl<T> ForwardsVOffset<T> {
|
||||
impl<'a, T: Follow<'a>> Follow<'a> for ForwardsVOffset<T> {
|
||||
type Inner = T::Inner;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let slice = &buf[loc..loc + SIZE_VOFFSET];
|
||||
let off = unsafe { read_scalar::<VOffsetT>(slice) as usize };
|
||||
let off = read_scalar::<VOffsetT>(slice) as usize;
|
||||
T::follow(buf, loc + off)
|
||||
}
|
||||
}
|
||||
@@ -211,8 +206,8 @@ impl<T> Push for ForwardsVOffset<T> {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], rest: &[u8]) {
|
||||
self.value().push(dst, rest);
|
||||
unsafe fn push(&self, dst: &mut [u8], written_len: usize) {
|
||||
self.value().push(dst, written_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,9 +225,9 @@ impl<T> BackwardsSOffset<T> {
|
||||
impl<'a, T: Follow<'a>> Follow<'a> for BackwardsSOffset<T> {
|
||||
type Inner = T::Inner;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let slice = &buf[loc..loc + SIZE_SOFFSET];
|
||||
let off = unsafe { read_scalar::<SOffsetT>(slice) };
|
||||
let off = read_scalar::<SOffsetT>(slice);
|
||||
T::follow(buf, (loc as SOffsetT - off) as usize)
|
||||
}
|
||||
}
|
||||
@@ -241,8 +236,8 @@ impl<T> Push for BackwardsSOffset<T> {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], rest: &[u8]) {
|
||||
self.value().push(dst, rest);
|
||||
unsafe fn push(&self, dst: &mut [u8], written_len: usize) {
|
||||
self.value().push(dst, written_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +247,7 @@ pub struct SkipSizePrefix<T>(PhantomData<T>);
|
||||
impl<'a, T: Follow<'a> + 'a> Follow<'a> for SkipSizePrefix<T> {
|
||||
type Inner = T::Inner;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
T::follow(buf, loc + SIZE_SIZEPREFIX)
|
||||
}
|
||||
}
|
||||
@@ -263,7 +258,7 @@ pub struct SkipRootOffset<T>(PhantomData<T>);
|
||||
impl<'a, T: Follow<'a> + 'a> Follow<'a> for SkipRootOffset<T> {
|
||||
type Inner = T::Inner;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
T::follow(buf, loc + SIZE_UOFFSET)
|
||||
}
|
||||
}
|
||||
@@ -274,7 +269,7 @@ pub struct FileIdentifier;
|
||||
impl<'a> Follow<'a> for FileIdentifier {
|
||||
type Inner = &'a [u8];
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
&buf[loc..loc + FILE_IDENTIFIER_LENGTH]
|
||||
}
|
||||
}
|
||||
@@ -286,7 +281,7 @@ pub struct SkipFileIdentifier<T>(PhantomData<T>);
|
||||
impl<'a, T: Follow<'a> + 'a> Follow<'a> for SkipFileIdentifier<T> {
|
||||
type Inner = T::Inner;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
T::follow(buf, loc + FILE_IDENTIFIER_LENGTH)
|
||||
}
|
||||
}
|
||||
@@ -294,8 +289,8 @@ impl<'a, T: Follow<'a> + 'a> Follow<'a> for SkipFileIdentifier<T> {
|
||||
impl<'a> Follow<'a> for bool {
|
||||
type Inner = bool;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { read_scalar_at::<u8>(buf, loc) != 0 }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
read_scalar_at::<u8>(buf, loc) != 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,8 +304,8 @@ macro_rules! impl_follow_for_endian_scalar {
|
||||
impl<'a> Follow<'a> for $ty {
|
||||
type Inner = $ty;
|
||||
#[inline(always)]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { read_scalar_at::<$ty>(buf, loc) }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
read_scalar_at::<$ty>(buf, loc)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,7 +24,11 @@ use crate::endian_scalar::emplace_scalar;
|
||||
/// types.
|
||||
pub trait Push: Sized {
|
||||
type Output;
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]);
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// dst is aligned to [`Self::alignment`] and has length greater than or equal to [`Self::size`]
|
||||
unsafe fn push(&self, dst: &mut [u8], written_len: usize);
|
||||
#[inline]
|
||||
fn size() -> usize {
|
||||
size_of::<Self::Output>()
|
||||
@@ -35,13 +39,29 @@ pub trait Push: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Push> Push for &'a T {
|
||||
type Output = T::Output;
|
||||
|
||||
unsafe fn push(&self, dst: &mut [u8], written_len: usize) {
|
||||
T::push(self, dst, written_len)
|
||||
}
|
||||
|
||||
fn size() -> usize {
|
||||
T::size()
|
||||
}
|
||||
|
||||
fn alignment() -> PushAlignment {
|
||||
T::alignment()
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure Push alignment calculations are typesafe (because this helps reduce
|
||||
/// implementation issues when using FlatBufferBuilder::align).
|
||||
pub struct PushAlignment(usize);
|
||||
impl PushAlignment {
|
||||
#[inline]
|
||||
pub fn new(x: usize) -> Self {
|
||||
PushAlignment { 0: x }
|
||||
PushAlignment(x)
|
||||
}
|
||||
#[inline]
|
||||
pub fn value(&self) -> usize {
|
||||
@@ -60,10 +80,8 @@ macro_rules! impl_push_for_endian_scalar {
|
||||
type Output = $ty;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe {
|
||||
emplace_scalar::<$ty>(dst, *self);
|
||||
}
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
emplace_scalar::<$ty>(dst, *self);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,23 +18,36 @@ use crate::follow::Follow;
|
||||
use crate::primitives::*;
|
||||
use crate::vtable::VTable;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Table<'a> {
|
||||
pub buf: &'a [u8],
|
||||
pub loc: usize,
|
||||
buf: &'a [u8],
|
||||
loc: usize,
|
||||
}
|
||||
|
||||
impl<'a> Table<'a> {
|
||||
/// # Safety
|
||||
///
|
||||
/// `buf` must contain a `soffset_t` at `loc`, which points to a valid vtable
|
||||
#[inline]
|
||||
pub fn new(buf: &'a [u8], loc: usize) -> Self {
|
||||
pub unsafe fn new(buf: &'a [u8], loc: usize) -> Self {
|
||||
Table { buf, loc }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn vtable(&self) -> VTable<'a> {
|
||||
<BackwardsSOffset<VTable<'a>>>::follow(self.buf, self.loc)
|
||||
// Safety:
|
||||
// Table::new is created with a valid buf and location
|
||||
unsafe { <BackwardsSOffset<VTable<'a>>>::follow(self.buf, self.loc) }
|
||||
}
|
||||
|
||||
/// Retrieves the value at the provided `slot_byte_loc` returning `default`
|
||||
/// if no value present
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The value of the corresponding slot must have type T
|
||||
#[inline]
|
||||
pub fn get<T: Follow<'a> + 'a>(
|
||||
pub unsafe fn get<T: Follow<'a> + 'a>(
|
||||
&self,
|
||||
slot_byte_loc: VOffsetT,
|
||||
default: Option<T::Inner>,
|
||||
@@ -50,19 +63,26 @@ impl<'a> Table<'a> {
|
||||
impl<'a> Follow<'a> for Table<'a> {
|
||||
type Inner = Table<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Table { buf, loc }
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if data contains a prefix of `ident`
|
||||
#[inline]
|
||||
pub fn buffer_has_identifier(data: &[u8], ident: &str, size_prefixed: bool) -> bool {
|
||||
assert_eq!(ident.len(), FILE_IDENTIFIER_LENGTH);
|
||||
|
||||
let got = if size_prefixed {
|
||||
<SkipSizePrefix<SkipRootOffset<FileIdentifier>>>::follow(data, 0)
|
||||
assert!(data.len() >= SIZE_SIZEPREFIX + SIZE_UOFFSET + FILE_IDENTIFIER_LENGTH);
|
||||
// Safety:
|
||||
// Verified data has sufficient bytes
|
||||
unsafe { <SkipSizePrefix<SkipRootOffset<FileIdentifier>>>::follow(data, 0) }
|
||||
} else {
|
||||
<SkipRootOffset<FileIdentifier>>::follow(data, 0)
|
||||
assert!(data.len() >= SIZE_UOFFSET + FILE_IDENTIFIER_LENGTH);
|
||||
// Safety:
|
||||
// Verified data has sufficient bytes
|
||||
unsafe { <SkipRootOffset<FileIdentifier>>::follow(data, 0) }
|
||||
};
|
||||
|
||||
ident.as_bytes() == got
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
use core::fmt::{Debug, Formatter, Result};
|
||||
use core::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator};
|
||||
use core::marker::PhantomData;
|
||||
use core::mem::size_of;
|
||||
use core::slice::from_raw_parts;
|
||||
use core::mem::{align_of, size_of};
|
||||
use core::str::from_utf8_unchecked;
|
||||
|
||||
use crate::endian_scalar::read_scalar_at;
|
||||
#[cfg(target_endian = "little")]
|
||||
use crate::endian_scalar::EndianScalar;
|
||||
use crate::follow::Follow;
|
||||
use crate::primitives::*;
|
||||
|
||||
@@ -55,6 +52,7 @@ where
|
||||
// and Clone for `T: Copy` and `T: Clone` respectively. However `Vector<'a, T>`
|
||||
// can always be copied, no matter that `T` you have.
|
||||
impl<'a, T> Copy for Vector<'a, T> {}
|
||||
|
||||
impl<'a, T> Clone for Vector<'a, T> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
@@ -62,32 +60,46 @@ impl<'a, T> Clone for Vector<'a, T> {
|
||||
}
|
||||
|
||||
impl<'a, T: 'a> Vector<'a, T> {
|
||||
/// # Safety
|
||||
///
|
||||
/// `buf` contains a valid vector at `loc` consisting of
|
||||
///
|
||||
/// - UOffsetT element count
|
||||
/// - Consecutive list of `T` elements
|
||||
#[inline(always)]
|
||||
pub fn new(buf: &'a [u8], loc: usize) -> Self {
|
||||
Vector {
|
||||
0: buf,
|
||||
1: loc,
|
||||
2: PhantomData,
|
||||
}
|
||||
pub unsafe fn new(buf: &'a [u8], loc: usize) -> Self {
|
||||
Vector(buf, loc, PhantomData)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn len(&self) -> usize {
|
||||
// Safety:
|
||||
// Valid vector at time of construction starting with UOffsetT element count
|
||||
unsafe { read_scalar_at::<UOffsetT>(self.0, self.1) as usize }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn bytes(&self) -> &'a [u8] {
|
||||
let sz = size_of::<T>();
|
||||
let len = self.len();
|
||||
&self.0[self.1 + SIZE_UOFFSET..self.1 + SIZE_UOFFSET + sz * len]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Follow<'a> + 'a> Vector<'a, T> {
|
||||
#[inline(always)]
|
||||
pub fn get(&self, idx: usize) -> T::Inner {
|
||||
assert!(idx < self.len() as usize);
|
||||
assert!(idx < self.len());
|
||||
let sz = size_of::<T>();
|
||||
debug_assert!(sz > 0);
|
||||
T::follow(self.0, self.1 as usize + SIZE_UOFFSET + sz * idx)
|
||||
// Safety:
|
||||
// Valid vector at time of construction, verified that idx < element count
|
||||
unsafe { T::follow(self.0, self.1 as usize + SIZE_UOFFSET + sz * idx) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -96,84 +108,40 @@ impl<'a, T: Follow<'a> + 'a> Vector<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SafeSliceAccess {}
|
||||
impl<'a, T: SafeSliceAccess + 'a> Vector<'a, T> {
|
||||
pub fn safe_slice(self) -> &'a [T] {
|
||||
let buf = self.0;
|
||||
let loc = self.1;
|
||||
let sz = size_of::<T>();
|
||||
debug_assert!(sz > 0);
|
||||
let len = unsafe { read_scalar_at::<UOffsetT>(buf, loc) } as usize;
|
||||
let data_buf = &buf[loc + SIZE_UOFFSET..loc + SIZE_UOFFSET + len * sz];
|
||||
let ptr = data_buf.as_ptr() as *const T;
|
||||
let s: &'a [T] = unsafe { from_raw_parts(ptr, len) };
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
impl SafeSliceAccess for u8 {}
|
||||
impl SafeSliceAccess for i8 {}
|
||||
impl SafeSliceAccess for bool {}
|
||||
|
||||
// TODO(caspern): Get rid of this. Conditional compliation is unnecessary complexity.
|
||||
// Vectors of primitives just don't work on big endian machines!!!
|
||||
#[cfg(target_endian = "little")]
|
||||
mod le_safe_slice_impls {
|
||||
impl super::SafeSliceAccess for u16 {}
|
||||
impl super::SafeSliceAccess for u32 {}
|
||||
impl super::SafeSliceAccess for u64 {}
|
||||
|
||||
impl super::SafeSliceAccess for i16 {}
|
||||
impl super::SafeSliceAccess for i32 {}
|
||||
impl super::SafeSliceAccess for i64 {}
|
||||
|
||||
impl super::SafeSliceAccess for f32 {}
|
||||
impl super::SafeSliceAccess for f64 {}
|
||||
}
|
||||
|
||||
#[cfg(target_endian = "little")]
|
||||
pub use self::le_safe_slice_impls::*;
|
||||
|
||||
pub fn follow_cast_ref<'a, T: Sized + 'a>(buf: &'a [u8], loc: usize) -> &'a T {
|
||||
/// # Safety
|
||||
///
|
||||
/// `buf` must contain a value of T at `loc` and have alignment of 1
|
||||
pub unsafe fn follow_cast_ref<'a, T: Sized + 'a>(buf: &'a [u8], loc: usize) -> &'a T {
|
||||
assert_eq!(align_of::<T>(), 1);
|
||||
let sz = size_of::<T>();
|
||||
let buf = &buf[loc..loc + sz];
|
||||
let ptr = buf.as_ptr() as *const T;
|
||||
unsafe { &*ptr }
|
||||
// SAFETY
|
||||
// buf contains a value at loc of type T and T has no alignment requirements
|
||||
&*ptr
|
||||
}
|
||||
|
||||
impl<'a> Follow<'a> for &'a str {
|
||||
type Inner = &'a str;
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let len = unsafe { read_scalar_at::<UOffsetT>(buf, loc) } as usize;
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let len = read_scalar_at::<UOffsetT>(buf, loc) as usize;
|
||||
let slice = &buf[loc + SIZE_UOFFSET..loc + SIZE_UOFFSET + len];
|
||||
unsafe { from_utf8_unchecked(slice) }
|
||||
from_utf8_unchecked(slice)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_endian = "little")]
|
||||
fn follow_slice_helper<T>(buf: &[u8], loc: usize) -> &[T] {
|
||||
let sz = size_of::<T>();
|
||||
debug_assert!(sz > 0);
|
||||
let len = unsafe { read_scalar_at::<UOffsetT>(buf, loc) as usize };
|
||||
let data_buf = &buf[loc + SIZE_UOFFSET..loc + SIZE_UOFFSET + len * sz];
|
||||
let ptr = data_buf.as_ptr() as *const T;
|
||||
let s: &[T] = unsafe { from_raw_parts(ptr, len) };
|
||||
s
|
||||
}
|
||||
|
||||
/// Implement direct slice access if the host is little-endian.
|
||||
#[cfg(target_endian = "little")]
|
||||
impl<'a, T: EndianScalar> Follow<'a> for &'a [T] {
|
||||
type Inner = &'a [T];
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
follow_slice_helper::<T>(buf, loc)
|
||||
impl<'a> Follow<'a> for &'a [u8] {
|
||||
type Inner = &'a [u8];
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let len = read_scalar_at::<UOffsetT>(buf, loc) as usize;
|
||||
&buf[loc + SIZE_UOFFSET..loc + SIZE_UOFFSET + len]
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement Follow for all possible Vectors that have Follow-able elements.
|
||||
impl<'a, T: Follow<'a> + 'a> Follow<'a> for Vector<'a, T> {
|
||||
type Inner = Vector<'a, T>;
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Vector::new(buf, loc)
|
||||
}
|
||||
}
|
||||
@@ -201,8 +169,14 @@ impl<'a, T: 'a> VectorIter<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new `VectorIter` from the provided slice
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// buf must contain a contiguous sequence of `items_num` values of `T`
|
||||
///
|
||||
#[inline]
|
||||
pub fn from_slice(buf: &'a [u8], items_num: usize) -> Self {
|
||||
pub unsafe fn from_slice(buf: &'a [u8], items_num: usize) -> Self {
|
||||
VectorIter {
|
||||
buf,
|
||||
loc: 0,
|
||||
@@ -235,7 +209,10 @@ impl<'a, T: Follow<'a> + 'a> Iterator for VectorIter<'a, T> {
|
||||
if self.remaining == 0 {
|
||||
None
|
||||
} else {
|
||||
let result = T::follow(self.buf, self.loc);
|
||||
// Safety:
|
||||
// VectorIter can only be created from a contiguous sequence of `items_num`
|
||||
// And remaining is initialized to `items_num`
|
||||
let result = unsafe { T::follow(self.buf, self.loc) };
|
||||
self.loc += sz;
|
||||
self.remaining -= 1;
|
||||
Some(result)
|
||||
@@ -272,7 +249,10 @@ impl<'a, T: Follow<'a> + 'a> DoubleEndedIterator for VectorIter<'a, T> {
|
||||
None
|
||||
} else {
|
||||
self.remaining -= 1;
|
||||
Some(T::follow(self.buf, self.loc + sz * self.remaining))
|
||||
// Safety:
|
||||
// VectorIter can only be created from a contiguous sequence of `items_num`
|
||||
// And remaining is initialized to `items_num`
|
||||
Some(unsafe { T::follow(self.buf, self.loc + sz * self.remaining) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +289,7 @@ impl<'a, 'b, T: Follow<'a> + 'a> IntoIterator for &'b Vector<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="serialize")]
|
||||
#[cfg(feature = "serialize")]
|
||||
impl<'a, T> serde::ser::Serialize for Vector<'a, T>
|
||||
where
|
||||
T: 'a + Follow<'a>,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::follow::Follow;
|
||||
use crate::{ForwardsUOffset, SOffsetT, SkipSizePrefix, UOffsetT, VOffsetT, Vector, SIZE_UOFFSET};
|
||||
#[cfg(feature = "no_std")]
|
||||
use alloc::vec::Vec;
|
||||
use core::ops::Range;
|
||||
use core::option::Option;
|
||||
use crate::follow::Follow;
|
||||
use crate::{ForwardsUOffset, SOffsetT, SkipSizePrefix, UOffsetT, VOffsetT, Vector, SIZE_UOFFSET};
|
||||
|
||||
#[cfg(feature="no_std")]
|
||||
use thiserror_core2::Error;
|
||||
#[cfg(not(feature="no_std"))]
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use thiserror::Error;
|
||||
#[cfg(feature = "no_std")]
|
||||
use thiserror_core2::Error;
|
||||
|
||||
/// Traces the location of data errors. Not populated for Dos detecting errors.
|
||||
/// Useful for MissingRequiredField and Utf8Error in particular, though
|
||||
@@ -28,8 +28,10 @@ pub enum ErrorTraceDetail {
|
||||
position: usize,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Default, Debug, Clone)]
|
||||
pub struct ErrorTrace(Vec<ErrorTraceDetail>);
|
||||
|
||||
impl core::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &[ErrorTraceDetail] {
|
||||
@@ -63,7 +65,7 @@ pub enum InvalidFlatbuffer {
|
||||
error_trace: ErrorTrace,
|
||||
},
|
||||
#[error("String in range [{}, {}) is missing its null terminator.\n{error_trace}",
|
||||
range.start, range.end)]
|
||||
range.start, range.end)]
|
||||
MissingNullTerminator {
|
||||
range: Range<usize>,
|
||||
error_trace: ErrorTrace,
|
||||
@@ -184,6 +186,7 @@ fn trace_field<T>(res: Result<T>, field_name: &'static str, position: usize) ->
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Adds a TableField trace detail if `res` is a data error.
|
||||
fn trace_elem<T>(res: Result<T>, index: usize, position: usize) -> Result<T> {
|
||||
append_trace(res, ErrorTraceDetail::VectorElement { index, position })
|
||||
@@ -205,6 +208,7 @@ pub struct VerifierOptions {
|
||||
// options to error un-recognized enums and unions? possible footgun.
|
||||
// Ignore nested flatbuffers, etc?
|
||||
}
|
||||
|
||||
impl Default for VerifierOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -226,6 +230,7 @@ pub struct Verifier<'opts, 'buf> {
|
||||
num_tables: usize,
|
||||
apparent_size: usize,
|
||||
}
|
||||
|
||||
impl<'opts, 'buf> Verifier<'opts, 'buf> {
|
||||
pub fn new(opts: &'opts VerifierOptions, buffer: &'buf [u8]) -> Self {
|
||||
Self {
|
||||
@@ -247,9 +252,12 @@ impl<'opts, 'buf> Verifier<'opts, 'buf> {
|
||||
/// memory since `buffer: &[u8]` has alignment 1.
|
||||
///
|
||||
/// ### WARNING
|
||||
///
|
||||
/// This does not work for flatbuffers-structs as they have alignment 1 according to
|
||||
/// `core::mem::align_of` but are meant to have higher alignment within a Flatbuffer w.r.t.
|
||||
/// `buffer[0]`. TODO(caspern).
|
||||
///
|
||||
/// Note this does not impact soundness as this crate does not assume alignment of structs
|
||||
#[inline]
|
||||
fn is_aligned<T>(&self, pos: usize) -> Result<()> {
|
||||
if pos % core::mem::align_of::<T>() == 0 {
|
||||
@@ -307,9 +315,9 @@ impl<'opts, 'buf> Verifier<'opts, 'buf> {
|
||||
|
||||
// signed offsets are subtracted.
|
||||
let derefed = if offset > 0 {
|
||||
pos.checked_sub(offset.abs() as usize)
|
||||
pos.checked_sub(offset.unsigned_abs() as usize)
|
||||
} else {
|
||||
pos.checked_add(offset.abs() as usize)
|
||||
pos.checked_add(offset.unsigned_abs() as usize)
|
||||
};
|
||||
if let Some(x) = derefed {
|
||||
if x < self.buffer.len() {
|
||||
@@ -372,6 +380,7 @@ pub struct TableVerifier<'ver, 'opts, 'buf> {
|
||||
// Verifier struct which holds the surrounding state and options.
|
||||
verifier: &'ver mut Verifier<'opts, 'buf>,
|
||||
}
|
||||
|
||||
impl<'ver, 'opts, 'buf> TableVerifier<'ver, 'opts, 'buf> {
|
||||
fn deref(&mut self, field: VOffsetT) -> Result<Option<usize>> {
|
||||
let field = field as usize;
|
||||
@@ -439,7 +448,9 @@ impl<'ver, 'opts, 'buf> TableVerifier<'ver, 'opts, 'buf> {
|
||||
}
|
||||
(Some(k), Some(v)) => {
|
||||
trace_field(Key::run_verifier(self.verifier, k), key_field_name, k)?;
|
||||
let discriminant = Key::follow(self.verifier.buffer, k);
|
||||
// Safety:
|
||||
// Run verifier on `k` above
|
||||
let discriminant = unsafe { Key::follow(self.verifier.buffer, k) };
|
||||
trace_field(
|
||||
verify_union(discriminant, self.verifier, v),
|
||||
val_field_name,
|
||||
@@ -486,16 +497,27 @@ fn verify_vector_range<T>(v: &mut Verifier, pos: usize) -> Result<core::ops::Ran
|
||||
}
|
||||
|
||||
pub trait SimpleToVerifyInSlice {}
|
||||
|
||||
impl SimpleToVerifyInSlice for bool {}
|
||||
|
||||
impl SimpleToVerifyInSlice for i8 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for u8 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for i16 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for u16 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for i32 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for u32 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for f32 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for i64 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for u64 {}
|
||||
|
||||
impl SimpleToVerifyInSlice for f64 {}
|
||||
|
||||
impl<T: SimpleToVerifyInSlice> Verifiable for Vector<'_, T> {
|
||||
|
||||
@@ -33,24 +33,42 @@ impl<'a> PartialEq for VTable<'a> {
|
||||
}
|
||||
|
||||
impl<'a> VTable<'a> {
|
||||
pub fn init(buf: &'a [u8], loc: usize) -> Self {
|
||||
/// SAFETY
|
||||
/// `buf` must contain a valid vtable at `loc`
|
||||
///
|
||||
/// This consists of a number of `VOffsetT`
|
||||
/// - size of vtable in bytes including size element
|
||||
/// - size of object in bytes including the vtable offset
|
||||
/// - n fields where n is the number of fields in the table's schema when the code was compiled
|
||||
pub unsafe fn init(buf: &'a [u8], loc: usize) -> Self {
|
||||
VTable { buf, loc }
|
||||
}
|
||||
|
||||
pub fn num_fields(&self) -> usize {
|
||||
(self.num_bytes() / SIZE_VOFFSET) - 2
|
||||
}
|
||||
|
||||
pub fn num_bytes(&self) -> usize {
|
||||
// Safety:
|
||||
// Valid VTable at time of construction
|
||||
unsafe { read_scalar_at::<VOffsetT>(self.buf, self.loc) as usize }
|
||||
}
|
||||
|
||||
pub fn object_inline_num_bytes(&self) -> usize {
|
||||
// Safety:
|
||||
// Valid VTable at time of construction
|
||||
let n = unsafe { read_scalar_at::<VOffsetT>(self.buf, self.loc + SIZE_VOFFSET) };
|
||||
n as usize
|
||||
}
|
||||
|
||||
pub fn get_field(&self, idx: usize) -> VOffsetT {
|
||||
// TODO(rw): distinguish between None and 0?
|
||||
if idx > self.num_fields() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Safety:
|
||||
// Valid VTable at time of construction
|
||||
unsafe {
|
||||
read_scalar_at::<VOffsetT>(
|
||||
self.buf,
|
||||
@@ -58,13 +76,17 @@ impl<'a> VTable<'a> {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, byte_loc: VOffsetT) -> VOffsetT {
|
||||
// TODO(rw): distinguish between None and 0?
|
||||
if byte_loc as usize >= self.num_bytes() {
|
||||
if byte_loc as usize + 2 > self.num_bytes() {
|
||||
return 0;
|
||||
}
|
||||
// Safety:
|
||||
// byte_loc is within bounds of vtable, which was valid at time of construction
|
||||
unsafe { read_scalar_at::<VOffsetT>(self.buf, self.loc + byte_loc as usize) }
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
let len = self.num_bytes();
|
||||
&self.buf[self.loc..self.loc + len]
|
||||
@@ -87,7 +109,7 @@ pub fn field_offset_to_field_index(field_o: VOffsetT) -> VOffsetT {
|
||||
|
||||
impl<'a> Follow<'a> for VTable<'a> {
|
||||
type Inner = VTable<'a>;
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
VTable::init(buf, loc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,11 @@ impl<'a> VTableWriter<'a> {
|
||||
/// to the provided value.
|
||||
#[inline(always)]
|
||||
pub fn write_vtable_byte_length(&mut self, n: VOffsetT) {
|
||||
let buf = &mut self.buf[..SIZE_VOFFSET];
|
||||
// Safety:
|
||||
// Validated range above
|
||||
unsafe {
|
||||
emplace_scalar::<VOffsetT>(&mut self.buf[..SIZE_VOFFSET], n);
|
||||
emplace_scalar::<VOffsetT>(buf, n);
|
||||
}
|
||||
debug_assert_eq!(n as usize, self.buf.len());
|
||||
}
|
||||
@@ -49,8 +52,11 @@ impl<'a> VTableWriter<'a> {
|
||||
/// Writes an object length (in bytes) into the vtable.
|
||||
#[inline(always)]
|
||||
pub fn write_object_inline_size(&mut self, n: VOffsetT) {
|
||||
let buf = &mut self.buf[SIZE_VOFFSET..2 * SIZE_VOFFSET];
|
||||
// Safety:
|
||||
// Validated range above
|
||||
unsafe {
|
||||
emplace_scalar::<VOffsetT>(&mut self.buf[SIZE_VOFFSET..2 * SIZE_VOFFSET], n);
|
||||
emplace_scalar::<VOffsetT>(buf, n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +67,11 @@ impl<'a> VTableWriter<'a> {
|
||||
#[inline(always)]
|
||||
pub fn write_field_offset(&mut self, vtable_offset: VOffsetT, object_data_offset: VOffsetT) {
|
||||
let idx = vtable_offset as usize;
|
||||
let buf = &mut self.buf[idx..idx + SIZE_VOFFSET];
|
||||
// Safety:
|
||||
// Validated range above
|
||||
unsafe {
|
||||
emplace_scalar::<VOffsetT>(&mut self.buf[idx..idx + SIZE_VOFFSET], object_data_offset);
|
||||
emplace_scalar::<VOffsetT>(buf, object_data_offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +82,9 @@ impl<'a> VTableWriter<'a> {
|
||||
// This is the closest thing to memset in Rust right now.
|
||||
let len = self.buf.len();
|
||||
let p = self.buf.as_mut_ptr() as *mut u8;
|
||||
|
||||
// Safety:
|
||||
// p is byte aligned and of length `len`
|
||||
unsafe {
|
||||
write_bytes(p, 0, len);
|
||||
}
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for Color {
|
||||
impl<'a> flatbuffers::Follow<'a> for Color {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for Color {
|
||||
impl flatbuffers::Push for Color {
|
||||
type Output = Color;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Color {
|
||||
type Scalar = i8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i8::from_le(self.0);
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
let b = i8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +55,8 @@ impl core::fmt::Debug for Equipment {
|
||||
impl<'a> flatbuffers::Follow<'a> for Equipment {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -66,21 +64,21 @@ impl<'a> flatbuffers::Follow<'a> for Equipment {
|
||||
impl flatbuffers::Push for Equipment {
|
||||
type Output = Equipment;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Equipment {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct Monster<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl<'a> Monster<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Monster { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -73,7 +73,7 @@ impl<'a> Monster<'a> {
|
||||
x.to_string()
|
||||
});
|
||||
let inventory = self.inventory().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let color = self.color();
|
||||
let weapons = self.weapons().map(|x| {
|
||||
@@ -106,49 +106,84 @@ impl<'a> Monster<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn pos(&self) -> Option<&'a Vec3> {
|
||||
self._tab.get::<Vec3>(Monster::VT_POS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Vec3>(Monster::VT_POS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn mana(&self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn hp(&self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn name(&self) -> Option<&'a str> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn inventory(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
|
||||
pub fn inventory(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color(&self) -> Color {
|
||||
self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn weapons(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon>>>>(Monster::VT_WEAPONS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon>>>>(Monster::VT_WEAPONS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn equipped_type(&self) -> Equipment {
|
||||
self._tab.get::<Equipment>(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Equipment>(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn equipped(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_EQUIPPED, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_EQUIPPED, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn path(&self) -> Option<&'a [Vec3]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Vec3>>>(Monster::VT_PATH, None).map(|v| v.safe_slice())
|
||||
pub fn path(&self) -> Option<flatbuffers::Vector<'a, Vec3>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Vec3>>>(Monster::VT_PATH, None)}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn equipped_as_weapon(&self) -> Option<Weapon<'a>> {
|
||||
if self.equipped_type() == Equipment::Weapon {
|
||||
self.equipped().map(Weapon::init_from_table)
|
||||
self.equipped().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Weapon::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -365,18 +400,6 @@ impl MonsterT {
|
||||
})
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
unsafe { flatbuffers::root_unchecked::<Monster<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a `Monster`
|
||||
/// and returns it.
|
||||
|
||||
@@ -29,39 +29,25 @@ impl core::fmt::Debug for Vec3 {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Vec3 {}
|
||||
impl flatbuffers::SafeSliceAccess for Vec3 {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Vec3>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Vec3 {
|
||||
type Output = Vec3;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Vec3 {
|
||||
type Output = Vec3;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -95,70 +81,88 @@ impl<'a> Vec3 {
|
||||
}
|
||||
|
||||
pub fn x(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_x(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn y(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_y(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn z(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[8..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_z(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[8..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct Weapon<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
|
||||
type Inner = Weapon<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<'a> Weapon<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Weapon { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -60,11 +60,17 @@ impl<'a> Weapon<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn name(&self) -> Option<&'a str> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn damage(&self) -> i16 {
|
||||
self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,10 +122,7 @@ fn main() {
|
||||
// Get an element from the `inventory` FlatBuffer's `vector`.
|
||||
assert!(monster.inventory().is_some());
|
||||
let inv = monster.inventory().unwrap();
|
||||
|
||||
// Note that this vector is returned as a slice, because direct access for
|
||||
// this type, a u8 vector, is safe on all platforms:
|
||||
let third_item = inv[2];
|
||||
let third_item = inv.get(2);
|
||||
assert_eq!(third_item, 2);
|
||||
|
||||
// Get and test the `weapons` FlatBuffers's `vector`.
|
||||
|
||||
@@ -737,7 +737,6 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += "pub use self::bitflags_{{ENUM_NAMESPACE}}::{{ENUM_TY}};";
|
||||
code_ += "";
|
||||
|
||||
code_.SetValue("FROM_BASE", "unsafe { Self::from_bits_unchecked(b) }");
|
||||
code_.SetValue("INTO_BASE", "self.bits()");
|
||||
} else {
|
||||
// Normal, c-modelled enums.
|
||||
@@ -810,7 +809,6 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
|
||||
code_.SetValue("FROM_BASE", "Self(b)");
|
||||
code_.SetValue("INTO_BASE", "self.0");
|
||||
}
|
||||
|
||||
@@ -839,35 +837,55 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += "impl<'a> flatbuffers::Follow<'a> for {{ENUM_TY}} {";
|
||||
code_ += " type Inner = Self;";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " let b = unsafe {";
|
||||
code_ += " flatbuffers::read_scalar_at::<{{BASE_TYPE}}>(buf, loc)";
|
||||
code_ += " };";
|
||||
code_ += " {{FROM_BASE}}";
|
||||
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " let b = flatbuffers::read_scalar_at::<{{BASE_TYPE}}>(buf, loc);";
|
||||
if (IsBitFlagsEnum(enum_def)) {
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
code_ += " // Safety:";
|
||||
code_ += " // This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.";
|
||||
code_ += " // from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0";
|
||||
code_ += " // https://github.com/bitflags/bitflags/issues/262";
|
||||
code_ += " Self::from_bits_unchecked(b)";
|
||||
} else {
|
||||
code_ += " Self(b)";
|
||||
}
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
code_ += "impl flatbuffers::Push for {{ENUM_TY}} {";
|
||||
code_ += " type Output = {{ENUM_TY}};";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {";
|
||||
code_ +=
|
||||
" unsafe { flatbuffers::emplace_scalar::<{{BASE_TYPE}}>"
|
||||
"(dst, {{INTO_BASE}}); }";
|
||||
code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {";
|
||||
code_ += " flatbuffers::emplace_scalar::<{{BASE_TYPE}}>(dst, {{INTO_BASE}});";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
code_ += "impl flatbuffers::EndianScalar for {{ENUM_TY}} {";
|
||||
code_ += " type Scalar = {{BASE_TYPE}};";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn to_little_endian(self) -> Self {";
|
||||
code_ += " let b = {{BASE_TYPE}}::to_le({{INTO_BASE}});";
|
||||
code_ += " {{FROM_BASE}}";
|
||||
code_ += " fn to_little_endian(self) -> {{BASE_TYPE}} {";
|
||||
code_ += " {{INTO_BASE}}.to_le()";
|
||||
code_ += " }";
|
||||
code_ += " #[inline]";
|
||||
code_ += " #[allow(clippy::wrong_self_convention)]";
|
||||
code_ += " fn from_little_endian(self) -> Self {";
|
||||
code_ += " let b = {{BASE_TYPE}}::from_le({{INTO_BASE}});";
|
||||
code_ += " {{FROM_BASE}}";
|
||||
code_ += " fn from_little_endian(v: {{BASE_TYPE}}) -> Self {";
|
||||
code_ += " let b = {{BASE_TYPE}}::from_le(v);";
|
||||
if (IsBitFlagsEnum(enum_def)) {
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
code_ += " // Safety:";
|
||||
code_ += " // This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.";
|
||||
code_ += " // from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0";
|
||||
code_ += " // https://github.com/bitflags/bitflags/issues/262";
|
||||
code_ += " unsafe { Self::from_bits_unchecked(b) }";
|
||||
} else {
|
||||
code_ += " Self(b)";
|
||||
}
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
@@ -1425,11 +1443,7 @@ class RustGenerator : public BaseGenerator {
|
||||
case ftVectorOfBool:
|
||||
case ftVectorOfFloat: {
|
||||
const auto typname = GetTypeBasic(type.VectorType());
|
||||
const auto vector_type =
|
||||
IsOneByte(type.VectorType().base_type)
|
||||
? "&" + lifetime + " [" + typname + "]"
|
||||
: "flatbuffers::Vector<" + lifetime + ", " + typname + ">";
|
||||
return WrapOption(vector_type);
|
||||
return WrapOption("flatbuffers::Vector<" + lifetime + ", " + typname + ">");
|
||||
}
|
||||
case ftVectorOfEnumKey: {
|
||||
const auto typname = WrapInNameSpace(*type.enum_def);
|
||||
@@ -1438,7 +1452,7 @@ class RustGenerator : public BaseGenerator {
|
||||
}
|
||||
case ftVectorOfStruct: {
|
||||
const auto typname = WrapInNameSpace(*type.struct_def);
|
||||
return WrapOption("&" + lifetime + " [" + typname + "]");
|
||||
return WrapOption("flatbuffers::Vector<" + lifetime + ", " + typname + ">");
|
||||
}
|
||||
case ftVectorOfTable: {
|
||||
const auto typname = WrapInNameSpace(*type.struct_def);
|
||||
@@ -1556,19 +1570,8 @@ class RustGenerator : public BaseGenerator {
|
||||
: "None";
|
||||
const std::string unwrap = field.IsOptional() ? "" : ".unwrap()";
|
||||
|
||||
const auto t = GetFullType(field.value.type);
|
||||
|
||||
// TODO(caspern): Shouldn't 1byte VectorOfEnumKey be slice too?
|
||||
const std::string safe_slice =
|
||||
(t == ftVectorOfStruct ||
|
||||
((t == ftVectorOfBool || t == ftVectorOfFloat ||
|
||||
t == ftVectorOfInteger) &&
|
||||
IsOneByte(field.value.type.VectorType().base_type)))
|
||||
? ".map(|v| v.safe_slice())"
|
||||
: "";
|
||||
|
||||
return "self._tab.get::<" + typname + ">({{STRUCT_TY}}::" + vt_offset +
|
||||
", " + default_value + ")" + safe_slice + unwrap;
|
||||
return "unsafe { self._tab.get::<" + typname + ">({{STRUCT_TY}}::" + vt_offset +
|
||||
", " + default_value + ")" + unwrap + "}";
|
||||
}
|
||||
|
||||
// Generates a fully-qualified name getter for use with --gen-name-strings
|
||||
@@ -1650,8 +1653,8 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += "impl<'a> flatbuffers::Follow<'a> for {{STRUCT_TY}}<'a> {";
|
||||
code_ += " type Inner = {{STRUCT_TY}}<'a>;";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " Self { _tab: flatbuffers::Table { buf, loc } }";
|
||||
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " Self { _tab: flatbuffers::Table::new(buf, loc) }";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
@@ -1672,7 +1675,7 @@ class RustGenerator : public BaseGenerator {
|
||||
|
||||
code_ += " #[inline]";
|
||||
code_ +=
|
||||
" pub fn init_from_table(table: flatbuffers::Table<'a>) -> "
|
||||
" pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> "
|
||||
"Self {";
|
||||
code_ += " {{STRUCT_TY}} { _tab: table }";
|
||||
code_ += " }";
|
||||
@@ -1764,16 +1767,7 @@ class RustGenerator : public BaseGenerator {
|
||||
break;
|
||||
}
|
||||
case ftVectorOfInteger:
|
||||
case ftVectorOfBool: {
|
||||
if (IsOneByte(type.VectorType().base_type)) {
|
||||
// 1 byte stuff is viewed w/ slice instead of flatbuffer::Vector
|
||||
// and thus needs to be cloned out of the slice.
|
||||
code_.SetValue("EXPR", "x.to_vec()");
|
||||
break;
|
||||
}
|
||||
code_.SetValue("EXPR", "x.into_iter().collect()");
|
||||
break;
|
||||
}
|
||||
case ftVectorOfBool:
|
||||
case ftVectorOfFloat:
|
||||
case ftVectorOfEnumKey: {
|
||||
code_.SetValue("EXPR", "x.into_iter().collect()");
|
||||
@@ -1840,6 +1834,9 @@ class RustGenerator : public BaseGenerator {
|
||||
this->GenComment(field.doc_comment);
|
||||
code_ += "#[inline]";
|
||||
code_ += "pub fn {{FIELD}}(&self) -> {{RETURN_TYPE}} {";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from valid Table for this object";
|
||||
code_ += " // which contains a valid value in this slot";
|
||||
code_ += " " + GenTableAccessorFuncBody(field, "'a");
|
||||
code_ += "}";
|
||||
|
||||
@@ -1864,16 +1861,22 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += "{{NESTED}}<'a> {";
|
||||
code_ += " let data = self.{{FIELD}}();";
|
||||
code_ += " use flatbuffers::Follow;";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid flatbuffer in this slot";
|
||||
code_ +=
|
||||
" <flatbuffers::ForwardsUOffset<{{NESTED}}<'a>>>"
|
||||
"::follow(data, 0)";
|
||||
" unsafe { <flatbuffers::ForwardsUOffset<{{NESTED}}<'a>>>"
|
||||
"::follow(data.bytes(), 0) }";
|
||||
} else {
|
||||
code_ += "Option<{{NESTED}}<'a>> {";
|
||||
code_ += " self.{{FIELD}}().map(|data| {";
|
||||
code_ += " use flatbuffers::Follow;";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid flatbuffer in this slot";
|
||||
code_ +=
|
||||
" <flatbuffers::ForwardsUOffset<{{NESTED}}<'a>>>"
|
||||
"::follow(data, 0)";
|
||||
" unsafe { <flatbuffers::ForwardsUOffset<{{NESTED}}<'a>>>"
|
||||
"::follow(data.bytes(), 0) }";
|
||||
code_ += " })";
|
||||
}
|
||||
code_ += "}";
|
||||
@@ -1909,11 +1912,17 @@ class RustGenerator : public BaseGenerator {
|
||||
// as of April 10, 2020
|
||||
if (field.IsRequired()) {
|
||||
code_ += " let u = self.{{FIELD}}();";
|
||||
code_ += " Some({{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid union in this slot";
|
||||
code_ += " Some(unsafe { {{U_ELEMENT_TABLE_TYPE}}::init_from_table(u) })";
|
||||
} else {
|
||||
code_ +=
|
||||
" self.{{FIELD}}().map("
|
||||
"{{U_ELEMENT_TABLE_TYPE}}::init_from_table)";
|
||||
code_ +=" self.{{FIELD}}().map(|t| {";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid union in this slot";
|
||||
code_ += " unsafe { {{U_ELEMENT_TABLE_TYPE}}::init_from_table(t) }";
|
||||
code_ += " })";
|
||||
}
|
||||
code_ += " } else {";
|
||||
code_ += " None";
|
||||
@@ -2282,8 +2291,8 @@ class RustGenerator : public BaseGenerator {
|
||||
|
||||
MapNativeTableField(
|
||||
field,
|
||||
"let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();"
|
||||
"_fbb.create_vector_of_strings(&w)");
|
||||
"let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();"
|
||||
"_fbb.create_vector(&w)");
|
||||
return;
|
||||
}
|
||||
case ftVectorOfTable: {
|
||||
@@ -2374,32 +2383,6 @@ class RustGenerator : public BaseGenerator {
|
||||
code_.SetValue("STRUCT_FN", namer_.Function(struct_def));
|
||||
code_.SetValue("STRUCT_CONST", namer_.Constant(struct_def.name));
|
||||
|
||||
// The root datatype accessors:
|
||||
code_ += "#[inline]";
|
||||
code_ +=
|
||||
"#[deprecated(since=\"2.0.0\", "
|
||||
"note=\"Deprecated in favor of `root_as...` methods.\")]";
|
||||
code_ +=
|
||||
"pub fn get_root_as_{{STRUCT_FN}}<'a>(buf: &'a [u8])"
|
||||
" -> {{STRUCT_TY}}<'a> {";
|
||||
code_ +=
|
||||
" unsafe { flatbuffers::root_unchecked::<{{STRUCT_TY}}"
|
||||
"<'a>>(buf) }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
|
||||
code_ += "#[inline]";
|
||||
code_ +=
|
||||
"#[deprecated(since=\"2.0.0\", "
|
||||
"note=\"Deprecated in favor of `root_as...` methods.\")]";
|
||||
code_ +=
|
||||
"pub fn get_size_prefixed_root_as_{{STRUCT_FN}}"
|
||||
"<'a>(buf: &'a [u8]) -> {{STRUCT_TY}}<'a> {";
|
||||
code_ +=
|
||||
" unsafe { flatbuffers::size_prefixed_root_unchecked::<{{STRUCT_TY}}"
|
||||
"<'a>>(buf) }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
// Default verifier root fns.
|
||||
code_ += "#[inline]";
|
||||
code_ += "/// Verifies that a buffer of bytes contains a `{{STRUCT_TY}}`";
|
||||
@@ -2641,43 +2624,25 @@ class RustGenerator : public BaseGenerator {
|
||||
// Follow for the value type, Follow for the reference type, Push for the
|
||||
// value type, and Push for the reference type.
|
||||
code_ += "impl flatbuffers::SimpleToVerifyInSlice for {{STRUCT_TY}} {}";
|
||||
code_ += "impl flatbuffers::SafeSliceAccess for {{STRUCT_TY}} {}";
|
||||
code_ += "impl<'a> flatbuffers::Follow<'a> for {{STRUCT_TY}} {";
|
||||
code_ += " type Inner = &'a {{STRUCT_TY}};";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " <&'a {{STRUCT_TY}}>::follow(buf, loc)";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "impl<'a> flatbuffers::Follow<'a> for &'a {{STRUCT_TY}} {";
|
||||
code_ += " type Inner = &'a {{STRUCT_TY}};";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " flatbuffers::follow_cast_ref::<{{STRUCT_TY}}>(buf, loc)";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "impl<'b> flatbuffers::Push for {{STRUCT_TY}} {";
|
||||
code_ += " type Output = {{STRUCT_TY}};";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {";
|
||||
code_ += " let src = unsafe {";
|
||||
code_ +=
|
||||
" ::core::slice::from_raw_parts("
|
||||
"self as *const {{STRUCT_TY}} as *const u8, Self::size())";
|
||||
code_ += " };";
|
||||
code_ += " dst.copy_from_slice(src);";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "impl<'b> flatbuffers::Push for &'b {{STRUCT_TY}} {";
|
||||
code_ += " type Output = {{STRUCT_TY}};";
|
||||
code_ += "";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {";
|
||||
code_ += " let src = unsafe {";
|
||||
code_ +=
|
||||
" ::core::slice::from_raw_parts("
|
||||
"*self as *const {{STRUCT_TY}} as *const u8, Self::size())";
|
||||
code_ += " };";
|
||||
code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {";
|
||||
code_ += " let src = ::core::slice::from_raw_parts(self as *const {{STRUCT_TY}} as *const u8, Self::size());";
|
||||
code_ += " dst.copy_from_slice(src);";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
@@ -2754,6 +2719,9 @@ class RustGenerator : public BaseGenerator {
|
||||
// Getter.
|
||||
if (IsStruct(field.value.type)) {
|
||||
code_ += "pub fn {{FIELD}}(&self) -> &{{FIELD_TYPE}} {";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid struct in this slot";
|
||||
code_ +=
|
||||
" unsafe {"
|
||||
" &*(self.0[{{FIELD_OFFSET}}..].as_ptr() as *const"
|
||||
@@ -2765,20 +2733,26 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ +=
|
||||
"pub fn {{FIELD}}(&'a self) -> "
|
||||
"flatbuffers::Array<'a, {{ARRAY_ITEM}}, {{ARRAY_SIZE}}> {";
|
||||
code_ += " flatbuffers::Array::follow(&self.0, {{FIELD_OFFSET}})";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid array in this slot";
|
||||
code_ += " unsafe { flatbuffers::Array::follow(&self.0, {{FIELD_OFFSET}}) }";
|
||||
} else {
|
||||
code_ += "pub fn {{FIELD}}(&self) -> {{FIELD_TYPE}} {";
|
||||
code_ +=
|
||||
" let mut mem = core::mem::MaybeUninit::"
|
||||
"<{{FIELD_TYPE}}>::uninit();";
|
||||
code_ += " unsafe {";
|
||||
"<<{{FIELD_TYPE}} as EndianScalar>::Scalar>::uninit();";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid value in this slot";
|
||||
code_ += " EndianScalar::from_little_endian(unsafe {";
|
||||
code_ += " core::ptr::copy_nonoverlapping(";
|
||||
code_ += " self.0[{{FIELD_OFFSET}}..].as_ptr(),";
|
||||
code_ += " mem.as_mut_ptr() as *mut u8,";
|
||||
code_ += " core::mem::size_of::<{{FIELD_TYPE}}>(),";
|
||||
code_ += " core::mem::size_of::<<{{FIELD_TYPE}} as EndianScalar>::Scalar>(),";
|
||||
code_ += " );";
|
||||
code_ += " mem.assume_init()";
|
||||
code_ += " }.from_little_endian()";
|
||||
code_ += " })";
|
||||
}
|
||||
code_ += "}\n";
|
||||
// Setter.
|
||||
@@ -2799,13 +2773,19 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ +=
|
||||
"pub fn set_{{FIELD}}(&mut self, items: &{{FIELD_TYPE}}) "
|
||||
"{";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid array in this slot";
|
||||
code_ +=
|
||||
" flatbuffers::emplace_scalar_array(&mut self.0, "
|
||||
"{{FIELD_OFFSET}}, items);";
|
||||
" unsafe { flatbuffers::emplace_scalar_array(&mut self.0, "
|
||||
"{{FIELD_OFFSET}}, items) };";
|
||||
} else {
|
||||
code_.SetValue("FIELD_SIZE",
|
||||
NumToString(InlineSize(field.value.type)));
|
||||
code_ += "pub fn set_{{FIELD}}(&mut self, x: &{{FIELD_TYPE}}) {";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid array in this slot";
|
||||
code_ += " unsafe {";
|
||||
code_ += " core::ptr::copy(";
|
||||
code_ += " x.as_ptr() as *const u8,";
|
||||
@@ -2817,11 +2797,14 @@ class RustGenerator : public BaseGenerator {
|
||||
} else {
|
||||
code_ += "pub fn set_{{FIELD}}(&mut self, x: {{FIELD_TYPE}}) {";
|
||||
code_ += " let x_le = x.to_little_endian();";
|
||||
code_ += " // Safety:";
|
||||
code_ += " // Created from a valid Table for this object";
|
||||
code_ += " // Which contains a valid value in this slot";
|
||||
code_ += " unsafe {";
|
||||
code_ += " core::ptr::copy_nonoverlapping(";
|
||||
code_ += " &x_le as *const {{FIELD_TYPE}} as *const u8,";
|
||||
code_ += " &x_le as *const _ as *const u8,";
|
||||
code_ += " self.0[{{FIELD_OFFSET}}..].as_mut_ptr(),";
|
||||
code_ += " core::mem::size_of::<{{FIELD_TYPE}}>(),";
|
||||
code_ += " core::mem::size_of::<<{{FIELD_TYPE}} as EndianScalar>::Scalar>(),";
|
||||
code_ += " );";
|
||||
code_ += " }";
|
||||
}
|
||||
|
||||
@@ -32,39 +32,25 @@ impl core::fmt::Debug for ArrayStruct {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for ArrayStruct {}
|
||||
impl flatbuffers::SafeSliceAccess for ArrayStruct {}
|
||||
impl<'a> flatbuffers::Follow<'a> for ArrayStruct {
|
||||
type Inner = &'a ArrayStruct;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a ArrayStruct>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a ArrayStruct {
|
||||
type Inner = &'a ArrayStruct;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<ArrayStruct>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for ArrayStruct {
|
||||
type Output = ArrayStruct;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b ArrayStruct {
|
||||
type Output = ArrayStruct;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -104,64 +90,88 @@ impl<'a> ArrayStruct {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn b(&'a self) -> flatbuffers::Array<'a, i32, 15> {
|
||||
flatbuffers::Array::follow(&self.0, 4)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::Array::follow(&self.0, 4) }
|
||||
}
|
||||
|
||||
pub fn set_b(&mut self, items: &[i32; 15]) {
|
||||
flatbuffers::emplace_scalar_array(&mut self.0, 4, items);
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 4, items) };
|
||||
}
|
||||
|
||||
pub fn c(&self) -> i8 {
|
||||
let mut mem = core::mem::MaybeUninit::<i8>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i8 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[64..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i8>(),
|
||||
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_c(&mut self, x: i8) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i8 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[64..].as_mut_ptr(),
|
||||
core::mem::size_of::<i8>(),
|
||||
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn d(&'a self) -> flatbuffers::Array<'a, NestedStruct, 2> {
|
||||
flatbuffers::Array::follow(&self.0, 72)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::Array::follow(&self.0, 72) }
|
||||
}
|
||||
|
||||
pub fn set_d(&mut self, x: &[NestedStruct; 2]) {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe {
|
||||
core::ptr::copy(
|
||||
x.as_ptr() as *const u8,
|
||||
@@ -172,34 +182,46 @@ impl<'a> ArrayStruct {
|
||||
}
|
||||
|
||||
pub fn e(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[136..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_e(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[136..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn f(&'a self) -> flatbuffers::Array<'a, i64, 2> {
|
||||
flatbuffers::Array::follow(&self.0, 144)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::Array::follow(&self.0, 144) }
|
||||
}
|
||||
|
||||
pub fn set_f(&mut self, items: &[i64; 2]) {
|
||||
flatbuffers::emplace_scalar_array(&mut self.0, 144, items);
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 144, items) };
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> ArrayStructT {
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct ArrayTable<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for ArrayTable<'a> {
|
||||
type Inner = ArrayTable<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> ArrayTable<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
ArrayTable { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> ArrayTable<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<&'a ArrayStruct> {
|
||||
self._tab.get::<ArrayStruct>(ArrayTable::VT_A, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<ArrayStruct>(ArrayTable::VT_A, None)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,18 +142,6 @@ impl ArrayTableT {
|
||||
})
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_root_as_array_table<'a>(buf: &'a [u8]) -> ArrayTable<'a> {
|
||||
unsafe { flatbuffers::root_unchecked::<ArrayTable<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_size_prefixed_root_as_array_table<'a>(buf: &'a [u8]) -> ArrayTable<'a> {
|
||||
unsafe { flatbuffers::size_prefixed_root_unchecked::<ArrayTable<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a `ArrayTable`
|
||||
/// and returns it.
|
||||
|
||||
@@ -30,39 +30,25 @@ impl core::fmt::Debug for NestedStruct {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for NestedStruct {}
|
||||
impl flatbuffers::SafeSliceAccess for NestedStruct {}
|
||||
impl<'a> flatbuffers::Follow<'a> for NestedStruct {
|
||||
type Inner = &'a NestedStruct;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a NestedStruct>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a NestedStruct {
|
||||
type Inner = &'a NestedStruct;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<NestedStruct>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for NestedStruct {
|
||||
type Output = NestedStruct;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b NestedStruct {
|
||||
type Output = NestedStruct;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -98,41 +84,59 @@ impl<'a> NestedStruct {
|
||||
}
|
||||
|
||||
pub fn a(&'a self) -> flatbuffers::Array<'a, i32, 2> {
|
||||
flatbuffers::Array::follow(&self.0, 0)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::Array::follow(&self.0, 0) }
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, items: &[i32; 2]) {
|
||||
flatbuffers::emplace_scalar_array(&mut self.0, 0, items);
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 0, items) };
|
||||
}
|
||||
|
||||
pub fn b(&self) -> TestEnum {
|
||||
let mut mem = core::mem::MaybeUninit::<TestEnum>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<TestEnum as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[8..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<TestEnum>(),
|
||||
core::mem::size_of::<<TestEnum as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_b(&mut self, x: TestEnum) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const TestEnum as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[8..].as_mut_ptr(),
|
||||
core::mem::size_of::<TestEnum>(),
|
||||
core::mem::size_of::<<TestEnum as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn c(&'a self) -> flatbuffers::Array<'a, TestEnum, 2> {
|
||||
flatbuffers::Array::follow(&self.0, 9)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::Array::follow(&self.0, 9) }
|
||||
}
|
||||
|
||||
pub fn set_c(&mut self, x: &[TestEnum; 2]) {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe {
|
||||
core::ptr::copy(
|
||||
x.as_ptr() as *const u8,
|
||||
@@ -143,11 +147,17 @@ impl<'a> NestedStruct {
|
||||
}
|
||||
|
||||
pub fn d(&'a self) -> flatbuffers::Array<'a, i64, 2> {
|
||||
flatbuffers::Array::follow(&self.0, 16)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::Array::follow(&self.0, 16) }
|
||||
}
|
||||
|
||||
pub fn set_d(&mut self, items: &[i64; 2]) {
|
||||
flatbuffers::emplace_scalar_array(&mut self.0, 16, items);
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid array in this slot
|
||||
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 16, items) };
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> NestedStructT {
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for TestEnum {
|
||||
impl<'a> flatbuffers::Follow<'a> for TestEnum {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for TestEnum {
|
||||
impl flatbuffers::Push for TestEnum {
|
||||
type Output = TestEnum;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for TestEnum {
|
||||
type Scalar = i8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i8::from_le(self.0);
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
let b = i8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,8 @@ impl core::fmt::Debug for FromInclude {
|
||||
impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i64>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
impl flatbuffers::Push for FromInclude {
|
||||
type Output = FromInclude;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i64>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for FromInclude {
|
||||
type Scalar = i64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i64::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i64 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i64::from_le(self.0);
|
||||
fn from_little_endian(v: i64) -> Self {
|
||||
let b = i64::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableB<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
|
||||
type Inner = TableB<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TableB<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableB { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> TableB<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<super::super::TableA<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,39 +27,25 @@ impl core::fmt::Debug for Unused {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
|
||||
impl flatbuffers::SafeSliceAccess for Unused {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Unused>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Unused {
|
||||
type Output = Unused;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Unused {
|
||||
type Output = Unused;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -89,24 +75,30 @@ impl<'a> Unused {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableA<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
|
||||
type Inner = TableA<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TableA<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> TableA<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,10 +51,8 @@ impl core::fmt::Debug for FromInclude {
|
||||
impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i64>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
impl flatbuffers::Push for FromInclude {
|
||||
type Output = FromInclude;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i64>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for FromInclude {
|
||||
type Scalar = i64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i64::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i64 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i64::from_le(self.0);
|
||||
fn from_little_endian(v: i64) -> Self {
|
||||
let b = i64::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableB<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
|
||||
type Inner = TableB<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TableB<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableB { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> TableB<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<super::super::TableA<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,39 +27,25 @@ impl core::fmt::Debug for Unused {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
|
||||
impl flatbuffers::SafeSliceAccess for Unused {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Unused>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Unused {
|
||||
type Output = Unused;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Unused {
|
||||
type Output = Unused;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -89,24 +75,30 @@ impl<'a> Unused {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableA<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
|
||||
type Inner = TableA<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TableA<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> TableA<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for ABC {
|
||||
impl<'a> flatbuffers::Follow<'a> for ABC {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i32>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i32>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for ABC {
|
||||
impl flatbuffers::Push for ABC {
|
||||
type Output = ABC;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i32>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for ABC {
|
||||
type Scalar = i32;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i32::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i32 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i32::from_le(self.0);
|
||||
fn from_little_endian(v: i32) -> Self {
|
||||
let b = i32::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct KeywordsInTable<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for KeywordsInTable<'a> {
|
||||
type Inner = KeywordsInTable<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ impl<'a> KeywordsInTable<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
KeywordsInTable { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -66,19 +66,31 @@ impl<'a> KeywordsInTable<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn is(&self) -> ABC {
|
||||
self._tab.get::<ABC>(KeywordsInTable::VT_IS, Some(ABC::void)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<ABC>(KeywordsInTable::VT_IS, Some(ABC::void)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn private(&self) -> public {
|
||||
self._tab.get::<public>(KeywordsInTable::VT_PRIVATE, Some(public::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<public>(KeywordsInTable::VT_PRIVATE, Some(public::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn type_(&self) -> i32 {
|
||||
self._tab.get::<i32>(KeywordsInTable::VT_TYPE_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(KeywordsInTable::VT_TYPE_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default(&self) -> bool {
|
||||
self._tab.get::<bool>(KeywordsInTable::VT_DEFAULT, Some(false)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<bool>(KeywordsInTable::VT_DEFAULT, Some(false)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for KeywordsInUnion {
|
||||
impl<'a> flatbuffers::Follow<'a> for KeywordsInUnion {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for KeywordsInUnion {
|
||||
impl flatbuffers::Push for KeywordsInUnion {
|
||||
type Output = KeywordsInUnion;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for KeywordsInUnion {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,8 @@ impl core::fmt::Debug for public {
|
||||
impl<'a> flatbuffers::Follow<'a> for public {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i32>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i32>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for public {
|
||||
impl flatbuffers::Push for public {
|
||||
type Output = public;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i32>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for public {
|
||||
type Scalar = i32;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i32::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i32 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i32::from_le(self.0);
|
||||
fn from_little_endian(v: i32) -> Self {
|
||||
let b = i32::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,39 +28,25 @@ impl core::fmt::Debug for Ability {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Ability {}
|
||||
impl flatbuffers::SafeSliceAccess for Ability {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Ability {
|
||||
type Inner = &'a Ability;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Ability>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Ability {
|
||||
type Inner = &'a Ability;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Ability>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Ability {
|
||||
type Output = Ability;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Ability {
|
||||
type Output = Ability;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -92,24 +78,30 @@ impl<'a> Ability {
|
||||
}
|
||||
|
||||
pub fn id(&self) -> u32 {
|
||||
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<u32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_id(&mut self, x: u32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const u32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -125,24 +117,30 @@ impl<'a> Ability {
|
||||
key.cmp(&val)
|
||||
}
|
||||
pub fn distance(&self) -> u32 {
|
||||
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<u32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_distance(&mut self, x: u32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const u32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,8 @@ impl core::fmt::Debug for AnyAmbiguousAliases {
|
||||
impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
|
||||
impl flatbuffers::Push for AnyAmbiguousAliases {
|
||||
type Output = AnyAmbiguousAliases;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for AnyAmbiguousAliases {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,8 @@ impl core::fmt::Debug for Any {
|
||||
impl<'a> flatbuffers::Follow<'a> for Any {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for Any {
|
||||
impl flatbuffers::Push for Any {
|
||||
type Output = Any;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Any {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,8 @@ impl core::fmt::Debug for AnyUniqueAliases {
|
||||
impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
|
||||
impl flatbuffers::Push for AnyUniqueAliases {
|
||||
type Output = AnyUniqueAliases;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for AnyUniqueAliases {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,32 +29,38 @@ pub use self::bitflags_color::Color;
|
||||
impl<'a> flatbuffers::Follow<'a> for Color {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
Self::from_bits_unchecked(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for Color {
|
||||
type Output = Color;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.bits()); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.bits());
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Color {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.bits());
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.bits().to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.bits());
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,32 +25,38 @@ pub use self::bitflags_long_enum::LongEnum;
|
||||
impl<'a> flatbuffers::Follow<'a> for LongEnum {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u64>(buf, loc)
|
||||
};
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u64>(buf, loc);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
Self::from_bits_unchecked(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for LongEnum {
|
||||
type Output = LongEnum;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u64>(dst, self.bits()); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u64>(dst, self.bits());
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for LongEnum {
|
||||
type Scalar = u64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u64::to_le(self.bits());
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
fn to_little_endian(self) -> u64 {
|
||||
self.bits().to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u64::from_le(self.bits());
|
||||
fn from_little_endian(v: u64) -> Self {
|
||||
let b = u64::from_le(v);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ pub struct Monster<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ impl<'a> Monster<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Monster { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -161,7 +161,7 @@ impl<'a> Monster<'a> {
|
||||
x.to_string()
|
||||
};
|
||||
let inventory = self.inventory().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let color = self.color();
|
||||
let test = match self.test_type() {
|
||||
@@ -196,7 +196,7 @@ impl<'a> Monster<'a> {
|
||||
Box::new(x.unpack())
|
||||
});
|
||||
let testnestedflatbuffer = self.testnestedflatbuffer().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let testempty = self.testempty().map(|x| {
|
||||
Box::new(x.unpack())
|
||||
@@ -211,7 +211,7 @@ impl<'a> Monster<'a> {
|
||||
let testhashs64_fnv1a = self.testhashs64_fnv1a();
|
||||
let testhashu64_fnv1a = self.testhashu64_fnv1a();
|
||||
let testarrayofbools = self.testarrayofbools().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let testf = self.testf();
|
||||
let testf2 = self.testf2();
|
||||
@@ -223,7 +223,7 @@ impl<'a> Monster<'a> {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
});
|
||||
let flex = self.flex().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let test5 = self.test5().map(|x| {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
@@ -298,7 +298,7 @@ impl<'a> Monster<'a> {
|
||||
});
|
||||
let signed_enum = self.signed_enum();
|
||||
let testrequirednestedflatbuffer = self.testrequirednestedflatbuffer().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let scalar_key_sorted_tables = self.scalar_key_sorted_tables().map(|x| {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
@@ -364,19 +364,31 @@ impl<'a> Monster<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn pos(&self) -> Option<&'a Vec3> {
|
||||
self._tab.get::<Vec3>(Monster::VT_POS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Vec3>(Monster::VT_POS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn mana(&self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn hp(&self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn name(&self) -> &'a str {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn key_compare_less_than(&self, o: &Monster) -> bool {
|
||||
@@ -389,220 +401,378 @@ impl<'a> Monster<'a> {
|
||||
key.cmp(val)
|
||||
}
|
||||
#[inline]
|
||||
pub fn inventory(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
|
||||
pub fn inventory(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color(&self) -> Color {
|
||||
self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test_type(&self) -> Any {
|
||||
self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test4(&self) -> Option<&'a [Test]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None).map(|v| v.safe_slice())
|
||||
pub fn test4(&self) -> Option<flatbuffers::Vector<'a, Test>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofstring(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)}
|
||||
}
|
||||
/// an example documentation comment: this will end up in the generated code
|
||||
/// multiline too
|
||||
#[inline]
|
||||
pub fn testarrayoftables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn enemy(&self) -> Option<Monster<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testnestedflatbuffer(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
|
||||
pub fn testnestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None)}
|
||||
}
|
||||
pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
|
||||
self.testnestedflatbuffer().map(|data| {
|
||||
use flatbuffers::Follow;
|
||||
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid flatbuffer in this slot
|
||||
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
pub fn testempty(&self) -> Option<Stat<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testbool(&self) -> bool {
|
||||
self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs32_fnv1(&self) -> i32 {
|
||||
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu32_fnv1(&self) -> u32 {
|
||||
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs64_fnv1(&self) -> i64 {
|
||||
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu64_fnv1(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs32_fnv1a(&self) -> i32 {
|
||||
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu32_fnv1a(&self) -> u32 {
|
||||
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs64_fnv1a(&self) -> i64 {
|
||||
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu64_fnv1a(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofbools(&self) -> Option<&'a [bool]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None).map(|v| v.safe_slice())
|
||||
pub fn testarrayofbools(&self) -> Option<flatbuffers::Vector<'a, bool>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testf(&self) -> f32 {
|
||||
self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testf2(&self) -> f32 {
|
||||
self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testf3(&self) -> f32 {
|
||||
self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofstring2(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofsortedstruct(&self) -> Option<&'a [Ability]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None).map(|v| v.safe_slice())
|
||||
pub fn testarrayofsortedstruct(&self) -> Option<flatbuffers::Vector<'a, Ability>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn flex(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None).map(|v| v.safe_slice())
|
||||
pub fn flex(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test5(&self) -> Option<&'a [Test]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None).map(|v| v.safe_slice())
|
||||
pub fn test5(&self) -> Option<flatbuffers::Vector<'a, Test>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_longs(&self) -> Option<flatbuffers::Vector<'a, i64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_doubles(&self) -> Option<flatbuffers::Vector<'a, f64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn parent_namespace_test(&self) -> Option<super::InParentNamespace<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn single_weak_reference(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_weak_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_strong_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn co_owning_reference(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_co_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn non_owning_reference(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_non_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_unique_type(&self) -> AnyUniqueAliases {
|
||||
self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_unique(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_ambiguous_type(&self) -> AnyAmbiguousAliases {
|
||||
self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_ambiguous(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_enums(&self) -> Option<flatbuffers::Vector<'a, Color>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn signed_enum(&self) -> Race {
|
||||
self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testrequirednestedflatbuffer(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
|
||||
pub fn testrequirednestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None)}
|
||||
}
|
||||
pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
|
||||
self.testrequirednestedflatbuffer().map(|data| {
|
||||
use flatbuffers::Follow;
|
||||
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid flatbuffer in this slot
|
||||
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
pub fn scalar_key_sorted_tables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn native_inline(&self) -> Option<&'a Test> {
|
||||
self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn long_enum_non_enum_default(&self) -> LongEnum {
|
||||
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn long_enum_normal_default(&self) -> LongEnum {
|
||||
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_monster(&self) -> Option<Monster<'a>> {
|
||||
if self.test_type() == Any::Monster {
|
||||
self.test().map(Monster::init_from_table)
|
||||
self.test().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -612,7 +782,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_test_simple_table_with_enum(&self) -> Option<TestSimpleTableWithEnum<'a>> {
|
||||
if self.test_type() == Any::TestSimpleTableWithEnum {
|
||||
self.test().map(TestSimpleTableWithEnum::init_from_table)
|
||||
self.test().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -622,7 +797,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_my_game_example_2_monster(&self) -> Option<super::example_2::Monster<'a>> {
|
||||
if self.test_type() == Any::MyGame_Example2_Monster {
|
||||
self.test().map(super::example_2::Monster::init_from_table)
|
||||
self.test().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { super::example_2::Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -632,7 +812,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_m(&self) -> Option<Monster<'a>> {
|
||||
if self.any_unique_type() == AnyUniqueAliases::M {
|
||||
self.any_unique().map(Monster::init_from_table)
|
||||
self.any_unique().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -642,7 +827,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_ts(&self) -> Option<TestSimpleTableWithEnum<'a>> {
|
||||
if self.any_unique_type() == AnyUniqueAliases::TS {
|
||||
self.any_unique().map(TestSimpleTableWithEnum::init_from_table)
|
||||
self.any_unique().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -652,7 +842,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_m2(&self) -> Option<super::example_2::Monster<'a>> {
|
||||
if self.any_unique_type() == AnyUniqueAliases::M2 {
|
||||
self.any_unique().map(super::example_2::Monster::init_from_table)
|
||||
self.any_unique().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { super::example_2::Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -662,7 +857,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m1(&self) -> Option<Monster<'a>> {
|
||||
if self.any_ambiguous_type() == AnyAmbiguousAliases::M1 {
|
||||
self.any_ambiguous().map(Monster::init_from_table)
|
||||
self.any_ambiguous().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -672,7 +872,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m2(&self) -> Option<Monster<'a>> {
|
||||
if self.any_ambiguous_type() == AnyAmbiguousAliases::M2 {
|
||||
self.any_ambiguous().map(Monster::init_from_table)
|
||||
self.any_ambiguous().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -682,7 +887,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m3(&self) -> Option<Monster<'a>> {
|
||||
if self.any_ambiguous_type() == AnyAmbiguousAliases::M3 {
|
||||
self.any_ambiguous().map(Monster::init_from_table)
|
||||
self.any_ambiguous().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -1391,7 +1601,7 @@ impl MonsterT {
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
let testarrayofstring = self.testarrayofstring.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
|
||||
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
let testarrayoftables = self.testarrayoftables.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
|
||||
@@ -1421,7 +1631,7 @@ impl MonsterT {
|
||||
let testf2 = self.testf2;
|
||||
let testf3 = self.testf3;
|
||||
let testarrayofstring2 = self.testarrayofstring2.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
|
||||
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
let testarrayofsortedstruct = self.testarrayofsortedstruct.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
|
||||
@@ -1534,18 +1744,6 @@ impl MonsterT {
|
||||
})
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
unsafe { flatbuffers::root_unchecked::<Monster<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a `Monster`
|
||||
/// and returns it.
|
||||
|
||||
@@ -63,10 +63,8 @@ impl core::fmt::Debug for Race {
|
||||
impl<'a> flatbuffers::Follow<'a> for Race {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for Race {
|
||||
impl flatbuffers::Push for Race {
|
||||
type Output = Race;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Race {
|
||||
type Scalar = i8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i8::from_le(self.0);
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
let b = i8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct Referrable<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
|
||||
type Inner = Referrable<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> Referrable<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Referrable { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -54,7 +54,10 @@ impl<'a> Referrable<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> u64 {
|
||||
self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn key_compare_less_than(&self, o: &Referrable) -> bool {
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct Stat<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
|
||||
type Inner = Stat<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<'a> Stat<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Stat { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -64,15 +64,24 @@ impl<'a> Stat<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> Option<&'a str> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn val(&self) -> i64 {
|
||||
self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn count(&self) -> u16 {
|
||||
self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn key_compare_less_than(&self, o: &Stat) -> bool {
|
||||
|
||||
@@ -29,39 +29,25 @@ impl core::fmt::Debug for StructOfStructs {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructs {}
|
||||
impl flatbuffers::SafeSliceAccess for StructOfStructs {}
|
||||
impl<'a> flatbuffers::Follow<'a> for StructOfStructs {
|
||||
type Inner = &'a StructOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a StructOfStructs>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructs {
|
||||
type Inner = &'a StructOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<StructOfStructs>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for StructOfStructs {
|
||||
type Output = StructOfStructs;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b StructOfStructs {
|
||||
type Output = StructOfStructs;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -95,6 +81,9 @@ impl<'a> StructOfStructs {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> &Ability {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[0..].as_ptr() as *const Ability) }
|
||||
}
|
||||
|
||||
@@ -104,6 +93,9 @@ impl<'a> StructOfStructs {
|
||||
}
|
||||
|
||||
pub fn b(&self) -> &Test {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[8..].as_ptr() as *const Test) }
|
||||
}
|
||||
|
||||
@@ -113,6 +105,9 @@ impl<'a> StructOfStructs {
|
||||
}
|
||||
|
||||
pub fn c(&self) -> &Ability {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[12..].as_ptr() as *const Ability) }
|
||||
}
|
||||
|
||||
|
||||
@@ -27,39 +27,25 @@ impl core::fmt::Debug for StructOfStructsOfStructs {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {}
|
||||
impl flatbuffers::SafeSliceAccess for StructOfStructsOfStructs {}
|
||||
impl<'a> flatbuffers::Follow<'a> for StructOfStructsOfStructs {
|
||||
type Inner = &'a StructOfStructsOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a StructOfStructsOfStructs>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructsOfStructs {
|
||||
type Inner = &'a StructOfStructsOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<StructOfStructsOfStructs>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
|
||||
type Output = StructOfStructsOfStructs;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b StructOfStructsOfStructs {
|
||||
type Output = StructOfStructsOfStructs;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const StructOfStructsOfStructs as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -89,6 +75,9 @@ impl<'a> StructOfStructsOfStructs {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> &StructOfStructs {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[0..].as_ptr() as *const StructOfStructs) }
|
||||
}
|
||||
|
||||
|
||||
@@ -28,39 +28,25 @@ impl core::fmt::Debug for Test {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Test {}
|
||||
impl flatbuffers::SafeSliceAccess for Test {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Test {
|
||||
type Inner = &'a Test;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Test>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Test {
|
||||
type Inner = &'a Test;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Test>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Test {
|
||||
type Output = Test;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Test {
|
||||
type Output = Test;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Test as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -92,47 +78,59 @@ impl<'a> Test {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i16 {
|
||||
let mut mem = core::mem::MaybeUninit::<i16>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i16 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i16>(),
|
||||
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i16) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i16 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i16>(),
|
||||
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn b(&self) -> i8 {
|
||||
let mut mem = core::mem::MaybeUninit::<i8>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i8 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[2..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i8>(),
|
||||
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_b(&mut self, x: i8) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i8 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[2..].as_mut_ptr(),
|
||||
core::mem::size_of::<i8>(),
|
||||
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TestSimpleTableWithEnum<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
|
||||
type Inner = TestSimpleTableWithEnum<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TestSimpleTableWithEnum<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TestSimpleTableWithEnum { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -54,7 +54,10 @@ impl<'a> TestSimpleTableWithEnum<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn color(&self) -> Color {
|
||||
self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TypeAliases<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
|
||||
type Inner = TypeAliases<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ impl<'a> TypeAliases<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TypeAliases { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -79,7 +79,7 @@ impl<'a> TypeAliases<'a> {
|
||||
let f32_ = self.f32_();
|
||||
let f64_ = self.f64_();
|
||||
let v8 = self.v8().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let vf64 = self.vf64().map(|x| {
|
||||
x.into_iter().collect()
|
||||
@@ -102,51 +102,87 @@ impl<'a> TypeAliases<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn i8_(&self) -> i8 {
|
||||
self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u8_(&self) -> u8 {
|
||||
self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn i16_(&self) -> i16 {
|
||||
self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u16_(&self) -> u16 {
|
||||
self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn i32_(&self) -> i32 {
|
||||
self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u32_(&self) -> u32 {
|
||||
self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn i64_(&self) -> i64 {
|
||||
self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u64_(&self) -> u64 {
|
||||
self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn f32_(&self) -> f32 {
|
||||
self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn f64_(&self) -> f64 {
|
||||
self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn v8(&self) -> Option<&'a [i8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None).map(|v| v.safe_slice())
|
||||
pub fn v8(&self) -> Option<flatbuffers::Vector<'a, i8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vf64(&self) -> Option<flatbuffers::Vector<'a, f64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,39 +32,25 @@ impl core::fmt::Debug for Vec3 {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Vec3 {}
|
||||
impl flatbuffers::SafeSliceAccess for Vec3 {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Vec3>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Vec3 {
|
||||
type Output = Vec3;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Vec3 {
|
||||
type Output = Vec3;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -104,121 +90,154 @@ impl<'a> Vec3 {
|
||||
}
|
||||
|
||||
pub fn x(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_x(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn y(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_y(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn z(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[8..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_z(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[8..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test1(&self) -> f64 {
|
||||
let mut mem = core::mem::MaybeUninit::<f64>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f64 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[16..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f64>(),
|
||||
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_test1(&mut self, x: f64) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f64 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[16..].as_mut_ptr(),
|
||||
core::mem::size_of::<f64>(),
|
||||
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test2(&self) -> Color {
|
||||
let mut mem = core::mem::MaybeUninit::<Color>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<Color as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[24..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<Color>(),
|
||||
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_test2(&mut self, x: Color) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const Color as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[24..].as_mut_ptr(),
|
||||
core::mem::size_of::<Color>(),
|
||||
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test3(&self) -> &Test {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[26..].as_ptr() as *const Test) }
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct Monster<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ impl<'a> Monster<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Monster { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct InParentNamespace<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
|
||||
type Inner = InParentNamespace<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ impl<'a> InParentNamespace<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
InParentNamespace { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
|
||||
@@ -51,10 +51,8 @@ impl core::fmt::Debug for FromInclude {
|
||||
impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i64>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
impl flatbuffers::Push for FromInclude {
|
||||
type Output = FromInclude;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i64>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for FromInclude {
|
||||
type Scalar = i64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i64::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i64 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i64::from_le(self.0);
|
||||
fn from_little_endian(v: i64) -> Self {
|
||||
let b = i64::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableB<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
|
||||
type Inner = TableB<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TableB<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableB { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> TableB<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<super::super::TableA<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,39 +27,25 @@ impl core::fmt::Debug for Unused {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
|
||||
impl flatbuffers::SafeSliceAccess for Unused {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Unused>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Unused {
|
||||
type Output = Unused;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Unused {
|
||||
type Output = Unused;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -89,24 +75,30 @@ impl<'a> Unused {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableA<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
|
||||
type Inner = TableA<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TableA<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> TableA<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,39 +30,25 @@ impl core::fmt::Debug for Ability {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Ability {}
|
||||
impl flatbuffers::SafeSliceAccess for Ability {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Ability {
|
||||
type Inner = &'a Ability;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Ability>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Ability {
|
||||
type Inner = &'a Ability;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Ability>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Ability {
|
||||
type Output = Ability;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Ability {
|
||||
type Output = Ability;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -106,24 +92,30 @@ impl<'a> Ability {
|
||||
}
|
||||
|
||||
pub fn id(&self) -> u32 {
|
||||
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<u32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_id(&mut self, x: u32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const u32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -139,24 +131,30 @@ impl<'a> Ability {
|
||||
key.cmp(&val)
|
||||
}
|
||||
pub fn distance(&self) -> u32 {
|
||||
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<u32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_distance(&mut self, x: u32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const u32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<u32>(),
|
||||
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +74,8 @@ impl Serialize for AnyAmbiguousAliases {
|
||||
impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
|
||||
impl flatbuffers::Push for AnyAmbiguousAliases {
|
||||
type Output = AnyAmbiguousAliases;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for AnyAmbiguousAliases {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +74,8 @@ impl Serialize for Any {
|
||||
impl<'a> flatbuffers::Follow<'a> for Any {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for Any {
|
||||
impl flatbuffers::Push for Any {
|
||||
type Output = Any;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Any {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +74,8 @@ impl Serialize for AnyUniqueAliases {
|
||||
impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
|
||||
impl flatbuffers::Push for AnyUniqueAliases {
|
||||
type Output = AnyUniqueAliases;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for AnyUniqueAliases {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,32 +40,38 @@ impl Serialize for Color {
|
||||
impl<'a> flatbuffers::Follow<'a> for Color {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
Self::from_bits_unchecked(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for Color {
|
||||
type Output = Color;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.bits()); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.bits());
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Color {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.bits());
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.bits().to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.bits());
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,32 +36,38 @@ impl Serialize for LongEnum {
|
||||
impl<'a> flatbuffers::Follow<'a> for LongEnum {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u64>(buf, loc)
|
||||
};
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u64>(buf, loc);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
Self::from_bits_unchecked(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for LongEnum {
|
||||
type Output = LongEnum;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u64>(dst, self.bits()); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u64>(dst, self.bits());
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for LongEnum {
|
||||
type Scalar = u64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u64::to_le(self.bits());
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
fn to_little_endian(self) -> u64 {
|
||||
self.bits().to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u64::from_le(self.bits());
|
||||
fn from_little_endian(v: u64) -> Self {
|
||||
let b = u64::from_le(v);
|
||||
// Safety:
|
||||
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
|
||||
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
|
||||
// https://github.com/bitflags/bitflags/issues/262
|
||||
unsafe { Self::from_bits_unchecked(b) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ pub struct Monster<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ impl<'a> Monster<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Monster { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -163,7 +163,7 @@ impl<'a> Monster<'a> {
|
||||
x.to_string()
|
||||
};
|
||||
let inventory = self.inventory().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let color = self.color();
|
||||
let test = match self.test_type() {
|
||||
@@ -198,7 +198,7 @@ impl<'a> Monster<'a> {
|
||||
Box::new(x.unpack())
|
||||
});
|
||||
let testnestedflatbuffer = self.testnestedflatbuffer().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let testempty = self.testempty().map(|x| {
|
||||
Box::new(x.unpack())
|
||||
@@ -213,7 +213,7 @@ impl<'a> Monster<'a> {
|
||||
let testhashs64_fnv1a = self.testhashs64_fnv1a();
|
||||
let testhashu64_fnv1a = self.testhashu64_fnv1a();
|
||||
let testarrayofbools = self.testarrayofbools().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let testf = self.testf();
|
||||
let testf2 = self.testf2();
|
||||
@@ -225,7 +225,7 @@ impl<'a> Monster<'a> {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
});
|
||||
let flex = self.flex().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let test5 = self.test5().map(|x| {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
@@ -300,7 +300,7 @@ impl<'a> Monster<'a> {
|
||||
});
|
||||
let signed_enum = self.signed_enum();
|
||||
let testrequirednestedflatbuffer = self.testrequirednestedflatbuffer().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let scalar_key_sorted_tables = self.scalar_key_sorted_tables().map(|x| {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
@@ -366,19 +366,31 @@ impl<'a> Monster<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn pos(&self) -> Option<&'a Vec3> {
|
||||
self._tab.get::<Vec3>(Monster::VT_POS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Vec3>(Monster::VT_POS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn mana(&self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn hp(&self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn name(&self) -> &'a str {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn key_compare_less_than(&self, o: &Monster) -> bool {
|
||||
@@ -391,220 +403,378 @@ impl<'a> Monster<'a> {
|
||||
key.cmp(val)
|
||||
}
|
||||
#[inline]
|
||||
pub fn inventory(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
|
||||
pub fn inventory(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color(&self) -> Color {
|
||||
self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test_type(&self) -> Any {
|
||||
self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test4(&self) -> Option<&'a [Test]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None).map(|v| v.safe_slice())
|
||||
pub fn test4(&self) -> Option<flatbuffers::Vector<'a, Test>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofstring(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)}
|
||||
}
|
||||
/// an example documentation comment: this will end up in the generated code
|
||||
/// multiline too
|
||||
#[inline]
|
||||
pub fn testarrayoftables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn enemy(&self) -> Option<Monster<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testnestedflatbuffer(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
|
||||
pub fn testnestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None)}
|
||||
}
|
||||
pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
|
||||
self.testnestedflatbuffer().map(|data| {
|
||||
use flatbuffers::Follow;
|
||||
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid flatbuffer in this slot
|
||||
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
pub fn testempty(&self) -> Option<Stat<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testbool(&self) -> bool {
|
||||
self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs32_fnv1(&self) -> i32 {
|
||||
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu32_fnv1(&self) -> u32 {
|
||||
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs64_fnv1(&self) -> i64 {
|
||||
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu64_fnv1(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs32_fnv1a(&self) -> i32 {
|
||||
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu32_fnv1a(&self) -> u32 {
|
||||
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashs64_fnv1a(&self) -> i64 {
|
||||
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testhashu64_fnv1a(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofbools(&self) -> Option<&'a [bool]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None).map(|v| v.safe_slice())
|
||||
pub fn testarrayofbools(&self) -> Option<flatbuffers::Vector<'a, bool>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testf(&self) -> f32 {
|
||||
self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testf2(&self) -> f32 {
|
||||
self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testf3(&self) -> f32 {
|
||||
self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofstring2(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testarrayofsortedstruct(&self) -> Option<&'a [Ability]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None).map(|v| v.safe_slice())
|
||||
pub fn testarrayofsortedstruct(&self) -> Option<flatbuffers::Vector<'a, Ability>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn flex(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None).map(|v| v.safe_slice())
|
||||
pub fn flex(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn test5(&self) -> Option<&'a [Test]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None).map(|v| v.safe_slice())
|
||||
pub fn test5(&self) -> Option<flatbuffers::Vector<'a, Test>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_longs(&self) -> Option<flatbuffers::Vector<'a, i64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_doubles(&self) -> Option<flatbuffers::Vector<'a, f64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn parent_namespace_test(&self) -> Option<super::InParentNamespace<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn single_weak_reference(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_weak_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_strong_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn co_owning_reference(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_co_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn non_owning_reference(&self) -> u64 {
|
||||
self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_non_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_unique_type(&self) -> AnyUniqueAliases {
|
||||
self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_unique(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_ambiguous_type(&self) -> AnyAmbiguousAliases {
|
||||
self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn any_ambiguous(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vector_of_enums(&self) -> Option<flatbuffers::Vector<'a, Color>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn signed_enum(&self) -> Race {
|
||||
self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn testrequirednestedflatbuffer(&self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
|
||||
pub fn testrequirednestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None)}
|
||||
}
|
||||
pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
|
||||
self.testrequirednestedflatbuffer().map(|data| {
|
||||
use flatbuffers::Follow;
|
||||
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid flatbuffer in this slot
|
||||
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
pub fn scalar_key_sorted_tables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn native_inline(&self) -> Option<&'a Test> {
|
||||
self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn long_enum_non_enum_default(&self) -> LongEnum {
|
||||
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn long_enum_normal_default(&self) -> LongEnum {
|
||||
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_monster(&self) -> Option<Monster<'a>> {
|
||||
if self.test_type() == Any::Monster {
|
||||
self.test().map(Monster::init_from_table)
|
||||
self.test().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -614,7 +784,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_test_simple_table_with_enum(&self) -> Option<TestSimpleTableWithEnum<'a>> {
|
||||
if self.test_type() == Any::TestSimpleTableWithEnum {
|
||||
self.test().map(TestSimpleTableWithEnum::init_from_table)
|
||||
self.test().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -624,7 +799,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_my_game_example_2_monster(&self) -> Option<super::example_2::Monster<'a>> {
|
||||
if self.test_type() == Any::MyGame_Example2_Monster {
|
||||
self.test().map(super::example_2::Monster::init_from_table)
|
||||
self.test().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { super::example_2::Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -634,7 +814,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_m(&self) -> Option<Monster<'a>> {
|
||||
if self.any_unique_type() == AnyUniqueAliases::M {
|
||||
self.any_unique().map(Monster::init_from_table)
|
||||
self.any_unique().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -644,7 +829,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_ts(&self) -> Option<TestSimpleTableWithEnum<'a>> {
|
||||
if self.any_unique_type() == AnyUniqueAliases::TS {
|
||||
self.any_unique().map(TestSimpleTableWithEnum::init_from_table)
|
||||
self.any_unique().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -654,7 +844,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_m2(&self) -> Option<super::example_2::Monster<'a>> {
|
||||
if self.any_unique_type() == AnyUniqueAliases::M2 {
|
||||
self.any_unique().map(super::example_2::Monster::init_from_table)
|
||||
self.any_unique().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { super::example_2::Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -664,7 +859,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m1(&self) -> Option<Monster<'a>> {
|
||||
if self.any_ambiguous_type() == AnyAmbiguousAliases::M1 {
|
||||
self.any_ambiguous().map(Monster::init_from_table)
|
||||
self.any_ambiguous().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -674,7 +874,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m2(&self) -> Option<Monster<'a>> {
|
||||
if self.any_ambiguous_type() == AnyAmbiguousAliases::M2 {
|
||||
self.any_ambiguous().map(Monster::init_from_table)
|
||||
self.any_ambiguous().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -684,7 +889,12 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m3(&self) -> Option<Monster<'a>> {
|
||||
if self.any_ambiguous_type() == AnyAmbiguousAliases::M3 {
|
||||
self.any_ambiguous().map(Monster::init_from_table)
|
||||
self.any_ambiguous().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Monster::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -1610,7 +1820,7 @@ impl MonsterT {
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
let testarrayofstring = self.testarrayofstring.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
|
||||
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
let testarrayoftables = self.testarrayoftables.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
|
||||
@@ -1640,7 +1850,7 @@ impl MonsterT {
|
||||
let testf2 = self.testf2;
|
||||
let testf3 = self.testf3;
|
||||
let testarrayofstring2 = self.testarrayofstring2.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
|
||||
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
let testarrayofsortedstruct = self.testarrayofsortedstruct.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
|
||||
@@ -1753,18 +1963,6 @@ impl MonsterT {
|
||||
})
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
unsafe { flatbuffers::root_unchecked::<Monster<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a `Monster`
|
||||
/// and returns it.
|
||||
|
||||
@@ -74,10 +74,8 @@ impl Serialize for Race {
|
||||
impl<'a> flatbuffers::Follow<'a> for Race {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for Race {
|
||||
impl flatbuffers::Push for Race {
|
||||
type Output = Race;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Race {
|
||||
type Scalar = i8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i8::from_le(self.0);
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
let b = i8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct Referrable<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
|
||||
type Inner = Referrable<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<'a> Referrable<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Referrable { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> Referrable<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> u64 {
|
||||
self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn key_compare_less_than(&self, o: &Referrable) -> bool {
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct Stat<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
|
||||
type Inner = Stat<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ impl<'a> Stat<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Stat { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -66,15 +66,24 @@ impl<'a> Stat<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> Option<&'a str> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn val(&self) -> i64 {
|
||||
self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn count(&self) -> u16 {
|
||||
self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn key_compare_less_than(&self, o: &Stat) -> bool {
|
||||
|
||||
@@ -31,39 +31,25 @@ impl core::fmt::Debug for StructOfStructs {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructs {}
|
||||
impl flatbuffers::SafeSliceAccess for StructOfStructs {}
|
||||
impl<'a> flatbuffers::Follow<'a> for StructOfStructs {
|
||||
type Inner = &'a StructOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a StructOfStructs>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructs {
|
||||
type Inner = &'a StructOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<StructOfStructs>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for StructOfStructs {
|
||||
type Output = StructOfStructs;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b StructOfStructs {
|
||||
type Output = StructOfStructs;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -110,6 +96,9 @@ impl<'a> StructOfStructs {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> &Ability {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[0..].as_ptr() as *const Ability) }
|
||||
}
|
||||
|
||||
@@ -119,6 +108,9 @@ impl<'a> StructOfStructs {
|
||||
}
|
||||
|
||||
pub fn b(&self) -> &Test {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[8..].as_ptr() as *const Test) }
|
||||
}
|
||||
|
||||
@@ -128,6 +120,9 @@ impl<'a> StructOfStructs {
|
||||
}
|
||||
|
||||
pub fn c(&self) -> &Ability {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[12..].as_ptr() as *const Ability) }
|
||||
}
|
||||
|
||||
|
||||
@@ -29,39 +29,25 @@ impl core::fmt::Debug for StructOfStructsOfStructs {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {}
|
||||
impl flatbuffers::SafeSliceAccess for StructOfStructsOfStructs {}
|
||||
impl<'a> flatbuffers::Follow<'a> for StructOfStructsOfStructs {
|
||||
type Inner = &'a StructOfStructsOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a StructOfStructsOfStructs>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructsOfStructs {
|
||||
type Inner = &'a StructOfStructsOfStructs;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<StructOfStructsOfStructs>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
|
||||
type Output = StructOfStructsOfStructs;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b StructOfStructsOfStructs {
|
||||
type Output = StructOfStructsOfStructs;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const StructOfStructsOfStructs as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -102,6 +88,9 @@ impl<'a> StructOfStructsOfStructs {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> &StructOfStructs {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[0..].as_ptr() as *const StructOfStructs) }
|
||||
}
|
||||
|
||||
|
||||
@@ -30,39 +30,25 @@ impl core::fmt::Debug for Test {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Test {}
|
||||
impl flatbuffers::SafeSliceAccess for Test {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Test {
|
||||
type Inner = &'a Test;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Test>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Test {
|
||||
type Inner = &'a Test;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Test>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Test {
|
||||
type Output = Test;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Test {
|
||||
type Output = Test;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Test as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -106,47 +92,59 @@ impl<'a> Test {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i16 {
|
||||
let mut mem = core::mem::MaybeUninit::<i16>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i16 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i16>(),
|
||||
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i16) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i16 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i16>(),
|
||||
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn b(&self) -> i8 {
|
||||
let mut mem = core::mem::MaybeUninit::<i8>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i8 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[2..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i8>(),
|
||||
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_b(&mut self, x: i8) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i8 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[2..].as_mut_ptr(),
|
||||
core::mem::size_of::<i8>(),
|
||||
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct TestSimpleTableWithEnum<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
|
||||
type Inner = TestSimpleTableWithEnum<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<'a> TestSimpleTableWithEnum<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TestSimpleTableWithEnum { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> TestSimpleTableWithEnum<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn color(&self) -> Color {
|
||||
self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct TypeAliases<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
|
||||
type Inner = TypeAliases<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ impl<'a> TypeAliases<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TypeAliases { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -81,7 +81,7 @@ impl<'a> TypeAliases<'a> {
|
||||
let f32_ = self.f32_();
|
||||
let f64_ = self.f64_();
|
||||
let v8 = self.v8().map(|x| {
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let vf64 = self.vf64().map(|x| {
|
||||
x.into_iter().collect()
|
||||
@@ -104,51 +104,87 @@ impl<'a> TypeAliases<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn i8_(&self) -> i8 {
|
||||
self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u8_(&self) -> u8 {
|
||||
self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn i16_(&self) -> i16 {
|
||||
self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u16_(&self) -> u16 {
|
||||
self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn i32_(&self) -> i32 {
|
||||
self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u32_(&self) -> u32 {
|
||||
self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn i64_(&self) -> i64 {
|
||||
self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn u64_(&self) -> u64 {
|
||||
self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn f32_(&self) -> f32 {
|
||||
self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn f64_(&self) -> f64 {
|
||||
self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn v8(&self) -> Option<&'a [i8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None).map(|v| v.safe_slice())
|
||||
pub fn v8(&self) -> Option<flatbuffers::Vector<'a, i8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn vf64(&self) -> Option<flatbuffers::Vector<'a, f64>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,39 +34,25 @@ impl core::fmt::Debug for Vec3 {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Vec3 {}
|
||||
impl flatbuffers::SafeSliceAccess for Vec3 {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Vec3>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Vec3 {
|
||||
type Output = Vec3;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Vec3 {
|
||||
type Output = Vec3;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -122,121 +108,154 @@ impl<'a> Vec3 {
|
||||
}
|
||||
|
||||
pub fn x(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_x(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn y(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_y(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn z(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[8..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_z(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[8..].as_mut_ptr(),
|
||||
core::mem::size_of::<f32>(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test1(&self) -> f64 {
|
||||
let mut mem = core::mem::MaybeUninit::<f64>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<f64 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[16..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<f64>(),
|
||||
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_test1(&mut self, x: f64) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const f64 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[16..].as_mut_ptr(),
|
||||
core::mem::size_of::<f64>(),
|
||||
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test2(&self) -> Color {
|
||||
let mut mem = core::mem::MaybeUninit::<Color>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<Color as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[24..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<Color>(),
|
||||
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_test2(&mut self, x: Color) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const Color as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[24..].as_mut_ptr(),
|
||||
core::mem::size_of::<Color>(),
|
||||
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test3(&self) -> &Test {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid struct in this slot
|
||||
unsafe { &*(self.0[26..].as_ptr() as *const Test) }
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct Monster<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<'a> Monster<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Monster { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct InParentNamespace<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
|
||||
type Inner = InParentNamespace<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<'a> InParentNamespace<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
InParentNamespace { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
|
||||
@@ -62,10 +62,8 @@ impl Serialize for FromInclude {
|
||||
impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i64>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -73,21 +71,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
|
||||
impl flatbuffers::Push for FromInclude {
|
||||
type Output = FromInclude;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i64>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for FromInclude {
|
||||
type Scalar = i64;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i64::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i64 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i64::from_le(self.0);
|
||||
fn from_little_endian(v: i64) -> Self {
|
||||
let b = i64::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct TableB<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
|
||||
type Inner = TableB<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<'a> TableB<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableB { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -58,7 +58,10 @@ impl<'a> TableB<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn a(&self) -> Option<super::super::TableA<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,39 +29,25 @@ impl core::fmt::Debug for Unused {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
|
||||
impl flatbuffers::SafeSliceAccess for Unused {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Unused>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
|
||||
type Inner = &'a Unused;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Unused {
|
||||
type Output = Unused;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Unused {
|
||||
type Output = Unused;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -102,24 +88,30 @@ impl<'a> Unused {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct TableA<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
|
||||
type Inner = TableA<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<'a> TableA<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -58,7 +58,10 @@ impl<'a> TableA<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for ABC {
|
||||
impl<'a> flatbuffers::Follow<'a> for ABC {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i32>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i32>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for ABC {
|
||||
impl flatbuffers::Push for ABC {
|
||||
type Output = ABC;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i32>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for ABC {
|
||||
type Scalar = i32;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i32::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i32 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i32::from_le(self.0);
|
||||
fn from_little_endian(v: i32) -> Self {
|
||||
let b = i32::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct MoreDefaults<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for MoreDefaults<'a> {
|
||||
type Inner = MoreDefaults<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ impl<'a> MoreDefaults<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
MoreDefaults { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -78,7 +78,7 @@ impl<'a> MoreDefaults<'a> {
|
||||
};
|
||||
let bools = {
|
||||
let x = self.bools();
|
||||
x.to_vec()
|
||||
x.into_iter().collect()
|
||||
};
|
||||
MoreDefaultsT {
|
||||
ints,
|
||||
@@ -92,27 +92,45 @@ impl<'a> MoreDefaults<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn ints(&self) -> flatbuffers::Vector<'a, i32> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i32>>>(MoreDefaults::VT_INTS, Some(Default::default())).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i32>>>(MoreDefaults::VT_INTS, Some(Default::default())).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn floats(&self) -> flatbuffers::Vector<'a, f32> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f32>>>(MoreDefaults::VT_FLOATS, Some(Default::default())).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f32>>>(MoreDefaults::VT_FLOATS, Some(Default::default())).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn empty_string(&self) -> &'a str {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_EMPTY_STRING, Some(&"")).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_EMPTY_STRING, Some(&"")).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn some_string(&self) -> &'a str {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_SOME_STRING, Some(&"some")).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_SOME_STRING, Some(&"some")).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn abcs(&self) -> flatbuffers::Vector<'a, ABC> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, ABC>>>(MoreDefaults::VT_ABCS, Some(Default::default())).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, ABC>>>(MoreDefaults::VT_ABCS, Some(Default::default())).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn bools(&self) -> &'a [bool] {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(MoreDefaults::VT_BOOLS, Some(Default::default())).map(|v| v.safe_slice()).unwrap()
|
||||
pub fn bools(&self) -> flatbuffers::Vector<'a, bool> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(MoreDefaults::VT_BOOLS, Some(Default::default())).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for EnumInNestedNS {
|
||||
impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
|
||||
impl flatbuffers::Push for EnumInNestedNS {
|
||||
type Output = EnumInNestedNS;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for EnumInNestedNS {
|
||||
type Scalar = i8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i8::from_le(self.0);
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
let b = i8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,39 +28,25 @@ impl core::fmt::Debug for StructInNestedNS {
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for StructInNestedNS {}
|
||||
impl flatbuffers::SafeSliceAccess for StructInNestedNS {}
|
||||
impl<'a> flatbuffers::Follow<'a> for StructInNestedNS {
|
||||
type Inner = &'a StructInNestedNS;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a StructInNestedNS>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a StructInNestedNS {
|
||||
type Inner = &'a StructInNestedNS;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<StructInNestedNS>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for StructInNestedNS {
|
||||
type Output = StructInNestedNS;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b StructInNestedNS {
|
||||
type Output = StructInNestedNS;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::core::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -92,47 +78,59 @@ impl<'a> StructInNestedNS {
|
||||
}
|
||||
|
||||
pub fn a(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_a(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn b(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_b(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableInNestedNS<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableInNestedNS<'a> {
|
||||
type Inner = TableInNestedNS<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> TableInNestedNS<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableInNestedNS { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -54,7 +54,10 @@ impl<'a> TableInNestedNS<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn foo(&self) -> i32 {
|
||||
self._tab.get::<i32>(TableInNestedNS::VT_FOO, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(TableInNestedNS::VT_FOO, Some(0)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,10 +55,8 @@ impl core::fmt::Debug for UnionInNestedNS {
|
||||
impl<'a> flatbuffers::Follow<'a> for UnionInNestedNS {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -66,21 +64,21 @@ impl<'a> flatbuffers::Follow<'a> for UnionInNestedNS {
|
||||
impl flatbuffers::Push for UnionInNestedNS {
|
||||
type Output = UnionInNestedNS;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for UnionInNestedNS {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct SecondTableInA<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for SecondTableInA<'a> {
|
||||
type Inner = SecondTableInA<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> SecondTableInA<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
SecondTableInA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -56,7 +56,10 @@ impl<'a> SecondTableInA<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn refer_to_c(&self) -> Option<super::namespace_c::TableInC<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_c::TableInC>>(SecondTableInA::VT_REFER_TO_C, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_c::TableInC>>(SecondTableInA::VT_REFER_TO_C, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableInFirstNS<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableInFirstNS<'a> {
|
||||
type Inner = TableInFirstNS<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ impl<'a> TableInFirstNS<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableInFirstNS { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -80,29 +80,49 @@ impl<'a> TableInFirstNS<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn foo_table(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS>>(TableInFirstNS::VT_FOO_TABLE, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS>>(TableInFirstNS::VT_FOO_TABLE, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn foo_enum(&self) -> namespace_b::EnumInNestedNS {
|
||||
self._tab.get::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, Some(namespace_b::EnumInNestedNS::A)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, Some(namespace_b::EnumInNestedNS::A)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn foo_union_type(&self) -> namespace_b::UnionInNestedNS {
|
||||
self._tab.get::<namespace_b::UnionInNestedNS>(TableInFirstNS::VT_FOO_UNION_TYPE, Some(namespace_b::UnionInNestedNS::NONE)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<namespace_b::UnionInNestedNS>(TableInFirstNS::VT_FOO_UNION_TYPE, Some(namespace_b::UnionInNestedNS::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn foo_union(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(TableInFirstNS::VT_FOO_UNION, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(TableInFirstNS::VT_FOO_UNION, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn foo_struct(&self) -> Option<&'a namespace_b::StructInNestedNS> {
|
||||
self._tab.get::<namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, None)}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn foo_union_as_table_in_nested_ns(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
|
||||
if self.foo_union_type() == namespace_b::UnionInNestedNS::TableInNestedNS {
|
||||
self.foo_union().map(namespace_b::TableInNestedNS::init_from_table)
|
||||
self.foo_union().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { namespace_b::TableInNestedNS::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct TableInC<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for TableInC<'a> {
|
||||
type Inner = TableInC<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<'a> TableInC<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableInC { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -62,11 +62,17 @@ impl<'a> TableInC<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn refer_to_a1(&self) -> Option<super::namespace_a::TableInFirstNS<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::TableInFirstNS>>(TableInC::VT_REFER_TO_A1, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::TableInFirstNS>>(TableInC::VT_REFER_TO_A1, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn refer_to_a2(&self) -> Option<super::namespace_a::SecondTableInA<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::SecondTableInA>>(TableInC::VT_REFER_TO_A2, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::SecondTableInA>>(TableInC::VT_REFER_TO_A2, None)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for OptionalByte {
|
||||
impl<'a> flatbuffers::Follow<'a> for OptionalByte {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for OptionalByte {
|
||||
impl flatbuffers::Push for OptionalByte {
|
||||
type Output = OptionalByte;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for OptionalByte {
|
||||
type Scalar = i8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i8::from_le(self.0);
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
let b = i8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct ScalarStuff<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for ScalarStuff<'a> {
|
||||
type Inner = ScalarStuff<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ impl<'a> ScalarStuff<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
ScalarStuff { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -194,147 +194,255 @@ impl<'a> ScalarStuff<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn just_i8(&self) -> i8 {
|
||||
self._tab.get::<i8>(ScalarStuff::VT_JUST_I8, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i8>(ScalarStuff::VT_JUST_I8, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_i8(&self) -> Option<i8> {
|
||||
self._tab.get::<i8>(ScalarStuff::VT_MAYBE_I8, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i8>(ScalarStuff::VT_MAYBE_I8, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_i8(&self) -> i8 {
|
||||
self._tab.get::<i8>(ScalarStuff::VT_DEFAULT_I8, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i8>(ScalarStuff::VT_DEFAULT_I8, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_u8(&self) -> u8 {
|
||||
self._tab.get::<u8>(ScalarStuff::VT_JUST_U8, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u8>(ScalarStuff::VT_JUST_U8, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_u8(&self) -> Option<u8> {
|
||||
self._tab.get::<u8>(ScalarStuff::VT_MAYBE_U8, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u8>(ScalarStuff::VT_MAYBE_U8, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_u8(&self) -> u8 {
|
||||
self._tab.get::<u8>(ScalarStuff::VT_DEFAULT_U8, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u8>(ScalarStuff::VT_DEFAULT_U8, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_i16(&self) -> i16 {
|
||||
self._tab.get::<i16>(ScalarStuff::VT_JUST_I16, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(ScalarStuff::VT_JUST_I16, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_i16(&self) -> Option<i16> {
|
||||
self._tab.get::<i16>(ScalarStuff::VT_MAYBE_I16, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(ScalarStuff::VT_MAYBE_I16, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_i16(&self) -> i16 {
|
||||
self._tab.get::<i16>(ScalarStuff::VT_DEFAULT_I16, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(ScalarStuff::VT_DEFAULT_I16, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_u16(&self) -> u16 {
|
||||
self._tab.get::<u16>(ScalarStuff::VT_JUST_U16, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u16>(ScalarStuff::VT_JUST_U16, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_u16(&self) -> Option<u16> {
|
||||
self._tab.get::<u16>(ScalarStuff::VT_MAYBE_U16, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u16>(ScalarStuff::VT_MAYBE_U16, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_u16(&self) -> u16 {
|
||||
self._tab.get::<u16>(ScalarStuff::VT_DEFAULT_U16, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u16>(ScalarStuff::VT_DEFAULT_U16, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_i32(&self) -> i32 {
|
||||
self._tab.get::<i32>(ScalarStuff::VT_JUST_I32, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(ScalarStuff::VT_JUST_I32, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_i32(&self) -> Option<i32> {
|
||||
self._tab.get::<i32>(ScalarStuff::VT_MAYBE_I32, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(ScalarStuff::VT_MAYBE_I32, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_i32(&self) -> i32 {
|
||||
self._tab.get::<i32>(ScalarStuff::VT_DEFAULT_I32, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(ScalarStuff::VT_DEFAULT_I32, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_u32(&self) -> u32 {
|
||||
self._tab.get::<u32>(ScalarStuff::VT_JUST_U32, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(ScalarStuff::VT_JUST_U32, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_u32(&self) -> Option<u32> {
|
||||
self._tab.get::<u32>(ScalarStuff::VT_MAYBE_U32, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(ScalarStuff::VT_MAYBE_U32, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_u32(&self) -> u32 {
|
||||
self._tab.get::<u32>(ScalarStuff::VT_DEFAULT_U32, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(ScalarStuff::VT_DEFAULT_U32, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_i64(&self) -> i64 {
|
||||
self._tab.get::<i64>(ScalarStuff::VT_JUST_I64, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(ScalarStuff::VT_JUST_I64, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_i64(&self) -> Option<i64> {
|
||||
self._tab.get::<i64>(ScalarStuff::VT_MAYBE_I64, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(ScalarStuff::VT_MAYBE_I64, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_i64(&self) -> i64 {
|
||||
self._tab.get::<i64>(ScalarStuff::VT_DEFAULT_I64, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(ScalarStuff::VT_DEFAULT_I64, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_u64(&self) -> u64 {
|
||||
self._tab.get::<u64>(ScalarStuff::VT_JUST_U64, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(ScalarStuff::VT_JUST_U64, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_u64(&self) -> Option<u64> {
|
||||
self._tab.get::<u64>(ScalarStuff::VT_MAYBE_U64, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(ScalarStuff::VT_MAYBE_U64, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_u64(&self) -> u64 {
|
||||
self._tab.get::<u64>(ScalarStuff::VT_DEFAULT_U64, Some(42)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(ScalarStuff::VT_DEFAULT_U64, Some(42)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_f32(&self) -> f32 {
|
||||
self._tab.get::<f32>(ScalarStuff::VT_JUST_F32, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(ScalarStuff::VT_JUST_F32, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_f32(&self) -> Option<f32> {
|
||||
self._tab.get::<f32>(ScalarStuff::VT_MAYBE_F32, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(ScalarStuff::VT_MAYBE_F32, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_f32(&self) -> f32 {
|
||||
self._tab.get::<f32>(ScalarStuff::VT_DEFAULT_F32, Some(42.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f32>(ScalarStuff::VT_DEFAULT_F32, Some(42.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_f64(&self) -> f64 {
|
||||
self._tab.get::<f64>(ScalarStuff::VT_JUST_F64, Some(0.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f64>(ScalarStuff::VT_JUST_F64, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_f64(&self) -> Option<f64> {
|
||||
self._tab.get::<f64>(ScalarStuff::VT_MAYBE_F64, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f64>(ScalarStuff::VT_MAYBE_F64, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_f64(&self) -> f64 {
|
||||
self._tab.get::<f64>(ScalarStuff::VT_DEFAULT_F64, Some(42.0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f64>(ScalarStuff::VT_DEFAULT_F64, Some(42.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_bool(&self) -> bool {
|
||||
self._tab.get::<bool>(ScalarStuff::VT_JUST_BOOL, Some(false)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<bool>(ScalarStuff::VT_JUST_BOOL, Some(false)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_bool(&self) -> Option<bool> {
|
||||
self._tab.get::<bool>(ScalarStuff::VT_MAYBE_BOOL, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<bool>(ScalarStuff::VT_MAYBE_BOOL, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_bool(&self) -> bool {
|
||||
self._tab.get::<bool>(ScalarStuff::VT_DEFAULT_BOOL, Some(true)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<bool>(ScalarStuff::VT_DEFAULT_BOOL, Some(true)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn just_enum(&self) -> OptionalByte {
|
||||
self._tab.get::<OptionalByte>(ScalarStuff::VT_JUST_ENUM, Some(OptionalByte::None)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<OptionalByte>(ScalarStuff::VT_JUST_ENUM, Some(OptionalByte::None)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn maybe_enum(&self) -> Option<OptionalByte> {
|
||||
self._tab.get::<OptionalByte>(ScalarStuff::VT_MAYBE_ENUM, None)
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<OptionalByte>(ScalarStuff::VT_MAYBE_ENUM, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn default_enum(&self) -> OptionalByte {
|
||||
self._tab.get::<OptionalByte>(ScalarStuff::VT_DEFAULT_ENUM, Some(OptionalByte::One)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<OptionalByte>(ScalarStuff::VT_DEFAULT_ENUM, Some(OptionalByte::One)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,18 +944,6 @@ impl ScalarStuffT {
|
||||
})
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_root_as_scalar_stuff<'a>(buf: &'a [u8]) -> ScalarStuff<'a> {
|
||||
unsafe { flatbuffers::root_unchecked::<ScalarStuff<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
|
||||
pub fn get_size_prefixed_root_as_scalar_stuff<'a>(buf: &'a [u8]) -> ScalarStuff<'a> {
|
||||
unsafe { flatbuffers::size_prefixed_root_unchecked::<ScalarStuff<'a>>(buf) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a `ScalarStuff`
|
||||
/// and returns it.
|
||||
|
||||
@@ -55,10 +55,8 @@ impl core::fmt::Debug for AB {
|
||||
impl<'a> flatbuffers::Follow<'a> for AB {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<i8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -66,21 +64,21 @@ impl<'a> flatbuffers::Follow<'a> for AB {
|
||||
impl flatbuffers::Push for AB {
|
||||
type Output = AB;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for AB {
|
||||
type Scalar = i8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = i8::from_le(self.0);
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
let b = i8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub(crate) struct Annotations<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Annotations<'a> {
|
||||
type Inner = Annotations<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> Annotations<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Annotations { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -54,7 +54,10 @@ impl<'a> Annotations<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn value(&self) -> i32 {
|
||||
self._tab.get::<i32>(Annotations::VT_VALUE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(Annotations::VT_VALUE, Some(0)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,8 @@ impl core::fmt::Debug for Any {
|
||||
impl<'a> flatbuffers::Follow<'a> for Any {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe {
|
||||
flatbuffers::read_scalar_at::<u8>(buf, loc)
|
||||
};
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for Any {
|
||||
impl flatbuffers::Push for Any {
|
||||
type Output = Any;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Any {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let b = u8::to_le(self.0);
|
||||
Self(b)
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let b = u8::from_le(self.0);
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ pub(crate) struct Game<'a> {
|
||||
impl<'a> flatbuffers::Follow<'a> for Game<'a> {
|
||||
type Inner = Game<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> Game<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Game { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
@@ -54,7 +54,10 @@ impl<'a> Game<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn value(&self) -> i32 {
|
||||
self._tab.get::<i32>(Game::VT_VALUE, Some(0)).unwrap()
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i32>(Game::VT_VALUE, Some(0)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,39 +27,25 @@ impl core::fmt::Debug for Object {
|
||||
}
|
||||
|
||||
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 {
|
||||
unsafe 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 {
|
||||
unsafe 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())
|
||||
};
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Object as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
@@ -89,24 +75,30 @@ impl<'a> Object {
|
||||
}
|
||||
|
||||
pub fn value(&self) -> i32 {
|
||||
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
|
||||
unsafe {
|
||||
let mut mem = core::mem::MaybeUninit::<<i32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
}.from_little_endian()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_value(&mut self, x: i32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const i32 as *const u8,
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<i32>(),
|
||||
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
|
||||
)
|
||||
.as_union_value(),
|
||||
),
|
||||
inventory: Some(builder.create_vector_direct(&[0u8, 1, 2, 3, 4][..])),
|
||||
test4: Some(builder.create_vector_direct(&[
|
||||
inventory: Some(builder.create_vector(&[0u8, 1, 2, 3, 4])),
|
||||
test4: Some(builder.create_vector(&[
|
||||
my_game::example::Test::new(10, 20),
|
||||
my_game::example::Test::new(30, 40),
|
||||
])),
|
||||
|
||||
@@ -86,8 +86,8 @@ fn create_serialized_example_with_generated_code(
|
||||
let mon = {
|
||||
let name = builder.create_string("MyMonster");
|
||||
let fred_name = builder.create_string("Fred");
|
||||
let inventory = builder.create_vector_direct(&[0u8, 1, 2, 3, 4]);
|
||||
let test4 = builder.create_vector_direct(&[
|
||||
let inventory = builder.create_vector(&[0u8, 1, 2, 3, 4]);
|
||||
let test4 = builder.create_vector(&[
|
||||
my_game::example::Test::new(10, 20),
|
||||
my_game::example::Test::new(30, 40),
|
||||
]);
|
||||
@@ -156,7 +156,7 @@ fn traverse_serialized_example_with_generated_code(bytes: &[u8]) {
|
||||
blackbox(pos_test3.b());
|
||||
blackbox(m.test_type());
|
||||
let table2 = m.test().unwrap();
|
||||
let monster2 = my_game::example::Monster::init_from_table(table2);
|
||||
let monster2 = unsafe { my_game::example::Monster::init_from_table(table2) };
|
||||
blackbox(monster2.name());
|
||||
blackbox(m.inventory());
|
||||
blackbox(m.test4());
|
||||
@@ -228,7 +228,7 @@ fn create_byte_vector_100_optimal(bench: &mut Bencher) {
|
||||
|
||||
let mut i = 0;
|
||||
bench.iter(|| {
|
||||
builder.create_vector_direct(v);
|
||||
builder.create_vector(v);
|
||||
i += 1;
|
||||
if i == 10000 {
|
||||
builder.reset();
|
||||
|
||||
@@ -12,6 +12,7 @@ impl TrackingAllocator {
|
||||
unsafe { N_ALLOCS }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl GlobalAlloc for TrackingAllocator {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
N_ALLOCS += 1;
|
||||
@@ -28,6 +29,7 @@ static A: TrackingAllocator = TrackingAllocator;
|
||||
|
||||
// import the flatbuffers generated code:
|
||||
extern crate flatbuffers;
|
||||
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[path = "../../include_test1/mod.rs"]
|
||||
pub mod include_test1_generated;
|
||||
@@ -39,20 +41,22 @@ pub mod include_test2_generated;
|
||||
#[allow(dead_code, unused_imports, clippy::approx_constant)]
|
||||
#[path = "../../monster_test/mod.rs"]
|
||||
mod monster_test_generated;
|
||||
|
||||
pub use monster_test_generated::my_game;
|
||||
|
||||
// verbatim from the test suite:
|
||||
fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::FlatBufferBuilder) {
|
||||
let mon = {
|
||||
let _ = builder.create_vector_of_strings(&[
|
||||
"these",
|
||||
"unused",
|
||||
"strings",
|
||||
"check",
|
||||
"the",
|
||||
"create_vector_of_strings",
|
||||
"function",
|
||||
]);
|
||||
let strings = [
|
||||
builder.create_string("these"),
|
||||
builder.create_string("unused"),
|
||||
builder.create_string("strings"),
|
||||
builder.create_string("check"),
|
||||
builder.create_string("the"),
|
||||
builder.create_string("create_vector_of_strings"),
|
||||
builder.create_string("function")
|
||||
];
|
||||
let _ = builder.create_vector(&strings);
|
||||
|
||||
let s0 = builder.create_string("test1");
|
||||
let s1 = builder.create_string("test2");
|
||||
@@ -83,10 +87,10 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.as_union_value(),
|
||||
.as_union_value(),
|
||||
),
|
||||
inventory: Some(builder.create_vector_direct(&[0u8, 1, 2, 3, 4][..])),
|
||||
test4: Some(builder.create_vector_direct(&[
|
||||
inventory: Some(builder.create_vector(&[0u8, 1, 2, 3, 4])),
|
||||
test4: Some(builder.create_vector(&[
|
||||
my_game::example::Test::new(10, 20),
|
||||
my_game::example::Test::new(30, 40),
|
||||
])),
|
||||
@@ -151,7 +155,7 @@ fn main() {
|
||||
assert_eq!(pos_test3.b(), 6i8);
|
||||
assert_eq!(m.test_type(), my_game::example::Any::Monster);
|
||||
let table2 = m.test().unwrap();
|
||||
let m2 = my_game::example::Monster::init_from_table(table2);
|
||||
let m2 = unsafe { my_game::example::Monster::init_from_table(table2) };
|
||||
|
||||
assert_eq!(m2.name(), "Fred");
|
||||
|
||||
@@ -162,10 +166,10 @@ fn main() {
|
||||
let test4 = m.test4().unwrap();
|
||||
assert_eq!(test4.len(), 2);
|
||||
assert_eq!(
|
||||
i32::from(test4[0].a())
|
||||
+ i32::from(test4[1].a())
|
||||
+ i32::from(test4[0].b())
|
||||
+ i32::from(test4[1].b()),
|
||||
i32::from(test4.get(0).a())
|
||||
+ i32::from(test4.get(1).a())
|
||||
+ i32::from(test4.get(0).b())
|
||||
+ i32::from(test4.get(1).b()),
|
||||
100
|
||||
);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user