[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:
tira-misu
2022-03-24 05:40:11 +01:00
committed by GitHub
parent 4213d91054
commit 2ad408697f
27 changed files with 1490 additions and 344 deletions

View File

@@ -55,7 +55,7 @@ class TsGenerator : public BaseGenerator {
// https://github.com/microsoft/TypeScript/issues/2536
// One per line to ease comparisons to that list are easier
static const char *const keywords[] = {
"argument",
"arguments",
"break",
"case",
"catch",
@@ -956,15 +956,22 @@ class TsGenerator : public BaseGenerator {
it != struct_def.fields.vec.end(); ++it) {
auto &field = **it;
const auto curr_member_accessor =
auto curr_member_accessor =
prefix + "." + ConvertCase(field.name, Case::kLowerCamel);
if (prefix != "this") {
curr_member_accessor =
prefix + "?." + ConvertCase(field.name, Case::kLowerCamel);
}
if (IsStruct(field.value.type)) {
ret += GenStructMemberValueTS(*field.value.type.struct_def,
curr_member_accessor, delimiter);
} else {
if (nullCheck) {
ret +=
"(" + prefix + " === null ? 0 : " + curr_member_accessor + "!)";
std::string nullValue = "0";
if (field.value.type.base_type == BASE_TYPE_BOOL) {
nullValue = "false";
}
ret += "(" + curr_member_accessor + " ?? " + nullValue + ")";
} else {
ret += curr_member_accessor;
}
@@ -1067,7 +1074,7 @@ class TsGenerator : public BaseGenerator {
parser.opts);
const std::string field_accessor =
"this." + field_name_escaped + "()";
"this." + field_name + "()";
field_val = GenNullCheckConditional(field_accessor,
field_accessor + "!.unpack()");
auto packing = GenNullCheckConditional(

View File

@@ -611,6 +611,72 @@ public struct MyGame_Example_StructOfStructs_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_StructOfStructsOfStructs: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_2_0_0() }
private var _a: MyGame_Example_StructOfStructs
public init(_ bb: ByteBuffer, o: Int32) {
let _accessor = Struct(bb: bb, position: o)
_a = MyGame_Example_StructOfStructs(_accessor.bb, o: _accessor.postion + 0)
}
public init(a: MyGame_Example_StructOfStructs) {
_a = a
}
public init() {
_a = MyGame_Example_StructOfStructs()
}
public init(_ _t: inout MyGame_Example_StructOfStructsOfStructs_Mutable) {
var _va = _t.a
_a = _va.unpack()
}
public var a: MyGame_Example_StructOfStructs { _a }
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
try verifier.inBuffer(position: position, of: MyGame_Example_StructOfStructsOfStructs.self)
}
}
extension MyGame_Example_StructOfStructsOfStructs: Encodable {
enum CodingKeys: String, CodingKey {
case a = "a"
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(a, forKey: .a)
}
}
public struct MyGame_Example_StructOfStructsOfStructs_Mutable: FlatBufferObject {
static func validateVersion() { FlatBuffersVersion_2_0_0() }
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Struct
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
public var a: MyGame_Example_StructOfStructs_Mutable { return MyGame_Example_StructOfStructs_Mutable(_accessor.bb, o: _accessor.postion + 0) }
public mutating func unpack() -> MyGame_Example_StructOfStructsOfStructs {
return MyGame_Example_StructOfStructsOfStructs(&self)
}
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout MyGame_Example_StructOfStructsOfStructs?) -> Offset {
guard var obj = obj else { return Offset() }
return pack(&builder, obj: &obj)
}
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout MyGame_Example_StructOfStructsOfStructs) -> Offset {
return builder.create(struct: obj)
}
}
public struct MyGame_InParentNamespace: FlatBufferObject, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_2_0_0() }

View File

