Rust structz (#6539)

* Rust structz

* struct of structs test

* swift tmp variables

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2021-03-29 19:56:45 -04:00
committed by GitHub
parent 1c26d2a1a0
commit 4133a39df8
25 changed files with 1681 additions and 564 deletions

View File

@@ -0,0 +1,83 @@
// <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 StructOfStructs : IFlatbufferObject
{
private Struct __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); }
public StructOfStructs __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public MyGame.Example.Ability A { get { return (new MyGame.Example.Ability()).__assign(__p.bb_pos + 0, __p.bb); } }
public MyGame.Example.Test B { get { return (new MyGame.Example.Test()).__assign(__p.bb_pos + 8, __p.bb); } }
public MyGame.Example.Ability C { get { return (new MyGame.Example.Ability()).__assign(__p.bb_pos + 12, __p.bb); } }
public static Offset<MyGame.Example.StructOfStructs> CreateStructOfStructs(FlatBufferBuilder builder, uint a_Id, uint a_Distance, short b_A, sbyte b_B, uint c_Id, uint c_Distance) {
builder.Prep(4, 20);
builder.Prep(4, 8);
builder.PutUint(c_Distance);
builder.PutUint(c_Id);
builder.Prep(2, 4);
builder.Pad(1);
builder.PutSbyte(b_B);
builder.PutShort(b_A);
builder.Prep(4, 8);
builder.PutUint(a_Distance);
builder.PutUint(a_Id);
return new Offset<MyGame.Example.StructOfStructs>(builder.Offset);
}
public StructOfStructsT UnPack() {
var _o = new StructOfStructsT();
this.UnPackTo(_o);
return _o;
}
public void UnPackTo(StructOfStructsT _o) {
_o.A = this.A.UnPack();
_o.B = this.B.UnPack();
_o.C = this.C.UnPack();
}
public static Offset<MyGame.Example.StructOfStructs> Pack(FlatBufferBuilder builder, StructOfStructsT _o) {
if (_o == null) return default(Offset<MyGame.Example.StructOfStructs>);
var _a_id = _o.A.Id;
var _a_distance = _o.A.Distance;
var _b_a = _o.B.A;
var _b_b = _o.B.B;
var _c_id = _o.C.Id;
var _c_distance = _o.C.Distance;
return CreateStructOfStructs(
builder,
_a_id,
_a_distance,
_b_a,
_b_b,
_c_id,
_c_distance);
}
};
public class StructOfStructsT
{
[Newtonsoft.Json.JsonProperty("a")]
public MyGame.Example.AbilityT A { get; set; }
[Newtonsoft.Json.JsonProperty("b")]
public MyGame.Example.TestT B { get; set; }
[Newtonsoft.Json.JsonProperty("c")]
public MyGame.Example.AbilityT C { get; set; }
public StructOfStructsT() {
this.A = new MyGame.Example.AbilityT();
this.B = new MyGame.Example.TestT();
this.C = new MyGame.Example.AbilityT();
}
}
}

View File

@@ -0,0 +1,80 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package Example
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type StructOfStructsT struct {
A *AbilityT
B *TestT
C *AbilityT
}
func (t *StructOfStructsT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 }
return CreateStructOfStructs(builder, t.A.Id, t.A.Distance, t.B.A, t.B.B, t.C.Id, t.C.Distance)
}
func (rcv *StructOfStructs) UnPackTo(t *StructOfStructsT) {
t.A = rcv.A(nil).UnPack()
t.B = rcv.B(nil).UnPack()
t.C = rcv.C(nil).UnPack()
}
func (rcv *StructOfStructs) UnPack() *StructOfStructsT {
if rcv == nil { return nil }
t := &StructOfStructsT{}
rcv.UnPackTo(t)
return t
}
type StructOfStructs struct {
_tab flatbuffers.Struct
}
func (rcv *StructOfStructs) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *StructOfStructs) Table() flatbuffers.Table {
return rcv._tab.Table
}
func (rcv *StructOfStructs) A(obj *Ability) *Ability {
if obj == nil {
obj = new(Ability)
}
obj.Init(rcv._tab.Bytes, rcv._tab.Pos+0)
return obj
}
func (rcv *StructOfStructs) B(obj *Test) *Test {
if obj == nil {
obj = new(Test)
}
obj.Init(rcv._tab.Bytes, rcv._tab.Pos+8)
return obj
}
func (rcv *StructOfStructs) C(obj *Ability) *Ability {
if obj == nil {
obj = new(Ability)
}
obj.Init(rcv._tab.Bytes, rcv._tab.Pos+12)
return obj
}
func CreateStructOfStructs(builder *flatbuffers.Builder, a_id uint32, a_distance uint32, b_a int16, b_b int8, c_id uint32, c_distance uint32) flatbuffers.UOffsetT {
builder.Prep(4, 20)
builder.Prep(4, 8)
builder.PrependUint32(c_distance)
builder.PrependUint32(c_id)
builder.Prep(2, 4)
builder.Pad(1)
builder.PrependInt8(b_b)
builder.PrependInt16(b_a)
builder.Prep(4, 8)
builder.PrependUint32(a_distance)
builder.PrependUint32(a_id)
return builder.Offset()
}

