mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 15:37:27 +00:00
* Refactored Rust Generated code into a module directory. Each symbol will be generated into one file and then imported into a module. This breaks the "out_dir" pattern where some users would generate code in their target/ directory. Also, these objects are best used in their own module. It will be hard for users to share their own module structure with flatbuffers namespaces. There may be solutions to these drawbacks but that should be discussed. I don't want to overengineer here. * shadow error * try fix .bat file * fix .bat 2 * Restore accidentally deleted files * Fixed some DONOTSUBMITs and made Rust outdir pattern use symlinks. * fixed binary files * git clang format * make generated onefiles not public and fix .bat * reduced diff with master in generate_code.sh * fix shadowed variable * add object api flags to .bat * space * Removed extern crate and extra & * use statement * more clippy lints * format * Undo extern crate -> use change, it actually matters to our tests Co-authored-by: Casper Neo <cneo@google.com>
185 lines
4.7 KiB
Rust
185 lines
4.7 KiB
Rust
// automatically generated by the FlatBuffers compiler, do not modify
|
|
extern crate flatbuffers;
|
|
use std::mem;
|
|
use std::cmp::Ordering;
|
|
use self::flatbuffers::{EndianScalar, Follow};
|
|
use super::*;
|
|
pub enum StatOffset {}
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub struct Stat<'a> {
|
|
pub _tab: flatbuffers::Table<'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 } }
|
|
}
|
|
}
|
|
|
|
impl<'a> Stat<'a> {
|
|
pub const fn get_fully_qualified_name() -> &'static str {
|
|
"MyGame.Example.Stat"
|
|
}
|
|
|
|
#[inline]
|
|
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
|
Stat { _tab: table }
|
|
}
|
|
#[allow(unused_mut)]
|
|
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
|
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
|
args: &'args StatArgs<'args>) -> flatbuffers::WIPOffset<Stat<'bldr>> {
|
|
let mut builder = StatBuilder::new(_fbb);
|
|
builder.add_val(args.val);
|
|
if let Some(x) = args.id { builder.add_id(x); }
|
|
builder.add_count(args.count);
|
|
builder.finish()
|
|
}
|
|
|
|
pub fn unpack(&self) -> StatT {
|
|
let id = self.id().map(|x| {
|
|
x.to_string()
|
|
});
|
|
let val = self.val();
|
|
let count = self.count();
|
|
StatT {
|
|
id,
|
|
val,
|
|
count,
|
|
}
|
|
}
|
|
pub const VT_ID: flatbuffers::VOffsetT = 4;
|
|
pub const VT_VAL: flatbuffers::VOffsetT = 6;
|
|
pub const VT_COUNT: flatbuffers::VOffsetT = 8;
|
|
|
|
#[inline]
|
|
pub fn id(&self) -> Option<&'a str> {
|
|
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()
|
|
}
|
|
#[inline]
|
|
pub fn count(&self) -> u16 {
|
|
self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()
|
|
}
|
|
#[inline]
|
|
pub fn key_compare_less_than(&self, o: &Stat) -> bool {
|
|
self.count() < o.count()
|
|
}
|
|
|
|
#[inline]
|
|
pub fn key_compare_with_value(&self, val: u16) -> ::std::cmp::Ordering {
|
|
let key = self.count();
|
|
key.cmp(&val)
|
|
}
|
|
}
|
|
|
|
impl flatbuffers::Verifiable for Stat<'_> {
|
|
#[inline]
|
|
fn run_verifier(
|
|
v: &mut flatbuffers::Verifier, pos: usize
|
|
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
|
use self::flatbuffers::Verifiable;
|
|
v.visit_table(pos)?
|
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("id", Self::VT_ID, false)?
|
|
.visit_field::<i64>("val", Self::VT_VAL, false)?
|
|
.visit_field::<u16>("count", Self::VT_COUNT, false)?
|
|
.finish();
|
|
Ok(())
|
|
}
|
|
}
|
|
pub struct StatArgs<'a> {
|
|
pub id: Option<flatbuffers::WIPOffset<&'a str>>,
|
|
pub val: i64,
|
|
pub count: u16,
|
|
}
|
|
impl<'a> Default for StatArgs<'a> {
|
|
#[inline]
|
|
fn default() -> Self {
|
|
StatArgs {
|
|
id: None,
|
|
val: 0,
|
|
count: 0,
|
|
}
|
|
}
|
|
}
|
|
pub struct StatBuilder<'a: 'b, 'b> {
|
|
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
|
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
|
}
|
|
impl<'a: 'b, 'b> StatBuilder<'a, 'b> {
|
|
#[inline]
|
|
pub fn add_id(&mut self, id: flatbuffers::WIPOffset<&'b str>) {
|
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Stat::VT_ID, id);
|
|
}
|
|
#[inline]
|
|
pub fn add_val(&mut self, val: i64) {
|
|
self.fbb_.push_slot::<i64>(Stat::VT_VAL, val, 0);
|
|
}
|
|
#[inline]
|
|
pub fn add_count(&mut self, count: u16) {
|
|
self.fbb_.push_slot::<u16>(Stat::VT_COUNT, count, 0);
|
|
}
|
|
#[inline]
|
|
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> StatBuilder<'a, 'b> {
|
|
let start = _fbb.start_table();
|
|
StatBuilder {
|
|
fbb_: _fbb,
|
|
start_: start,
|
|
}
|
|
}
|
|
#[inline]
|
|
pub fn finish(self) -> flatbuffers::WIPOffset<Stat<'a>> {
|
|
let o = self.fbb_.end_table(self.start_);
|
|
flatbuffers::WIPOffset::new(o.value())
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for Stat<'_> {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
let mut ds = f.debug_struct("Stat");
|
|
ds.field("id", &self.id());
|
|
ds.field("val", &self.val());
|
|
ds.field("count", &self.count());
|
|
ds.finish()
|
|
}
|
|
}
|
|
#[non_exhaustive]
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct StatT {
|
|
pub id: Option<String>,
|
|
pub val: i64,
|
|
pub count: u16,
|
|
}
|
|
impl Default for StatT {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: None,
|
|
val: 0,
|
|
count: 0,
|
|
}
|
|
}
|
|
}
|
|
impl StatT {
|
|
pub fn pack<'b>(
|
|
&self,
|
|
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
|
) -> flatbuffers::WIPOffset<Stat<'b>> {
|
|
let id = self.id.as_ref().map(|x|{
|
|
_fbb.create_string(x)
|
|
});
|
|
let val = self.val;
|
|
let count = self.count;
|
|
Stat::create(_fbb, &StatArgs{
|
|
id,
|
|
val,
|
|
count,
|
|
})
|
|
}
|
|
}
|