@@ -0,0 +1,74 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
namespace MyGame.Example
{
using global::System;
using global::System.Collections.Generic;
using global::FlatBuffers;
public struct StructOfStructsOfStructs : IFlatbufferObject
{
private Struct __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); }
public StructOfStructsOfStructs __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public MyGame.Example.StructOfStructs A { get { return (new MyGame.Example.StructOfStructs()).__assign(__p.bb_pos + 0, __p.bb); } }
public static Offset<MyGame.Example.StructOfStructsOfStructs> CreateStructOfStructsOfStructs(FlatBufferBuilder builder, uint a_a_Id, uint a_a_Distance, short a_b_A, sbyte a_b_B, uint a_c_Id, uint a_c_Distance) {
builder.Prep(4, 20);
builder.Prep(4, 20);
builder.Prep(4, 8);
builder.PutUint(a_c_Distance);
builder.PutUint(a_c_Id);
builder.Prep(2, 4);
builder.Pad(1);
builder.PutSbyte(a_b_B);
builder.PutShort(a_b_A);
builder.Prep(4, 8);
builder.PutUint(a_a_Distance);
builder.PutUint(a_a_Id);
return new Offset<MyGame.Example.StructOfStructsOfStructs>(builder.Offset);
}
public StructOfStructsOfStructsT UnPack() {
var _o = new StructOfStructsOfStructsT();
this.UnPackTo(_o);
return _o;
}
public void UnPackTo(StructOfStructsOfStructsT _o) {
_o.A = this.A.UnPack();
}
public static Offset<MyGame.Example.StructOfStructsOfStructs> Pack(FlatBufferBuilder builder, StructOfStructsOfStructsT _o) {
if (_o == null) return default(Offset<MyGame.Example.StructOfStructsOfStructs>);
var _a_a_id = _o.A.A.Id;
var _a_a_distance = _o.A.A.Distance;
var _a_b_a = _o.A.B.A;
var _a_b_b = _o.A.B.B;
var _a_c_id = _o.A.C.Id;
var _a_c_distance = _o.A.C.Distance;
return CreateStructOfStructsOfStructs(
builder,
_a_a_id,
_a_a_distance,
_a_b_a,
_a_b_b,
_a_c_id,
_a_c_distance);
}
}
public class StructOfStructsOfStructsT
{
[Newtonsoft.Json.JsonProperty("a")]
public MyGame.Example.StructOfStructsT A { get; set; }
public StructOfStructsOfStructsT() {
this.A = new MyGame.Example.StructOfStructsT();
}
}
}

View File

@@ -0,0 +1,63 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package Example
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type StructOfStructsOfStructsT struct {
A *StructOfStructsT
}
func (t *StructOfStructsOfStructsT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 }
return CreateStructOfStructsOfStructs(builder, t.A.A.Id, t.A.A.Distance, t.A.B.A, t.A.B.B, t.A.C.Id, t.A.C.Distance)
}
func (rcv *StructOfStructsOfStructs) UnPackTo(t *StructOfStructsOfStructsT) {
t.A = rcv.A(nil).UnPack()
}
func (rcv *StructOfStructsOfStructs) UnPack() *StructOfStructsOfStructsT {
if rcv == nil { return nil }
t := &StructOfStructsOfStructsT{}
rcv.UnPackTo(t)
return t
}
type StructOfStructsOfStructs struct {
_tab flatbuffers.Struct
}
func (rcv *StructOfStructsOfStructs) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *StructOfStructsOfStructs) Table() flatbuffers.Table {
return rcv._tab.Table
}
func (rcv *StructOfStructsOfStructs) A(obj *StructOfStructs) *StructOfStructs {
if obj == nil {
obj = new(StructOfStructs)
}
obj.Init(rcv._tab.Bytes, rcv._tab.Pos+0)
return obj
}
func CreateStructOfStructsOfStructs(builder *flatbuffers.Builder, a_a_id uint32, a_a_distance uint32, a_b_a int16, a_b_b int8, a_c_id uint32, a_c_distance uint32) flatbuffers.UOffsetT {
builder.Prep(4, 20)
builder.Prep(4, 20)
builder.Prep(4, 8)
builder.PrependUint32(a_c_distance)
builder.PrependUint32(a_c_id)
builder.Prep(2, 4)
builder.Pad(1)
builder.PrependInt8(a_b_b)
builder.PrependInt16(a_b_a)
builder.Prep(4, 8)
builder.PrependUint32(a_a_distance)
builder.PrependUint32(a_a_id)
return builder.Offset()
}

View File