View File

@@ -0,0 +1,44 @@
// 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 StructOfStructs extends Struct {
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
public StructOfStructs __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public MyGame.Example.Ability a() { return a(new MyGame.Example.Ability()); }
public MyGame.Example.Ability a(MyGame.Example.Ability obj) { return obj.__assign(bb_pos + 0, bb); }
public MyGame.Example.Test b() { return b(new MyGame.Example.Test()); }
public MyGame.Example.Test b(MyGame.Example.Test obj) { return obj.__assign(bb_pos + 8, bb); }
public MyGame.Example.Ability c() { return c(new MyGame.Example.Ability()); }
public MyGame.Example.Ability c(MyGame.Example.Ability obj) { return obj.__assign(bb_pos + 12, bb); }
public static int createStructOfStructs(FlatBufferBuilder builder, long a_id, long a_distance, short b_a, byte b_b, long c_id, long c_distance) {
builder.prep(4, 20);
builder.prep(4, 8);
builder.putInt((int)c_distance);
builder.putInt((int)c_id);
builder.prep(2, 4);
builder.pad(1);
builder.putByte(b_b);
builder.putShort(b_a);
builder.prep(4, 8);
builder.putInt((int)a_distance);
builder.putInt((int)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 StructOfStructs get(int j) { return get(new StructOfStructs(), j); }
public StructOfStructs get(StructOfStructs obj, int j) { return obj.__assign(__element(j), bb); }
}
}

View File

@@ -0,0 +1,42 @@
// 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")
@ExperimentalUnsignedTypes
class StructOfStructs : Struct() {
fun __init(_i: Int, _bb: ByteBuffer) {
__reset(_i, _bb)
}
fun __assign(_i: Int, _bb: ByteBuffer) : StructOfStructs {
__init(_i, _bb)
return this
}
val a : MyGame.Example.Ability? get() = a(MyGame.Example.Ability())
fun a(obj: MyGame.Example.Ability) : MyGame.Example.Ability? = obj.__assign(bb_pos + 0, bb)
val b : MyGame.Example.Test? get() = b(MyGame.Example.Test())
fun b(obj: MyGame.Example.Test) : MyGame.Example.Test? = obj.__assign(bb_pos + 8, bb)
val c : MyGame.Example.Ability? get() = c(MyGame.Example.Ability())
fun c(obj: MyGame.Example.Ability) : MyGame.Example.Ability? = obj.__assign(bb_pos + 12, bb)
companion object {
fun createStructOfStructs(builder: FlatBufferBuilder, a_id: UInt, a_distance: UInt, b_a: Short, b_b: Byte, c_id: UInt, c_distance: UInt) : Int {
builder.prep(4, 20)
builder.prep(4, 8)
builder.putInt(c_distance.toInt())
builder.putInt(c_id.toInt())
builder.prep(2, 4)
builder.pad(1)
builder.putByte(b_b)
builder.putShort(b_a)
builder.prep(4, 8)
builder.putInt(a_distance.toInt())
builder.putInt(a_id.toInt())
return builder.offset()
}
}
}

View File

@@ -0,0 +1,45 @@
-- automatically generated by the FlatBuffers compiler, do not modify
-- namespace: Example
local flatbuffers = require('flatbuffers')
local StructOfStructs = {} -- the module
local StructOfStructs_mt = {} -- the class metatable
function StructOfStructs.New()
local o = {}
setmetatable(o, {__index = StructOfStructs_mt})
return o
end
function StructOfStructs_mt:Init(buf, pos)
self.view = flatbuffers.view.New(buf, pos)
end
function StructOfStructs_mt:A(obj)
obj:Init(self.view.bytes, self.view.pos + 0)
return obj
end
function StructOfStructs_mt:B(obj)
obj:Init(self.view.bytes, self.view.pos + 8)
return obj
end
function StructOfStructs_mt:C(obj)
obj:Init(self.view.bytes, self.view.pos + 12)
return obj
end
function StructOfStructs.CreateStructOfStructs(builder, a_id, a_distance, b_a, b_b, c_id, c_distance)
builder:Prep(4, 20)
builder:Prep(4, 8)
builder:PrependUint32(c_distance)
builder:PrependUint32(c_id)
builder:Prep(2, 4)
builder:Pad(1)
builder:PrependInt8(b_b)
builder:PrependInt16(b_a)
builder:Prep(4, 8)
builder:PrependUint32(a_distance)
builder:PrependUint32(a_id)
return builder:Offset()
end
return StructOfStructs -- return the module

