forked from BigfootDev/flatbuffers
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -339,6 +339,12 @@ flatc(
|
||||
schema="arrays_test.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
RUST_OPTS,
|
||||
prefix="rust_namer_test",
|
||||
schema="rust_namer_test.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + PYTHON_OPTS,
|
||||
schema="arrays_test.fbs",
|
||||
|
||||
@@ -146,7 +146,8 @@ class IdlNamer : public Namer {
|
||||
|
||||
std::string LegacyRustUnionTypeMethod(const FieldDef &d) {
|
||||
// assert d is a union
|
||||
return Method(d.name + "_type");
|
||||
// d should convert case but not escape keywords due to historical reasons
|
||||
return ConvertCase(d.name, config_.fields, Case::kLowerCamel) + "_type";
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
27
tests/rust_namer_test.fbs
Normal file
27
tests/rust_namer_test.fbs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace RustNamerTest;
|
||||
|
||||
table FieldTable {}
|
||||
|
||||
union FieldUnion {
|
||||
f :FieldTable (id: 0),
|
||||
}
|
||||
|
||||
table RootTable {
|
||||
field42 :FieldUnion (id: 1);
|
||||
}
|
||||
|
||||
table PlayerStatEvent {}
|
||||
table PlayerSpectate {}
|
||||
table PlayerInputChange {}
|
||||
|
||||
union GameMessage
|
||||
{
|
||||
PlayerStatEvent,
|
||||
PlayerSpectate,
|
||||
PlayerInputChange
|
||||
}
|
||||
|
||||
table GameMessageWrapper
|
||||
{
|
||||
Message:GameMessage;
|
||||
}
|
||||
21
tests/rust_namer_test/mod.rs
Normal file
21
tests/rust_namer_test/mod.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
// Automatically generated by the Flatbuffers compiler. Do not modify.
|
||||
// @generated
|
||||
pub mod rust_namer_test {
|
||||
use super::*;
|
||||
mod field_union_generated;
|
||||
pub use self::field_union_generated::*;
|
||||
mod game_message_generated;
|
||||
pub use self::game_message_generated::*;
|
||||
mod field_table_generated;
|
||||
pub use self::field_table_generated::*;
|
||||
mod root_table_generated;
|
||||
pub use self::root_table_generated::*;
|
||||
mod player_stat_event_generated;
|
||||
pub use self::player_stat_event_generated::*;
|
||||
mod player_spectate_generated;
|
||||
pub use self::player_spectate_generated::*;
|
||||
mod player_input_change_generated;
|
||||
pub use self::player_input_change_generated::*;
|
||||
mod game_message_wrapper_generated;
|
||||
pub use self::game_message_wrapper_generated::*;
|
||||
} // rust_namer_test
|
||||
117
tests/rust_namer_test/rust_namer_test/field_table_generated.rs
Normal file
117
tests/rust_namer_test/rust_namer_test/field_table_generated.rs
Normal file
@@ -0,0 +1,117 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum FieldTableOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct FieldTable<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for FieldTable<'a> {
|
||||
type Inner = FieldTable<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FieldTable<'a> {
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"RustNamerTest.FieldTable"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
FieldTable { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
_args: &'args FieldTableArgs
|
||||
) -> flatbuffers::WIPOffset<FieldTable<'bldr>> {
|
||||
let mut builder = FieldTableBuilder::new(_fbb);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> FieldTableT {
|
||||
FieldTableT {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for FieldTable<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct FieldTableArgs {
|
||||
}
|
||||
impl<'a> Default for FieldTableArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
FieldTableArgs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FieldTableBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> FieldTableBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> FieldTableBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
FieldTableBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<FieldTable<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for FieldTable<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("FieldTable");
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FieldTableT {
|
||||
}
|
||||
impl Default for FieldTableT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl FieldTableT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<FieldTable<'b>> {
|
||||
FieldTable::create(_fbb, &FieldTableArgs{
|
||||
})
|
||||
}
|
||||
}
|
||||
145
tests/rust_namer_test/rust_namer_test/field_union_generated.rs
Normal file
145
tests/rust_namer_test/rust_namer_test/field_union_generated.rs
Normal file
@@ -0,0 +1,145 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MIN_FIELD_UNION: u8 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MAX_FIELD_UNION: u8 = 1;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_VALUES_FIELD_UNION: [FieldUnion; 2] = [
|
||||
FieldUnion::NONE,
|
||||
FieldUnion::f,
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct FieldUnion(pub u8);
|
||||
#[allow(non_upper_case_globals)]
|
||||
impl FieldUnion {
|
||||
pub const NONE: Self = Self(0);
|
||||
pub const f: Self = Self(1);
|
||||
|
||||
pub const ENUM_MIN: u8 = 0;
|
||||
pub const ENUM_MAX: u8 = 1;
|
||||
pub const ENUM_VALUES: &'static [Self] = &[
|
||||
Self::NONE,
|
||||
Self::f,
|
||||
];
|
||||
/// Returns the variant's name or "" if unknown.
|
||||
pub fn variant_name(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::NONE => Some("NONE"),
|
||||
Self::f => Some("f"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::fmt::Debug for FieldUnion {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
f.write_str(name)
|
||||
} else {
|
||||
f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for FieldUnion {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for FieldUnion {
|
||||
type Output = FieldUnion;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for FieldUnion {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for FieldUnion {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
u8::run_verifier(v, pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for FieldUnion {}
|
||||
pub struct FieldUnionUnionTableOffset {}
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum FieldUnionT {
|
||||
NONE,
|
||||
F(Box<FieldTableT>),
|
||||
}
|
||||
impl Default for FieldUnionT {
|
||||
fn default() -> Self {
|
||||
Self::NONE
|
||||
}
|
||||
}
|
||||
impl FieldUnionT {
|
||||
pub fn field_union_type(&self) -> FieldUnion {
|
||||
match self {
|
||||
Self::NONE => FieldUnion::NONE,
|
||||
Self::F(_) => FieldUnion::f,
|
||||
}
|
||||
}
|
||||
pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
|
||||
match self {
|
||||
Self::NONE => None,
|
||||
Self::F(v) => Some(v.pack(fbb).as_union_value()),
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return the owned FieldTableT, setting the union to NONE.
|
||||
pub fn take_f(&mut self) -> Option<Box<FieldTableT>> {
|
||||
if let Self::F(_) = self {
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::F(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return a reference to the FieldTableT.
|
||||
pub fn as_f(&self) -> Option<&FieldTableT> {
|
||||
if let Self::F(v) = self { Some(v.as_ref()) } else { None }
|
||||
}
|
||||
/// If the union variant matches, return a mutable reference to the FieldTableT.
|
||||
pub fn as_f_mut(&mut self) -> Option<&mut FieldTableT> {
|
||||
if let Self::F(v) = self { Some(v.as_mut()) } else { None }
|
||||
}
|
||||
}
|
||||
201
tests/rust_namer_test/rust_namer_test/game_message_generated.rs
Normal file
201
tests/rust_namer_test/rust_namer_test/game_message_generated.rs
Normal file
@@ -0,0 +1,201 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MIN_GAME_MESSAGE: u8 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MAX_GAME_MESSAGE: u8 = 3;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_VALUES_GAME_MESSAGE: [GameMessage; 4] = [
|
||||
GameMessage::NONE,
|
||||
GameMessage::PlayerStatEvent,
|
||||
GameMessage::PlayerSpectate,
|
||||
GameMessage::PlayerInputChange,
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct GameMessage(pub u8);
|
||||
#[allow(non_upper_case_globals)]
|
||||
impl GameMessage {
|
||||
pub const NONE: Self = Self(0);
|
||||
pub const PlayerStatEvent: Self = Self(1);
|
||||
pub const PlayerSpectate: Self = Self(2);
|
||||
pub const PlayerInputChange: Self = Self(3);
|
||||
|
||||
pub const ENUM_MIN: u8 = 0;
|
||||
pub const ENUM_MAX: u8 = 3;
|
||||
pub const ENUM_VALUES: &'static [Self] = &[
|
||||
Self::NONE,
|
||||
Self::PlayerStatEvent,
|
||||
Self::PlayerSpectate,
|
||||
Self::PlayerInputChange,
|
||||
];
|
||||
/// Returns the variant's name or "" if unknown.
|
||||
pub fn variant_name(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::NONE => Some("NONE"),
|
||||
Self::PlayerStatEvent => Some("PlayerStatEvent"),
|
||||
Self::PlayerSpectate => Some("PlayerSpectate"),
|
||||
Self::PlayerInputChange => Some("PlayerInputChange"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::fmt::Debug for GameMessage {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
f.write_str(name)
|
||||
} else {
|
||||
f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for GameMessage {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for GameMessage {
|
||||
type Output = GameMessage;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for GameMessage {
|
||||
type Scalar = u8;
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> u8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(v: u8) -> Self {
|
||||
let b = u8::from_le(v);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for GameMessage {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
u8::run_verifier(v, pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for GameMessage {}
|
||||
pub struct GameMessageUnionTableOffset {}
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum GameMessageT {
|
||||
NONE,
|
||||
PlayerStatEvent(Box<PlayerStatEventT>),
|
||||
PlayerSpectate(Box<PlayerSpectateT>),
|
||||
PlayerInputChange(Box<PlayerInputChangeT>),
|
||||
}
|
||||
impl Default for GameMessageT {
|
||||
fn default() -> Self {
|
||||
Self::NONE
|
||||
}
|
||||
}
|
||||
impl GameMessageT {
|
||||
pub fn game_message_type(&self) -> GameMessage {
|
||||
match self {
|
||||
Self::NONE => GameMessage::NONE,
|
||||
Self::PlayerStatEvent(_) => GameMessage::PlayerStatEvent,
|
||||
Self::PlayerSpectate(_) => GameMessage::PlayerSpectate,
|
||||
Self::PlayerInputChange(_) => GameMessage::PlayerInputChange,
|
||||
}
|
||||
}
|
||||
pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
|
||||
match self {
|
||||
Self::NONE => None,
|
||||
Self::PlayerStatEvent(v) => Some(v.pack(fbb).as_union_value()),
|
||||
Self::PlayerSpectate(v) => Some(v.pack(fbb).as_union_value()),
|
||||
Self::PlayerInputChange(v) => Some(v.pack(fbb).as_union_value()),
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return the owned PlayerStatEventT, setting the union to NONE.
|
||||
pub fn take_player_stat_event(&mut self) -> Option<Box<PlayerStatEventT>> {
|
||||
if let Self::PlayerStatEvent(_) = self {
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::PlayerStatEvent(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return a reference to the PlayerStatEventT.
|
||||
pub fn as_player_stat_event(&self) -> Option<&PlayerStatEventT> {
|
||||
if let Self::PlayerStatEvent(v) = self { Some(v.as_ref()) } else { None }
|
||||
}
|
||||
/// If the union variant matches, return a mutable reference to the PlayerStatEventT.
|
||||
pub fn as_player_stat_event_mut(&mut self) -> Option<&mut PlayerStatEventT> {
|
||||
if let Self::PlayerStatEvent(v) = self { Some(v.as_mut()) } else { None }
|
||||
}
|
||||
/// If the union variant matches, return the owned PlayerSpectateT, setting the union to NONE.
|
||||
pub fn take_player_spectate(&mut self) -> Option<Box<PlayerSpectateT>> {
|
||||
if let Self::PlayerSpectate(_) = self {
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::PlayerSpectate(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return a reference to the PlayerSpectateT.
|
||||
pub fn as_player_spectate(&self) -> Option<&PlayerSpectateT> {
|
||||
if let Self::PlayerSpectate(v) = self { Some(v.as_ref()) } else { None }
|
||||
}
|
||||
/// If the union variant matches, return a mutable reference to the PlayerSpectateT.
|
||||
pub fn as_player_spectate_mut(&mut self) -> Option<&mut PlayerSpectateT> {
|
||||
if let Self::PlayerSpectate(v) = self { Some(v.as_mut()) } else { None }
|
||||
}
|
||||
/// If the union variant matches, return the owned PlayerInputChangeT, setting the union to NONE.
|
||||
pub fn take_player_input_change(&mut self) -> Option<Box<PlayerInputChangeT>> {
|
||||
if let Self::PlayerInputChange(_) = self {
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::PlayerInputChange(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return a reference to the PlayerInputChangeT.
|
||||
pub fn as_player_input_change(&self) -> Option<&PlayerInputChangeT> {
|
||||
if let Self::PlayerInputChange(v) = self { Some(v.as_ref()) } else { None }
|
||||
}
|
||||
/// If the union variant matches, return a mutable reference to the PlayerInputChangeT.
|
||||
pub fn as_player_input_change_mut(&mut self) -> Option<&mut PlayerInputChangeT> {
|
||||
if let Self::PlayerInputChange(v) = self { Some(v.as_mut()) } else { None }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum GameMessageWrapperOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct GameMessageWrapper<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for GameMessageWrapper<'a> {
|
||||
type Inner = GameMessageWrapper<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GameMessageWrapper<'a> {
|
||||
pub const VT_MESSAGE_TYPE: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_MESSAGE: flatbuffers::VOffsetT = 6;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"RustNamerTest.GameMessageWrapper"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
GameMessageWrapper { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args GameMessageWrapperArgs
|
||||
) -> flatbuffers::WIPOffset<GameMessageWrapper<'bldr>> {
|
||||
let mut builder = GameMessageWrapperBuilder::new(_fbb);
|
||||
if let Some(x) = args.Message { builder.add_Message(x); }
|
||||
builder.add_Message_type(args.Message_type);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> GameMessageWrapperT {
|
||||
let Message = match self.Message_type() {
|
||||
GameMessage::NONE => GameMessageT::NONE,
|
||||
GameMessage::PlayerStatEvent => GameMessageT::PlayerStatEvent(Box::new(
|
||||
self.Message_as_player_stat_event()
|
||||
.expect("Invalid union table, expected `GameMessage::PlayerStatEvent`.")
|
||||
.unpack()
|
||||
)),
|
||||
GameMessage::PlayerSpectate => GameMessageT::PlayerSpectate(Box::new(
|
||||
self.Message_as_player_spectate()
|
||||
.expect("Invalid union table, expected `GameMessage::PlayerSpectate`.")
|
||||
.unpack()
|
||||
)),
|
||||
GameMessage::PlayerInputChange => GameMessageT::PlayerInputChange(Box::new(
|
||||
self.Message_as_player_input_change()
|
||||
.expect("Invalid union table, expected `GameMessage::PlayerInputChange`.")
|
||||
.unpack()
|
||||
)),
|
||||
_ => GameMessageT::NONE,
|
||||
};
|
||||
GameMessageWrapperT {
|
||||
Message,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn Message_type(&self) -> GameMessage {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<GameMessage>(GameMessageWrapper::VT_MESSAGE_TYPE, Some(GameMessage::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn Message(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
// 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>>>(GameMessageWrapper::VT_MESSAGE, None)}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Message_as_player_stat_event(&self) -> Option<PlayerStatEvent<'a>> {
|
||||
if self.Message_type() == GameMessage::PlayerStatEvent {
|
||||
self.Message().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { PlayerStatEvent::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Message_as_player_spectate(&self) -> Option<PlayerSpectate<'a>> {
|
||||
if self.Message_type() == GameMessage::PlayerSpectate {
|
||||
self.Message().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { PlayerSpectate::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Message_as_player_input_change(&self) -> Option<PlayerInputChange<'a>> {
|
||||
if self.Message_type() == GameMessage::PlayerInputChange {
|
||||
self.Message().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { PlayerInputChange::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for GameMessageWrapper<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_union::<GameMessage, _>("Message_type", Self::VT_MESSAGE_TYPE, "Message", Self::VT_MESSAGE, false, |key, v, pos| {
|
||||
match key {
|
||||
GameMessage::PlayerStatEvent => v.verify_union_variant::<flatbuffers::ForwardsUOffset<PlayerStatEvent>>("GameMessage::PlayerStatEvent", pos),
|
||||
GameMessage::PlayerSpectate => v.verify_union_variant::<flatbuffers::ForwardsUOffset<PlayerSpectate>>("GameMessage::PlayerSpectate", pos),
|
||||
GameMessage::PlayerInputChange => v.verify_union_variant::<flatbuffers::ForwardsUOffset<PlayerInputChange>>("GameMessage::PlayerInputChange", pos),
|
||||
_ => Ok(()),
|
||||
}
|
||||
})?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct GameMessageWrapperArgs {
|
||||
pub Message_type: GameMessage,
|
||||
pub Message: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
|
||||
}
|
||||
impl<'a> Default for GameMessageWrapperArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
GameMessageWrapperArgs {
|
||||
Message_type: GameMessage::NONE,
|
||||
Message: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GameMessageWrapperBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> GameMessageWrapperBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_Message_type(&mut self, Message_type: GameMessage) {
|
||||
self.fbb_.push_slot::<GameMessage>(GameMessageWrapper::VT_MESSAGE_TYPE, Message_type, GameMessage::NONE);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_Message(&mut self, Message: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(GameMessageWrapper::VT_MESSAGE, Message);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> GameMessageWrapperBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
GameMessageWrapperBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<GameMessageWrapper<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for GameMessageWrapper<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("GameMessageWrapper");
|
||||
ds.field("Message_type", &self.Message_type());
|
||||
match self.Message_type() {
|
||||
GameMessage::PlayerStatEvent => {
|
||||
if let Some(x) = self.Message_as_player_stat_event() {
|
||||
ds.field("Message", &x)
|
||||
} else {
|
||||
ds.field("Message", &"InvalidFlatbuffer: Union discriminant does not match value.")
|
||||
}
|
||||
},
|
||||
GameMessage::PlayerSpectate => {
|
||||
if let Some(x) = self.Message_as_player_spectate() {
|
||||
ds.field("Message", &x)
|
||||
} else {
|
||||
ds.field("Message", &"InvalidFlatbuffer: Union discriminant does not match value.")
|
||||
}
|
||||
},
|
||||
GameMessage::PlayerInputChange => {
|
||||
if let Some(x) = self.Message_as_player_input_change() {
|
||||
ds.field("Message", &x)
|
||||
} else {
|
||||
ds.field("Message", &"InvalidFlatbuffer: Union discriminant does not match value.")
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let x: Option<()> = None;
|
||||
ds.field("Message", &x)
|
||||
},
|
||||
};
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct GameMessageWrapperT {
|
||||
pub Message: GameMessageT,
|
||||
}
|
||||
impl Default for GameMessageWrapperT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
Message: GameMessageT::NONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl GameMessageWrapperT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<GameMessageWrapper<'b>> {
|
||||
let Message_type = self.Message.game_message_type();
|
||||
let Message = self.Message.pack(_fbb);
|
||||
GameMessageWrapper::create(_fbb, &GameMessageWrapperArgs{
|
||||
Message_type,
|
||||
Message,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum PlayerInputChangeOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct PlayerInputChange<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for PlayerInputChange<'a> {
|
||||
type Inner = PlayerInputChange<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PlayerInputChange<'a> {
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"RustNamerTest.PlayerInputChange"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
PlayerInputChange { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
_args: &'args PlayerInputChangeArgs
|
||||
) -> flatbuffers::WIPOffset<PlayerInputChange<'bldr>> {
|
||||
let mut builder = PlayerInputChangeBuilder::new(_fbb);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> PlayerInputChangeT {
|
||||
PlayerInputChangeT {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for PlayerInputChange<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct PlayerInputChangeArgs {
|
||||
}
|
||||
impl<'a> Default for PlayerInputChangeArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
PlayerInputChangeArgs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlayerInputChangeBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> PlayerInputChangeBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> PlayerInputChangeBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
PlayerInputChangeBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<PlayerInputChange<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for PlayerInputChange<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("PlayerInputChange");
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PlayerInputChangeT {
|
||||
}
|
||||
impl Default for PlayerInputChangeT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl PlayerInputChangeT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<PlayerInputChange<'b>> {
|
||||
PlayerInputChange::create(_fbb, &PlayerInputChangeArgs{
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum PlayerSpectateOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct PlayerSpectate<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for PlayerSpectate<'a> {
|
||||
type Inner = PlayerSpectate<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PlayerSpectate<'a> {
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"RustNamerTest.PlayerSpectate"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
PlayerSpectate { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
_args: &'args PlayerSpectateArgs
|
||||
) -> flatbuffers::WIPOffset<PlayerSpectate<'bldr>> {
|
||||
let mut builder = PlayerSpectateBuilder::new(_fbb);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> PlayerSpectateT {
|
||||
PlayerSpectateT {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for PlayerSpectate<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct PlayerSpectateArgs {
|
||||
}
|
||||
impl<'a> Default for PlayerSpectateArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
PlayerSpectateArgs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlayerSpectateBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> PlayerSpectateBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> PlayerSpectateBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
PlayerSpectateBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<PlayerSpectate<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for PlayerSpectate<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("PlayerSpectate");
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PlayerSpectateT {
|
||||
}
|
||||
impl Default for PlayerSpectateT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl PlayerSpectateT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<PlayerSpectate<'b>> {
|
||||
PlayerSpectate::create(_fbb, &PlayerSpectateArgs{
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum PlayerStatEventOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct PlayerStatEvent<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for PlayerStatEvent<'a> {
|
||||
type Inner = PlayerStatEvent<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PlayerStatEvent<'a> {
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"RustNamerTest.PlayerStatEvent"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
PlayerStatEvent { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
_args: &'args PlayerStatEventArgs
|
||||
) -> flatbuffers::WIPOffset<PlayerStatEvent<'bldr>> {
|
||||
let mut builder = PlayerStatEventBuilder::new(_fbb);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> PlayerStatEventT {
|
||||
PlayerStatEventT {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for PlayerStatEvent<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct PlayerStatEventArgs {
|
||||
}
|
||||
impl<'a> Default for PlayerStatEventArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
PlayerStatEventArgs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlayerStatEventBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> PlayerStatEventBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> PlayerStatEventBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
PlayerStatEventBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<PlayerStatEvent<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for PlayerStatEvent<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("PlayerStatEvent");
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PlayerStatEventT {
|
||||
}
|
||||
impl Default for PlayerStatEventT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl PlayerStatEventT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<PlayerStatEvent<'b>> {
|
||||
PlayerStatEvent::create(_fbb, &PlayerStatEventArgs{
|
||||
})
|
||||
}
|
||||
}
|
||||
199
tests/rust_namer_test/rust_namer_test/root_table_generated.rs
Normal file
199
tests/rust_namer_test/rust_namer_test/root_table_generated.rs
Normal file
@@ -0,0 +1,199 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum RootTableOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct RootTable<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for RootTable<'a> {
|
||||
type Inner = RootTable<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RootTable<'a> {
|
||||
pub const VT_FIELD42_TYPE: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_FIELD42: flatbuffers::VOffsetT = 6;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"RustNamerTest.RootTable"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
RootTable { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args RootTableArgs
|
||||
) -> flatbuffers::WIPOffset<RootTable<'bldr>> {
|
||||
let mut builder = RootTableBuilder::new(_fbb);
|
||||
if let Some(x) = args.field42 { builder.add_field42(x); }
|
||||
builder.add_field42_type(args.field42_type);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> RootTableT {
|
||||
let field42 = match self.field42_type() {
|
||||
FieldUnion::NONE => FieldUnionT::NONE,
|
||||
FieldUnion::f => FieldUnionT::F(Box::new(
|
||||
self.field42_as_f()
|
||||
.expect("Invalid union table, expected `FieldUnion::f`.")
|
||||
.unpack()
|
||||
)),
|
||||
_ => FieldUnionT::NONE,
|
||||
};
|
||||
RootTableT {
|
||||
field42,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn field42_type(&self) -> FieldUnion {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<FieldUnion>(RootTable::VT_FIELD42_TYPE, Some(FieldUnion::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn field42(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
// 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>>>(RootTable::VT_FIELD42, None)}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn field42_as_f(&self) -> Option<FieldTable<'a>> {
|
||||
if self.field42_type() == FieldUnion::f {
|
||||
self.field42().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { FieldTable::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for RootTable<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_union::<FieldUnion, _>("field42_type", Self::VT_FIELD42_TYPE, "field42", Self::VT_FIELD42, false, |key, v, pos| {
|
||||
match key {
|
||||
FieldUnion::f => v.verify_union_variant::<flatbuffers::ForwardsUOffset<FieldTable>>("FieldUnion::f", pos),
|
||||
_ => Ok(()),
|
||||
}
|
||||
})?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct RootTableArgs {
|
||||
pub field42_type: FieldUnion,
|
||||
pub field42: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
|
||||
}
|
||||
impl<'a> Default for RootTableArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
RootTableArgs {
|
||||
field42_type: FieldUnion::NONE,
|
||||
field42: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RootTableBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> RootTableBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_field42_type(&mut self, field42_type: FieldUnion) {
|
||||
self.fbb_.push_slot::<FieldUnion>(RootTable::VT_FIELD42_TYPE, field42_type, FieldUnion::NONE);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_field42(&mut self, field42: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(RootTable::VT_FIELD42, field42);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> RootTableBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
RootTableBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<RootTable<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for RootTable<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("RootTable");
|
||||
ds.field("field42_type", &self.field42_type());
|
||||
match self.field42_type() {
|
||||
FieldUnion::f => {
|
||||
if let Some(x) = self.field42_as_f() {
|
||||
ds.field("field42", &x)
|
||||
} else {
|
||||
ds.field("field42", &"InvalidFlatbuffer: Union discriminant does not match value.")
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let x: Option<()> = None;
|
||||
ds.field("field42", &x)
|
||||
},
|
||||
};
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct RootTableT {
|
||||
pub field42: FieldUnionT,
|
||||
}
|
||||
impl Default for RootTableT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
field42: FieldUnionT::NONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl RootTableT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<RootTable<'b>> {
|
||||
let field42_type = self.field42.field_union_type();
|
||||
let field42 = self.field42.pack(_fbb);
|
||||
RootTable::create(_fbb, &RootTableArgs{
|
||||
field42_type,
|
||||
field42,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,11 @@ mod arrays_test_generated;
|
||||
#[path = "../../keyword_test/mod.rs"]
|
||||
mod keyword_test_generated;
|
||||
|
||||
// Test rust namer, should not cause compiling issues
|
||||
#[allow(dead_code, unused_imports, clippy::all)]
|
||||
#[path = "../../rust_namer_test/mod.rs"]
|
||||
mod rust_namer_test;
|
||||
|
||||
#[rustfmt::skip] // TODO: Use standard rust formatting and remove dead code.
|
||||
#[allow(dead_code)]
|
||||
mod flatbuffers_tests {
|
||||
|
||||
Reference in New Issue
Block a user