@@ -0,0 +1,66 @@
// automatically generated by the FlatBuffers compiler, do not modify
package MyGame.Example;
import java.nio.*;
import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
@SuppressWarnings("unused")
public final class StructOfStructsOfStructs extends Struct {
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
public StructOfStructsOfStructs __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public MyGame.Example.StructOfStructs a() { return a(new MyGame.Example.StructOfStructs()); }
public MyGame.Example.StructOfStructs a(MyGame.Example.StructOfStructs obj) { return obj.__assign(bb_pos + 0, bb); }
public static int createStructOfStructsOfStructs(FlatBufferBuilder builder, long a_a_id, long a_a_distance, short a_b_a, byte a_b_b, long a_c_id, long a_c_distance) {
builder.prep(4, 20);
builder.prep(4, 20);
builder.prep(4, 8);
builder.putInt((int) a_c_distance);
builder.putInt((int) a_c_id);
builder.prep(2, 4);
builder.pad(1);
builder.putByte(a_b_b);
builder.putShort(a_b_a);
builder.prep(4, 8);
builder.putInt((int) a_a_distance);
builder.putInt((int) a_a_id);
return builder.offset();
}
public static final class Vector extends BaseVector {
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
public StructOfStructsOfStructs get(int j) { return get(new StructOfStructsOfStructs(), j); }
public StructOfStructsOfStructs get(StructOfStructsOfStructs obj, int j) { return obj.__assign(__element(j), bb); }
}
public StructOfStructsOfStructsT unpack() {
StructOfStructsOfStructsT _o = new StructOfStructsOfStructsT();
unpackTo(_o);
return _o;
}
public void unpackTo(StructOfStructsOfStructsT _o) {
a().unpackTo(_o.getA());
}
public static int pack(FlatBufferBuilder builder, StructOfStructsOfStructsT _o) {
if (_o == null) return 0;
int _a_a_id = _o.getA().getA().getId();
int _a_a_distance = _o.getA().getA().getDistance();
short _a_b_a = _o.getA().getB().getA();
byte _a_b_b = _o.getA().getB().getB();
int _a_c_id = _o.getA().getC().getId();
int _a_c_distance = _o.getA().getC().getDistance();
return createStructOfStructsOfStructs(
builder,
_a_a_id,
_a_a_distance,
_a_b_a,
_a_b_b,
_a_c_id,
_a_c_distance);
}
}

View File

@@ -0,0 +1,38 @@
// automatically generated by the FlatBuffers compiler, do not modify
package MyGame.Example
import java.nio.*
import kotlin.math.sign
import com.google.flatbuffers.*
@Suppress("unused")
class StructOfStructsOfStructs : Struct() {
fun __init(_i: Int, _bb: ByteBuffer) {
__reset(_i, _bb)
}
fun __assign(_i: Int, _bb: ByteBuffer) : StructOfStructsOfStructs {
__init(_i, _bb)
return this
}
val a : MyGame.Example.StructOfStructs? get() = a(MyGame.Example.StructOfStructs())
fun a(obj: MyGame.Example.StructOfStructs) : MyGame.Example.StructOfStructs? = obj.__assign(bb_pos + 0, bb)
companion object {
fun createStructOfStructsOfStructs(builder: FlatBufferBuilder, a_a_id: UInt, a_a_distance: UInt, a_b_a: Short, a_b_b: Byte, a_c_id: UInt, a_c_distance: UInt) : Int {
builder.prep(4, 20)
builder.prep(4, 20)
builder.prep(4, 8)
builder.putInt(a_c_distance.toInt())
builder.putInt(a_c_id.toInt())
builder.prep(2, 4)
builder.pad(1)
builder.putByte(a_b_b)
builder.putShort(a_b_a)
builder.prep(4, 8)
builder.putInt(a_a_distance.toInt())
builder.putInt(a_a_id.toInt())
return builder.offset()
}
}
}

View File

@@ -0,0 +1,49 @@
--[[ MyGame.Example.StructOfStructsOfStructs
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 2.0.6
Declared by : //monster_test.fbs
Rooting type : MyGame.Example.Monster (//monster_test.fbs)
--]]
local flatbuffers = require('flatbuffers')
local StructOfStructsOfStructs = {}
local mt = {}
function StructOfStructsOfStructs.New()
local o = {}
setmetatable(o, {__index = mt})
return o
end
function mt:Init(buf, pos)
self.view = flatbuffers.view.New(buf, pos)
end
function mt:A(obj)
obj:Init(self.view.bytes, self.view.pos + 0)
return obj
end
function StructOfStructsOfStructs.CreateStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, a_c_id, a_c_distance)
builder:Prep(4, 20)
builder:Prep(4, 20)
builder:Prep(4, 8)
builder:PrependUint32(a_c_distance)
builder:PrependUint32(a_c_id)
builder:Prep(2, 4)
builder:Pad(1)
builder:PrependInt8(a_b_b)
builder:PrependInt16(a_b_a)
builder:Prep(4, 8)
builder:PrependUint32(a_a_distance)
builder:PrependUint32(a_a_id)
return builder:Offset()
end
return StructOfStructsOfStructs