View File

@@ -0,0 +1,74 @@
<?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 StructOfStructs extends Struct
{
/**
* @param int $_i offset
* @param ByteBuffer $_bb
* @return StructOfStructs
**/
public function init($_i, ByteBuffer $_bb)
{
$this->bb_pos = $_i;
$this->bb = $_bb;
return $this;
}
/**
* @return Ability
*/
public function getA()
{
$obj = new Ability();
$obj->init($this->bb_pos + 0, $this->bb);
return $obj;
}
/**
* @return Test
*/
public function getB()
{
$obj = new Test();
$obj->init($this->bb_pos + 8, $this->bb);
return $obj;
}
/**
* @return Ability
*/
public function getC()
{
$obj = new Ability();
$obj->init($this->bb_pos + 12, $this->bb);
return $obj;
}
/**
* @return int offset
*/
public static function createStructOfStructs(FlatBufferBuilder $builder, $a_id, $a_distance, $b_a, $b_b, $c_id, $c_distance)
{
$builder->prep(4, 20);
$builder->prep(4, 8);
$builder->putUint($c_distance);
$builder->putUint($c_id);
$builder->prep(2, 4);
$builder->pad(1);
$builder->putSbyte($b_b);
$builder->putShort($b_a);
$builder->prep(4, 8);
$builder->putUint($a_distance);
$builder->putUint($a_id);
return $builder->offset();
}
}

View File

@@ -0,0 +1,90 @@
# automatically generated by the FlatBuffers compiler, do not modify
# namespace: Example
import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()
class StructOfStructs(object):
__slots__ = ['_tab']
@classmethod
def SizeOf(cls):
return 20
# StructOfStructs
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)
# StructOfStructs
def A(self, obj):
obj.Init(self._tab.Bytes, self._tab.Pos + 0)
return obj
# StructOfStructs
def B(self, obj):
obj.Init(self._tab.Bytes, self._tab.Pos + 8)
return obj
# StructOfStructs
def C(self, obj):
obj.Init(self._tab.Bytes, self._tab.Pos + 12)
return obj
def CreateStructOfStructs(builder, a_id, a_distance, b_a, b_b, c_id, c_distance):
builder.Prep(4, 20)
builder.Prep(4, 8)
builder.PrependUint32(c_distance)
builder.PrependUint32(c_id)
builder.Prep(2, 4)
builder.Pad(1)
builder.PrependInt8(b_b)
builder.PrependInt16(b_a)
builder.Prep(4, 8)
builder.PrependUint32(a_distance)
builder.PrependUint32(a_id)
return builder.Offset()
import MyGame.Example.Ability
import MyGame.Example.Test
try:
from typing import Optional
except:
pass
class StructOfStructsT(object):
# StructOfStructsT
def __init__(self):
self.a = None # type: Optional[MyGame.Example.Ability.AbilityT]
self.b = None # type: Optional[MyGame.Example.Test.TestT]
self.c = None # type: Optional[MyGame.Example.Ability.AbilityT]
@classmethod
def InitFromBuf(cls, buf, pos):
structOfStructs = StructOfStructs()
structOfStructs.Init(buf, pos)
return cls.InitFromObj(structOfStructs)
@classmethod
def InitFromObj(cls, structOfStructs):
x = StructOfStructsT()
x._UnPack(structOfStructs)
return x
# StructOfStructsT
def _UnPack(self, structOfStructs):
if structOfStructs is None:
return
if structOfStructs.A(MyGame.Example.Ability.Ability()) is not None:
self.a = MyGame.Example.Ability.AbilityT.InitFromObj(structOfStructs.A(MyGame.Example.Ability.Ability()))
if structOfStructs.B(MyGame.Example.Test.Test()) is not None:
self.b = MyGame.Example.Test.TestT.InitFromObj(structOfStructs.B(MyGame.Example.Test.Test()))
if structOfStructs.C(MyGame.Example.Ability.Ability()) is not None:
self.c = MyGame.Example.Ability.AbilityT.InitFromObj(structOfStructs.C(MyGame.Example.Ability.Ability()))
# StructOfStructsT
def Pack(self, builder):
return CreateStructOfStructs(builder, self.a.id, self.a.distance, self.b.a, self.b.b, self.c.id, self.c.distance)