mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-24 11:11:46 +00:00
[TS] Fix generation of struct members in object api (#7148)
* Fix C/C++ Create<Type>Direct with sorted vectors If a struct has a key the vector has to be sorted. To sort the vector you can't use "const". * Changes due to code review * Improve code readability * Add generate of JSON schema to string to lib * option indent_step is supported * Remove unused variables * Fix break in test * Fix style to be consistent with rest of the code * [TS] Fix reserved words as arguments (#6955) * [TS] Fix generation of reserved words in object api (#7106) * [TS] Fix generation of object api * [TS] Fix MakeCamel -> ConvertCase * [TS] Add test for struct of struct of struct * Update generated files * Add missing files * [TS] Fix query of null/undefined fields in object api
This commit is contained in:
@@ -25,6 +25,8 @@ pub mod my_game {
|
||||
pub use self::ability_generated::*;
|
||||
mod struct_of_structs_generated;
|
||||
pub use self::struct_of_structs_generated::*;
|
||||
mod struct_of_structs_of_structs_generated;
|
||||
pub use self::struct_of_structs_of_structs_generated::*;
|
||||
mod stat_generated;
|
||||
pub use self::stat_generated::*;
|
||||
mod referrable_generated;
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
extern crate flatbuffers;
|
||||
use std::mem;
|
||||
use std::cmp::Ordering;
|
||||
extern crate serde;
|
||||
use self::serde::ser::{Serialize, Serializer, SerializeStruct};
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
// struct StructOfStructsOfStructs, aligned to 4
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct StructOfStructsOfStructs(pub [u8; 20]);
|
||||
impl Default for StructOfStructsOfStructs {
|
||||
fn default() -> Self {
|
||||
Self([0; 20])
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for StructOfStructsOfStructs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("StructOfStructsOfStructs")
|
||||
.field("a", &self.a())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
<&'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 {
|
||||
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 {
|
||||
::std::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 {
|
||||
::std::slice::from_raw_parts(*self as *const StructOfStructsOfStructs as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for StructOfStructsOfStructs {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for StructOfStructsOfStructs {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_struct("StructOfStructsOfStructs", 1)?;
|
||||
s.serialize_field("a", &self.a())?;
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> StructOfStructsOfStructs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
a: &StructOfStructs,
|
||||
) -> Self {
|
||||
let mut s = Self([0; 20]);
|
||||
s.set_a(a);
|
||||
s
|
||||
}
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.Example.StructOfStructsOfStructs"
|
||||
}
|
||||
|
||||
pub fn a(&self) -> &StructOfStructs {
|
||||
unsafe { &*(self.0[0..].as_ptr() as *const StructOfStructs) }
|
||||
}
|
||||
|
||||
#[allow(clippy::identity_op)]
|
||||
pub fn set_a(&mut self, x: &StructOfStructs) {
|
||||
self.0[0..0 + 20].copy_from_slice(&x.0)
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> StructOfStructsOfStructsT {
|
||||
StructOfStructsOfStructsT {
|
||||
a: self.a().unpack(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct StructOfStructsOfStructsT {
|
||||
pub a: StructOfStructsT,
|
||||
}
|
||||
impl StructOfStructsOfStructsT {
|
||||
pub fn pack(&self) -> StructOfStructsOfStructs {
|
||||
StructOfStructsOfStructs::new(
|
||||
&self.a.pack(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user