View File

@@ -0,0 +1,55 @@
<?php
// automatically generated by the FlatBuffers compiler, do not modify
namespace MyGame\Example;
use \Google\FlatBuffers\Struct;
use \Google\FlatBuffers\Table;
use \Google\FlatBuffers\ByteBuffer;
use \Google\FlatBuffers\FlatBufferBuilder;
class StructOfStructsOfStructs extends Struct
{
/**
* @param int $_i offset
* @param ByteBuffer $_bb
* @return StructOfStructsOfStructs
**/
public function init($_i, ByteBuffer $_bb)
{
$this->bb_pos = $_i;
$this->bb = $_bb;
return $this;
}
/**
* @return StructOfStructs
*/
public function getA()
{
$obj = new StructOfStructs();
$obj->init($this->bb_pos + 0, $this->bb);
return $obj;
}
/**
* @return int offset
*/
public static function createStructOfStructsOfStructs(FlatBufferBuilder $builder, $a_a_id, $a_a_distance, $a_b_a, $a_b_b, $a_c_id, $a_c_distance)
{
$builder->prep(4, 20);
$builder->prep(4, 20);
$builder->prep(4, 8);
$builder->putUint($a_c_distance);
$builder->putUint($a_c_id);
$builder->prep(2, 4);
$builder->pad(1);
$builder->putSbyte($a_b_b);
$builder->putShort($a_b_a);
$builder->prep(4, 8);
$builder->putUint($a_a_distance);
$builder->putUint($a_a_id);
return $builder->offset();
}
}

View File

@@ -0,0 +1,74 @@
# automatically generated by the FlatBuffers compiler, do not modify
# namespace: Example
import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()
class StructOfStructsOfStructs(object):
__slots__ = ['_tab']
@classmethod
def SizeOf(cls):
return 20
# StructOfStructsOfStructs
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)
# StructOfStructsOfStructs
def A(self, obj):
obj.Init(self._tab.Bytes, self._tab.Pos + 0)
return obj
def CreateStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, a_c_id, a_c_distance):
builder.Prep(4, 20)
builder.Prep(4, 20)
builder.Prep(4, 8)
builder.PrependUint32(a_c_distance)
builder.PrependUint32(a_c_id)
builder.Prep(2, 4)
builder.Pad(1)
builder.PrependInt8(a_b_b)
builder.PrependInt16(a_b_a)
builder.Prep(4, 8)
builder.PrependUint32(a_a_distance)
builder.PrependUint32(a_a_id)
return builder.Offset()
import MyGame.Example.StructOfStructs
try:
from typing import Optional
except:
pass
class StructOfStructsOfStructsT(object):
# StructOfStructsOfStructsT
def __init__(self):
self.a = None # type: Optional[MyGame.Example.StructOfStructs.StructOfStructsT]
@classmethod
def InitFromBuf(cls, buf, pos):
structOfStructsOfStructs = StructOfStructsOfStructs()
structOfStructsOfStructs.Init(buf, pos)
return cls.InitFromObj(structOfStructsOfStructs)
@classmethod
def InitFromObj(cls, structOfStructsOfStructs):
x = StructOfStructsOfStructsT()
x._UnPack(structOfStructsOfStructs)
return x
# StructOfStructsOfStructsT
def _UnPack(self, structOfStructsOfStructs):
if structOfStructsOfStructs is None:
return
if structOfStructsOfStructs.A(MyGame.Example.StructOfStructs.StructOfStructs()) is not None:
self.a = MyGame.Example.StructOfStructs.StructOfStructsT.InitFromObj(structOfStructsOfStructs.A(MyGame.Example.StructOfStructs.StructOfStructs()))
# StructOfStructsOfStructsT
def Pack(self, builder):
return CreateStructOfStructsOfStructs(builder, self.a.a.id, self.a.a.distance, self.a.b.a, self.a.b.b, self.a.c.id, self.a.c.distance)

View File

@@ -0,0 +1,22 @@
// automatically generated by the FlatBuffers compiler, do not modify
package MyGame.Example;
import java.nio.*;
import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
public class StructOfStructsOfStructsT {
private MyGame.Example.StructOfStructsT a;
public MyGame.Example.StructOfStructsT getA() { return a; }
public void setA(MyGame.Example.StructOfStructsT a) { this.a = a; }
public StructOfStructsOfStructsT() {
this.a = new MyGame.Example.StructOfStructsT();
}
}

View File

@@ -35,6 +35,8 @@ struct Ability;
struct StructOfStructs;
struct StructOfStructsOfStructs;
struct Stat;
struct StatBuilder;
struct StatT;
@@ -73,6 +75,8 @@ inline const flatbuffers::TypeTable *AbilityTypeTable();
inline const flatbuffers::TypeTable *StructOfStructsTypeTable();
inline const flatbuffers::TypeTable *StructOfStructsOfStructsTypeTable();
inline const flatbuffers::TypeTable *StatTypeTable();
inline const flatbuffers::TypeTable *ReferrableTypeTable();
@@ -815,6 +819,47 @@ struct StructOfStructs::Traits {
using FieldType = decltype(std::declval<type>().get_field<Index>());
};
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) StructOfStructsOfStructs FLATBUFFERS_FINAL_CLASS {
private:
MyGame::Example::StructOfStructs a_;
public:
struct Traits;
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
return StructOfStructsOfStructsTypeTable();
}
StructOfStructsOfStructs()
: a_() {
}
StructOfStructsOfStructs(const MyGame::Example::StructOfStructs &_a)
: a_(_a) {
}
const MyGame::Example::StructOfStructs &a() const {
return a_;
}
MyGame::Example::StructOfStructs &mutable_a() {
return a_;
}
template<size_t Index>
auto get_field() const {
if constexpr (Index == 0) return a();
else static_assert(Index != Index, "Invalid Field Index");
}
};
FLATBUFFERS_STRUCT_END(StructOfStructsOfStructs, 20);
struct StructOfStructsOfStructs::Traits {
using type = StructOfStructsOfStructs;
static constexpr auto name = "StructOfStructsOfStructs";
static constexpr auto fully_qualified_name = "MyGame.Example.StructOfStructsOfStructs";
static constexpr size_t fields_number = 1;
static constexpr std::array<const char *, fields_number> field_names = {
"a"
};
template<size_t Index>
using FieldType = decltype(std::declval<type>().get_field<Index>());
};
} // namespace Example
struct InParentNamespaceT : public flatbuffers::NativeTable {
@@ -3737,6 +3782,23 @@ inline const flatbuffers::TypeTable *StructOfStructsTypeTable() {
return &tt;
}
inline const flatbuffers::TypeTable *StructOfStructsOfStructsTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_SEQUENCE, 0, 0 }
};
static const flatbuffers::TypeFunction type_refs[] = {
MyGame::Example::StructOfStructsTypeTable
};
static const int64_t values[] = { 0, 20 };
static const char * const names[] = {
"a"
};
static const flatbuffers::TypeTable tt = {
flatbuffers::ST_STRUCT, 1, type_codes, type_refs, nullptr, values, names
};
return &tt;
}
inline const flatbuffers::TypeTable *StatTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_STRING, 0, -1 },

Binary file not shown.

View File

@@ -70,6 +70,10 @@ struct StructOfStructs {
c: Ability;
}
struct StructOfStructsOfStructs {
a: StructOfStructs;
}
table Stat {
id:string;
val:long;

View File

@@ -140,6 +140,15 @@
},
"additionalProperties" : false
},
"MyGame_Example_StructOfStructsOfStructs" : {
"type" : "object",
"properties" : {
"a" : {
"$ref" : "#/definitions/MyGame_Example_StructOfStructs"
}
},
"additionalProperties" : false
},
"MyGame_Example_Stat" : {
"type" : "object",
"properties" : {

View File

@@ -9,6 +9,7 @@ export { Race } from './my-game/example/race';
export { Referrable, ReferrableT } from './my-game/example/referrable';
export { Stat, StatT } from './my-game/example/stat';
export { StructOfStructs, StructOfStructsT } from './my-game/example/struct-of-structs';
export { StructOfStructsOfStructs, StructOfStructsOfStructsT } from './my-game/example/struct-of-structs-of-structs';
export { Test, TestT } from './my-game/example/test';
export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './my-game/example/test-simple-table-with-enum';
export { TypeAliases, TypeAliasesT } from './my-game/example/type-aliases';

View File

@@ -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;

View File

@@ -0,0 +1,113 @@
// 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::*;
// 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<'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(),
)
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -35,6 +35,8 @@ struct Ability;
struct StructOfStructs;
struct StructOfStructsOfStructs;
struct Stat;
struct StatBuilder;
struct StatT;
@@ -73,6 +75,8 @@ bool operator==(const Ability &lhs, const Ability &rhs);
bool operator!=(const Ability &lhs, const Ability &rhs);
bool operator==(const StructOfStructs &lhs, const StructOfStructs &rhs);
bool operator!=(const StructOfStructs &lhs, const StructOfStructs &rhs);
bool operator==(const StructOfStructsOfStructs &lhs, const StructOfStructsOfStructs &rhs);
bool operator!=(const StructOfStructsOfStructs &lhs, const StructOfStructsOfStructs &rhs);
bool operator==(const StatT &lhs, const StatT &rhs);
bool operator!=(const StatT &lhs, const StatT &rhs);
bool operator==(const ReferrableT &lhs, const ReferrableT &rhs);
@@ -104,6 +108,8 @@ inline const flatbuffers::TypeTable *AbilityTypeTable();
inline const flatbuffers::TypeTable *StructOfStructsTypeTable();
inline const flatbuffers::TypeTable *StructOfStructsOfStructsTypeTable();
inline const flatbuffers::TypeTable *StatTypeTable();
inline const flatbuffers::TypeTable *ReferrableTypeTable();
@@ -890,6 +896,39 @@ inline bool operator!=(const StructOfStructs &lhs, const StructOfStructs &rhs) {
}
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) StructOfStructsOfStructs FLATBUFFERS_FINAL_CLASS {
private:
MyGame::Example::StructOfStructs a_;
public:
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
return StructOfStructsOfStructsTypeTable();
}
StructOfStructsOfStructs()
: a_() {
}
StructOfStructsOfStructs(const MyGame::Example::StructOfStructs &_a)
: a_(_a) {
}
const MyGame::Example::StructOfStructs &a() const {
return a_;
}
MyGame::Example::StructOfStructs &mutable_a() {
return a_;
}
};
FLATBUFFERS_STRUCT_END(StructOfStructsOfStructs, 20);
inline bool operator==(const StructOfStructsOfStructs &lhs, const StructOfStructsOfStructs &rhs) {
return
(lhs.a() == rhs.a());
}
inline bool operator!=(const StructOfStructsOfStructs &lhs, const StructOfStructsOfStructs &rhs) {
return !(lhs == rhs);
}
} // namespace Example
struct InParentNamespaceT : public flatbuffers::NativeTable {
@@ -3704,6 +3743,23 @@ inline const flatbuffers::TypeTable *StructOfStructsTypeTable() {
return &tt;
}
inline const flatbuffers::TypeTable *StructOfStructsOfStructsTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_SEQUENCE, 0, 0 }
};
static const flatbuffers::TypeFunction type_refs[] = {
MyGame::Example::StructOfStructsTypeTable
};
static const int64_t values[] = { 0, 20 };
static const char * const names[] = {
"a"
};
static const flatbuffers::TypeTable tt = {
flatbuffers::ST_STRUCT, 1, type_codes, type_refs, nullptr, values, names
};
return &tt;
}
inline const flatbuffers::TypeTable *StatTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_STRING, 0, -1 },

View File

@@ -61,6 +61,8 @@ class Ability
class StructOfStructs
class StructOfStructsOfStructs
class Stat
class Referrable
@@ -193,6 +195,25 @@ def CreateStructOfStructs(b_:flatbuffers_builder, a_id:int, a_distance:int, b_a:
b_.PrependUint32(a_id)
return b_.Offset()
class StructOfStructsOfStructs : flatbuffers_handle
def a():
return MyGame_Example_StructOfStructs{ buf_, pos_ + 0 }
def CreateStructOfStructsOfStructs(b_:flatbuffers_builder, a_a_id:int, a_a_distance:int, a_b_a:int, a_b_b:int, a_c_id:int, a_c_distance:int):
b_.Prep(4, 20)
b_.Prep(4, 20)
b_.Prep(4, 8)
b_.PrependUint32(a_c_distance)
b_.PrependUint32(a_c_id)
b_.Prep(2, 4)
b_.Pad(1)
b_.PrependInt8(a_b_b)
b_.PrependInt16(a_b_a)
b_.Prep(4, 8)
b_.PrependUint32(a_a_distance)
b_.PrependUint32(a_a_id)
return b_.Offset()
class Stat : flatbuffers_handle
def id():
return buf_.flatbuffers_field_string(pos_, 4)

View File

@@ -543,6 +543,73 @@ class StructOfStructsT(object):
return CreateStructOfStructs(builder, self.a.id, self.a.distance, self.b.a, self.b.b, self.c.id, self.c.distance)
class StructOfStructsOfStructs(object):
__slots__ = ['_tab']
@classmethod
def SizeOf(cls):
return 20
# StructOfStructsOfStructs
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)
# StructOfStructsOfStructs
def A(self, obj):
obj.Init(self._tab.Bytes, self._tab.Pos + 0)
return obj
def CreateStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, a_c_id, a_c_distance):
builder.Prep(4, 20)
builder.Prep(4, 20)
builder.Prep(4, 8)
builder.PrependUint32(a_c_distance)
builder.PrependUint32(a_c_id)
builder.Prep(2, 4)
builder.Pad(1)
builder.PrependInt8(a_b_b)
builder.PrependInt16(a_b_a)
builder.Prep(4, 8)
builder.PrependUint32(a_a_distance)
builder.PrependUint32(a_a_id)
return builder.Offset()
try:
from typing import Optional
except:
pass
class StructOfStructsOfStructsT(object):
# StructOfStructsOfStructsT
def __init__(self):
self.a = None # type: Optional[StructOfStructsT]
@classmethod
def InitFromBuf(cls, buf, pos):
structOfStructsOfStructs = StructOfStructsOfStructs()
structOfStructsOfStructs.Init(buf, pos)
return cls.InitFromObj(structOfStructsOfStructs)
@classmethod
def InitFromObj(cls, structOfStructsOfStructs):
x = StructOfStructsOfStructsT()
x._UnPack(structOfStructsOfStructs)
return x
# StructOfStructsOfStructsT
def _UnPack(self, structOfStructsOfStructs):
if structOfStructsOfStructs is None:
return
if structOfStructsOfStructs.A(StructOfStructs()) is not None:
self.a = StructOfStructsT.InitFromObj(structOfStructsOfStructs.A(StructOfStructs()))
# StructOfStructsOfStructsT
def Pack(self, builder):
return CreateStructOfStructsOfStructs(builder, self.a.a.id, self.a.a.distance, self.a.b.a, self.a.b.b, self.a.c.id, self.a.c.distance)
class Stat(object):
__slots__ = ['_tab']

View File

@@ -855,6 +855,94 @@ class StructOfStructsObjectBuilder extends fb.ObjectBuilder {
return fbBuilder.buffer;
}
}
class StructOfStructsOfStructs {
StructOfStructsOfStructs._(this._bc, this._bcOffset);
static const fb.Reader<StructOfStructsOfStructs> reader = _StructOfStructsOfStructsReader();
final fb.BufferContext _bc;
final int _bcOffset;
StructOfStructs get a => StructOfStructs.reader.read(_bc, _bcOffset + 0);
@override
String toString() {
return 'StructOfStructsOfStructs{a: $a}';
}
StructOfStructsOfStructsT unpack() => StructOfStructsOfStructsT(
a: a.unpack());
static int pack(fb.Builder fbBuilder, StructOfStructsOfStructsT? object) {
if (object == null) return 0;
return object.pack(fbBuilder);
}
}
class StructOfStructsOfStructsT implements fb.Packable {
StructOfStructsT a;
StructOfStructsOfStructsT({
required this.a});
@override
int pack(fb.Builder fbBuilder) {
a.pack(fbBuilder);
return fbBuilder.offset;
}
@override
String toString() {
return 'StructOfStructsOfStructsT{a: $a}';
}
}
class _StructOfStructsOfStructsReader extends fb.StructReader<StructOfStructsOfStructs> {
const _StructOfStructsOfStructsReader();
@override
int get size => 20;
@override
StructOfStructsOfStructs createObject(fb.BufferContext bc, int offset) =>
StructOfStructsOfStructs._(bc, offset);
}
class StructOfStructsOfStructsBuilder {
StructOfStructsOfStructsBuilder(this.fbBuilder);
final fb.Builder fbBuilder;
int finish(fb.StructBuilder a) {
a();
return fbBuilder.offset;
}
}
class StructOfStructsOfStructsObjectBuilder extends fb.ObjectBuilder {
final StructOfStructsObjectBuilder _a;
StructOfStructsOfStructsObjectBuilder({
required StructOfStructsObjectBuilder a,
})
: _a = a;
/// Finish building, and store into the [fbBuilder].
@override
int finish(fb.Builder fbBuilder) {
_a.finish(fbBuilder);
return fbBuilder.offset;
}
/// Convenience method to serialize to byte list.
@override
Uint8List toBytes([String? fileIdentifier]) {
final fbBuilder = fb.Builder(deduplicateTables: false);
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
return fbBuilder.buffer;
}
}
class Stat {
Stat._(this._bc, this._bcOffset);
factory Stat(List<int> bytes) {

View File

@@ -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;

View File

@@ -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(),
)
}
}

View File

@@ -0,0 +1,74 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
import { StructOfStructs, StructOfStructsT } from '../../my-game/example/struct-of-structs';
export class StructOfStructsOfStructs {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructsOfStructs {
this.bb_pos = i;
this.bb = bb;
return this;
}
a(obj?:StructOfStructs):StructOfStructs|null {
return (obj || new StructOfStructs()).__init(this.bb_pos, this.bb!);
}
static getFullyQualifiedName():string {
return 'MyGame.Example.StructOfStructsOfStructs';
}
static sizeOf():number {
return 20;
}
static createStructOfStructsOfStructs(builder:flatbuffers.Builder, a_a_id: number, a_a_distance: number, a_b_a: number, a_b_b: number, a_c_id: number, a_c_distance: number):flatbuffers.Offset {
builder.prep(4, 20);
builder.prep(4, 20);
builder.prep(4, 8);
builder.writeInt32(a_c_distance);
builder.writeInt32(a_c_id);
builder.prep(2, 4);
builder.pad(1);
builder.writeInt8(a_b_b);
builder.writeInt16(a_b_a);
builder.prep(4, 8);
builder.writeInt32(a_a_distance);
builder.writeInt32(a_a_id);
return builder.offset();
}
unpack(): StructOfStructsOfStructsT {
return new StructOfStructsOfStructsT(
(this.a() !== null ? this.a()!.unpack() : null)
);
}
unpackTo(_o: StructOfStructsOfStructsT): void {
_o.a = (this.a() !== null ? this.a()!.unpack() : null);
}
}
export class StructOfStructsOfStructsT {
constructor(
public a: StructOfStructsT|null = null
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return StructOfStructsOfStructs.createStructOfStructsOfStructs(builder,
(this.a?.a?.id ?? 0),
(this.a?.a?.distance ?? 0),
(this.a?.b?.a ?? 0),
(this.a?.b?.b ?? 0),
(this.a?.c?.id ?? 0),
(this.a?.c?.distance ?? 0)
);
}
}

View File

@@ -77,12 +77,12 @@ constructor(
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return StructOfStructs.createStructOfStructs(builder,
(this.a === null ? 0 : this.a.id!),
(this.a === null ? 0 : this.a.distance!),
(this.b === null ? 0 : this.b.a!),
(this.b === null ? 0 : this.b.b!),
(this.c === null ? 0 : this.c.id!),
(this.c === null ? 0 : this.c.distance!)
(this.a?.id ?? 0),
(this.a?.distance ?? 0),
(this.b?.a ?? 0),
(this.b?.b ?? 0),
(this.c?.id ?? 0),
(this.c?.distance ?? 0)
);
}
}

View File

@@ -130,8 +130,8 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset {
this.z,
this.test1,
this.test2,
(this.test3 === null ? 0 : this.test3.a!),
(this.test3 === null ? 0 : this.test3.b!)
(this.test3?.a ?? 0),
(this.test3?.b ?? 0)
);
}
}