mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-30 18:50:01 +00:00
[Rust] Ensure unions are referenced with the correct path (#6422)
* Add codegen test for namespaced unions * [Rust] Handle cross-namespace union use * [Rust] Test namespace handling * [Rust] Drop trailing whitespace in codegen * [Rust] Set flags in generate_code.bat to match .sh * [C#] Add additional namespace test file
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace NamespaceA.NamespaceB
|
||||
{
|
||||
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public enum UnionInNestedNS : byte
|
||||
{
|
||||
NONE = 0,
|
||||
TableInNestedNS = 1,
|
||||
};
|
||||
|
||||
public class UnionInNestedNSUnion {
|
||||
public UnionInNestedNS Type { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public UnionInNestedNSUnion() {
|
||||
this.Type = UnionInNestedNS.NONE;
|
||||
this.Value = null;
|
||||
}
|
||||
|
||||
public T As<T>() where T : class { return this.Value as T; }
|
||||
public NamespaceA.NamespaceB.TableInNestedNST AsTableInNestedNS() { return this.As<NamespaceA.NamespaceB.TableInNestedNST>(); }
|
||||
|
||||
public static int Pack(FlatBuffers.FlatBufferBuilder builder, UnionInNestedNSUnion _o) {
|
||||
switch (_o.Type) {
|
||||
default: return 0;
|
||||
case UnionInNestedNS.TableInNestedNS: return NamespaceA.NamespaceB.TableInNestedNS.Pack(builder, _o.AsTableInNestedNS()).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UnionInNestedNSUnion_JsonConverter : Newtonsoft.Json.JsonConverter {
|
||||
public override bool CanConvert(System.Type objectType) {
|
||||
return objectType == typeof(UnionInNestedNSUnion) || objectType == typeof(System.Collections.Generic.List<UnionInNestedNSUnion>);
|
||||
}
|
||||
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = value as System.Collections.Generic.List<UnionInNestedNSUnion>;
|
||||
if (_olist != null) {
|
||||
writer.WriteStartArray();
|
||||
foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); }
|
||||
writer.WriteEndArray();
|
||||
} else {
|
||||
this.WriteJson(writer, value as UnionInNestedNSUnion, serializer);
|
||||
}
|
||||
}
|
||||
public void WriteJson(Newtonsoft.Json.JsonWriter writer, UnionInNestedNSUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return;
|
||||
serializer.Serialize(writer, _o.Value);
|
||||
}
|
||||
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
var _olist = existingValue as System.Collections.Generic.List<UnionInNestedNSUnion>;
|
||||
if (_olist != null) {
|
||||
for (var _j = 0; _j < _olist.Count; ++_j) {
|
||||
reader.Read();
|
||||
_olist[_j] = this.ReadJson(reader, _olist[_j], serializer);
|
||||
}
|
||||
reader.Read();
|
||||
return _olist;
|
||||
} else {
|
||||
return this.ReadJson(reader, existingValue as UnionInNestedNSUnion, serializer);
|
||||
}
|
||||
}
|
||||
public UnionInNestedNSUnion ReadJson(Newtonsoft.Json.JsonReader reader, UnionInNestedNSUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
|
||||
if (_o == null) return null;
|
||||
switch (_o.Type) {
|
||||
default: break;
|
||||
case UnionInNestedNS.TableInNestedNS: _o.Value = serializer.Deserialize<NamespaceA.NamespaceB.TableInNestedNST>(reader); break;
|
||||
}
|
||||
return _o;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package NamespaceB
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
|
||||
NamespaceA__NamespaceB "NamespaceA/NamespaceB"
|
||||
)
|
||||
|
||||
type UnionInNestedNST struct {
|
||||
Type UnionInNestedNS
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func (t *UnionInNestedNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
switch t.Type {
|
||||
case UnionInNestedNSTableInNestedNS:
|
||||
return t.Value.(*NamespaceA__NamespaceB.TableInNestedNST).Pack(builder)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv UnionInNestedNS) UnPack(table flatbuffers.Table) *UnionInNestedNST {
|
||||
switch rcv {
|
||||
case UnionInNestedNSTableInNestedNS:
|
||||
x := TableInNestedNS{_tab: table}
|
||||
return &NamespaceA__NamespaceB.UnionInNestedNST{ Type: UnionInNestedNSTableInNestedNS, Value: x.UnPack() }
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package NamespaceA.NamespaceB;
|
||||
|
||||
public final class UnionInNestedNS {
|
||||
private UnionInNestedNS() { }
|
||||
public static final byte NONE = 0;
|
||||
public static final byte TableInNestedNS = 1;
|
||||
|
||||
public static final String[] names = { "NONE", "TableInNestedNS", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package NamespaceA.NamespaceB
|
||||
|
||||
@Suppress("unused")
|
||||
@ExperimentalUnsignedTypes
|
||||
class UnionInNestedNS private constructor() {
|
||||
companion object {
|
||||
const val NONE: UByte = 0u
|
||||
const val TableInNestedNS: UByte = 1u
|
||||
val names : Array<String> = arrayOf("NONE", "TableInNestedNS")
|
||||
fun name(e: Int) : String = names[e]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: NamespaceB
|
||||
|
||||
local UnionInNestedNS = {
|
||||
NONE = 0,
|
||||
TableInNestedNS = 1,
|
||||
}
|
||||
|
||||
return UnionInNestedNS -- return the module
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace NamespaceA\NamespaceB;
|
||||
|
||||
class UnionInNestedNS
|
||||
{
|
||||
const NONE = 0;
|
||||
const TableInNestedNS = 1;
|
||||
|
||||
private static $names = array(
|
||||
UnionInNestedNS::NONE=>"NONE",
|
||||
UnionInNestedNS::TableInNestedNS=>"TableInNestedNS",
|
||||
);
|
||||
|
||||
public static function Name($e)
|
||||
{
|
||||
if (!isset(self::$names[$e])) {
|
||||
throw new \Exception();
|
||||
}
|
||||
return self::$names[$e];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: NamespaceB
|
||||
|
||||
|
||||
def UnionInNestedNSCreator(unionType, table):
|
||||
from flatbuffers.table import Table
|
||||
if not isinstance(table, Table):
|
||||
return None
|
||||
if unionType == UnionInNestedNS().TableInNestedNS:
|
||||
return TableInNestedNST.InitFromBuf(table.Bytes, table.Pos)
|
||||
return None
|
||||
@@ -22,23 +22,32 @@ public struct TableInFirstNS : IFlatbufferObject
|
||||
public NamespaceA.NamespaceB.TableInNestedNS? FooTable { get { int o = __p.__offset(4); return o != 0 ? (NamespaceA.NamespaceB.TableInNestedNS?)(new NamespaceA.NamespaceB.TableInNestedNS()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } }
|
||||
public NamespaceA.NamespaceB.EnumInNestedNS FooEnum { get { int o = __p.__offset(6); return o != 0 ? (NamespaceA.NamespaceB.EnumInNestedNS)__p.bb.GetSbyte(o + __p.bb_pos) : NamespaceA.NamespaceB.EnumInNestedNS.A; } }
|
||||
public bool MutateFooEnum(NamespaceA.NamespaceB.EnumInNestedNS foo_enum) { int o = __p.__offset(6); if (o != 0) { __p.bb.PutSbyte(o + __p.bb_pos, (sbyte)foo_enum); return true; } else { return false; } }
|
||||
public NamespaceA.NamespaceB.StructInNestedNS? FooStruct { get { int o = __p.__offset(8); return o != 0 ? (NamespaceA.NamespaceB.StructInNestedNS?)(new NamespaceA.NamespaceB.StructInNestedNS()).__assign(o + __p.bb_pos, __p.bb) : null; } }
|
||||
public NamespaceA.NamespaceB.UnionInNestedNS FooUnionType { get { int o = __p.__offset(8); return o != 0 ? (NamespaceA.NamespaceB.UnionInNestedNS)__p.bb.Get(o + __p.bb_pos) : NamespaceA.NamespaceB.UnionInNestedNS.NONE; } }
|
||||
public TTable? FooUnion<TTable>() where TTable : struct, IFlatbufferObject { int o = __p.__offset(10); return o != 0 ? (TTable?)__p.__union<TTable>(o + __p.bb_pos) : null; }
|
||||
public NamespaceA.NamespaceB.TableInNestedNS FooUnionAsTableInNestedNS() { return FooUnion<NamespaceA.NamespaceB.TableInNestedNS>().Value; }
|
||||
public NamespaceA.NamespaceB.StructInNestedNS? FooStruct { get { int o = __p.__offset(12); return o != 0 ? (NamespaceA.NamespaceB.StructInNestedNS?)(new NamespaceA.NamespaceB.StructInNestedNS()).__assign(o + __p.bb_pos, __p.bb) : null; } }
|
||||
|
||||
public static Offset<NamespaceA.TableInFirstNS> CreateTableInFirstNS(FlatBufferBuilder builder,
|
||||
Offset<NamespaceA.NamespaceB.TableInNestedNS> foo_tableOffset = default(Offset<NamespaceA.NamespaceB.TableInNestedNS>),
|
||||
NamespaceA.NamespaceB.EnumInNestedNS foo_enum = NamespaceA.NamespaceB.EnumInNestedNS.A,
|
||||
NamespaceA.NamespaceB.UnionInNestedNS foo_union_type = NamespaceA.NamespaceB.UnionInNestedNS.NONE,
|
||||
int foo_unionOffset = 0,
|
||||
NamespaceA.NamespaceB.StructInNestedNST foo_struct = null) {
|
||||
builder.StartTable(3);
|
||||
builder.StartTable(5);
|
||||
TableInFirstNS.AddFooStruct(builder, NamespaceA.NamespaceB.StructInNestedNS.Pack(builder, foo_struct));
|
||||
TableInFirstNS.AddFooUnion(builder, foo_unionOffset);
|
||||
TableInFirstNS.AddFooTable(builder, foo_tableOffset);
|
||||
TableInFirstNS.AddFooUnionType(builder, foo_union_type);
|
||||
TableInFirstNS.AddFooEnum(builder, foo_enum);
|
||||
return TableInFirstNS.EndTableInFirstNS(builder);
|
||||
}
|
||||
|
||||
public static void StartTableInFirstNS(FlatBufferBuilder builder) { builder.StartTable(3); }
|
||||
public static void StartTableInFirstNS(FlatBufferBuilder builder) { builder.StartTable(5); }
|
||||
public static void AddFooTable(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.TableInNestedNS> fooTableOffset) { builder.AddOffset(0, fooTableOffset.Value, 0); }
|
||||
public static void AddFooEnum(FlatBufferBuilder builder, NamespaceA.NamespaceB.EnumInNestedNS fooEnum) { builder.AddSbyte(1, (sbyte)fooEnum, 0); }
|
||||
public static void AddFooStruct(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.StructInNestedNS> fooStructOffset) { builder.AddStruct(2, fooStructOffset.Value, 0); }
|
||||
public static void AddFooUnionType(FlatBufferBuilder builder, NamespaceA.NamespaceB.UnionInNestedNS fooUnionType) { builder.AddByte(2, (byte)fooUnionType, 0); }
|
||||
public static void AddFooUnion(FlatBufferBuilder builder, int fooUnionOffset) { builder.AddOffset(3, fooUnionOffset, 0); }
|
||||
public static void AddFooStruct(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.StructInNestedNS> fooStructOffset) { builder.AddStruct(4, fooStructOffset.Value, 0); }
|
||||
public static Offset<NamespaceA.TableInFirstNS> EndTableInFirstNS(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<NamespaceA.TableInFirstNS>(o);
|
||||
@@ -51,15 +60,27 @@ public struct TableInFirstNS : IFlatbufferObject
|
||||
public void UnPackTo(TableInFirstNST _o) {
|
||||
_o.FooTable = this.FooTable.HasValue ? this.FooTable.Value.UnPack() : null;
|
||||
_o.FooEnum = this.FooEnum;
|
||||
_o.FooUnion = new NamespaceA.NamespaceB.UnionInNestedNSUnion();
|
||||
_o.FooUnion.Type = this.FooUnionType;
|
||||
switch (this.FooUnionType) {
|
||||
default: break;
|
||||
case NamespaceA.NamespaceB.UnionInNestedNS.TableInNestedNS:
|
||||
_o.FooUnion.Value = this.FooUnion<NamespaceA.NamespaceB.TableInNestedNS>().HasValue ? this.FooUnion<NamespaceA.NamespaceB.TableInNestedNS>().Value.UnPack() : null;
|
||||
break;
|
||||
}
|
||||
_o.FooStruct = this.FooStruct.HasValue ? this.FooStruct.Value.UnPack() : null;
|
||||
}
|
||||
public static Offset<NamespaceA.TableInFirstNS> Pack(FlatBufferBuilder builder, TableInFirstNST _o) {
|
||||
if (_o == null) return default(Offset<NamespaceA.TableInFirstNS>);
|
||||
var _foo_table = _o.FooTable == null ? default(Offset<NamespaceA.NamespaceB.TableInNestedNS>) : NamespaceA.NamespaceB.TableInNestedNS.Pack(builder, _o.FooTable);
|
||||
var _foo_union_type = _o.FooUnion == null ? NamespaceA.NamespaceB.UnionInNestedNS.NONE : _o.FooUnion.Type;
|
||||
var _foo_union = _o.FooUnion == null ? 0 : NamespaceA.NamespaceB.UnionInNestedNSUnion.Pack(builder, _o.FooUnion);
|
||||
return CreateTableInFirstNS(
|
||||
builder,
|
||||
_foo_table,
|
||||
_o.FooEnum,
|
||||
_foo_union_type,
|
||||
_foo_union,
|
||||
_o.FooStruct);
|
||||
}
|
||||
};
|
||||
@@ -70,12 +91,26 @@ public class TableInFirstNST
|
||||
public NamespaceA.NamespaceB.TableInNestedNST FooTable { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("foo_enum")]
|
||||
public NamespaceA.NamespaceB.EnumInNestedNS FooEnum { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("foo_union_type")]
|
||||
private NamespaceA.NamespaceB.UnionInNestedNS FooUnionType {
|
||||
get {
|
||||
return this.FooUnion != null ? this.FooUnion.Type : NamespaceA.NamespaceB.UnionInNestedNS.NONE;
|
||||
}
|
||||
set {
|
||||
this.FooUnion = new NamespaceA.NamespaceB.UnionInNestedNSUnion();
|
||||
this.FooUnion.Type = value;
|
||||
}
|
||||
}
|
||||
[Newtonsoft.Json.JsonProperty("foo_union")]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(NamespaceA.NamespaceB.UnionInNestedNSUnion_JsonConverter))]
|
||||
public NamespaceA.NamespaceB.UnionInNestedNSUnion FooUnion { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("foo_struct")]
|
||||
public NamespaceA.NamespaceB.StructInNestedNST FooStruct { get; set; }
|
||||
|
||||
public TableInFirstNST() {
|
||||
this.FooTable = null;
|
||||
this.FooEnum = NamespaceA.NamespaceB.EnumInNestedNS.A;
|
||||
this.FooUnion = null;
|
||||
this.FooStruct = new NamespaceA.NamespaceB.StructInNestedNST();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,15 +11,22 @@ import (
|
||||
type TableInFirstNST struct {
|
||||
FooTable *NamespaceA__NamespaceB.TableInNestedNST
|
||||
FooEnum NamespaceA__NamespaceB.EnumInNestedNS
|
||||
FooUnion *NamespaceA__NamespaceB.UnionInNestedNST
|
||||
FooStruct *NamespaceA__NamespaceB.StructInNestedNST
|
||||
}
|
||||
|
||||
func (t *TableInFirstNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
fooTableOffset := t.FooTable.Pack(builder)
|
||||
fooUnionOffset := t.FooUnion.Pack(builder)
|
||||
|
||||
TableInFirstNSStart(builder)
|
||||
TableInFirstNSAddFooTable(builder, fooTableOffset)
|
||||
TableInFirstNSAddFooEnum(builder, t.FooEnum)
|
||||
if t.FooUnion != nil {
|
||||
TableInFirstNSAddFooUnionType(builder, t.FooUnion.Type)
|
||||
}
|
||||
TableInFirstNSAddFooUnion(builder, fooUnionOffset)
|
||||
fooStructOffset := t.FooStruct.Pack(builder)
|
||||
TableInFirstNSAddFooStruct(builder, fooStructOffset)
|
||||
return TableInFirstNSEnd(builder)
|
||||
@@ -28,6 +35,10 @@ func (t *TableInFirstNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffset
|
||||
func (rcv *TableInFirstNS) UnPackTo(t *TableInFirstNST) {
|
||||
t.FooTable = rcv.FooTable(nil).UnPack()
|
||||
t.FooEnum = rcv.FooEnum()
|
||||
fooUnionTable := flatbuffers.Table{}
|
||||
if rcv.FooUnion(&fooUnionTable) {
|
||||
t.FooUnion = rcv.FooUnionType().UnPack(fooUnionTable)
|
||||
}
|
||||
t.FooStruct = rcv.FooStruct(nil).UnPack()
|
||||
}
|
||||
|
||||
@@ -90,8 +101,29 @@ func (rcv *TableInFirstNS) MutateFooEnum(n NamespaceA__NamespaceB.EnumInNestedNS
|
||||
return rcv._tab.MutateInt8Slot(6, int8(n))
|
||||
}
|
||||
|
||||
func (rcv *TableInFirstNS) FooStruct(obj *NamespaceA__NamespaceB.StructInNestedNS) *NamespaceA__NamespaceB.StructInNestedNS {
|
||||
func (rcv *TableInFirstNS) FooUnionType() NamespaceA__NamespaceB.UnionInNestedNS {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
|
||||
if o != 0 {
|
||||
return NamespaceA__NamespaceB.UnionInNestedNS(rcv._tab.GetByte(o + rcv._tab.Pos))
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv *TableInFirstNS) MutateFooUnionType(n NamespaceA__NamespaceB.UnionInNestedNS) bool {
|
||||
return rcv._tab.MutateByteSlot(8, byte(n))
|
||||
}
|
||||
|
||||
func (rcv *TableInFirstNS) FooUnion(obj *flatbuffers.Table) bool {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
|
||||
if o != 0 {
|
||||
rcv._tab.Union(obj, o)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (rcv *TableInFirstNS) FooStruct(obj *NamespaceA__NamespaceB.StructInNestedNS) *NamespaceA__NamespaceB.StructInNestedNS {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(12))
|
||||
if o != 0 {
|
||||
x := o + rcv._tab.Pos
|
||||
if obj == nil {
|
||||
@@ -104,7 +136,7 @@ func (rcv *TableInFirstNS) FooStruct(obj *NamespaceA__NamespaceB.StructInNestedN
|
||||
}
|
||||
|
||||
func TableInFirstNSStart(builder *flatbuffers.Builder) {
|
||||
builder.StartObject(3)
|
||||
builder.StartObject(5)
|
||||
}
|
||||
func TableInFirstNSAddFooTable(builder *flatbuffers.Builder, fooTable flatbuffers.UOffsetT) {
|
||||
builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(fooTable), 0)
|
||||
@@ -112,8 +144,14 @@ func TableInFirstNSAddFooTable(builder *flatbuffers.Builder, fooTable flatbuffer
|
||||
func TableInFirstNSAddFooEnum(builder *flatbuffers.Builder, fooEnum NamespaceA__NamespaceB.EnumInNestedNS) {
|
||||
builder.PrependInt8Slot(1, int8(fooEnum), 0)
|
||||
}
|
||||
func TableInFirstNSAddFooUnionType(builder *flatbuffers.Builder, fooUnionType NamespaceA__NamespaceB.UnionInNestedNS) {
|
||||
builder.PrependByteSlot(2, byte(fooUnionType), 0)
|
||||
}
|
||||
func TableInFirstNSAddFooUnion(builder *flatbuffers.Builder, fooUnion flatbuffers.UOffsetT) {
|
||||
builder.PrependUOffsetTSlot(3, flatbuffers.UOffsetT(fooUnion), 0)
|
||||
}
|
||||
func TableInFirstNSAddFooStruct(builder *flatbuffers.Builder, fooStruct flatbuffers.UOffsetT) {
|
||||
builder.PrependStructSlot(2, flatbuffers.UOffsetT(fooStruct), 0)
|
||||
builder.PrependStructSlot(4, flatbuffers.UOffsetT(fooStruct), 0)
|
||||
}
|
||||
func TableInFirstNSEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
return builder.EndObject()
|
||||
|
||||
@@ -19,13 +19,17 @@ public final class TableInFirstNS extends Table {
|
||||
public NamespaceA.NamespaceB.TableInNestedNS fooTable(NamespaceA.NamespaceB.TableInNestedNS obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public byte fooEnum() { int o = __offset(6); return o != 0 ? bb.get(o + bb_pos) : 0; }
|
||||
public boolean mutateFooEnum(byte foo_enum) { int o = __offset(6); if (o != 0) { bb.put(o + bb_pos, foo_enum); return true; } else { return false; } }
|
||||
public byte fooUnionType() { int o = __offset(8); return o != 0 ? bb.get(o + bb_pos) : 0; }
|
||||
public Table fooUnion(Table obj) { int o = __offset(10); return o != 0 ? __union(obj, o + bb_pos) : null; }
|
||||
public NamespaceA.NamespaceB.StructInNestedNS fooStruct() { return fooStruct(new NamespaceA.NamespaceB.StructInNestedNS()); }
|
||||
public NamespaceA.NamespaceB.StructInNestedNS fooStruct(NamespaceA.NamespaceB.StructInNestedNS obj) { int o = __offset(8); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
|
||||
public NamespaceA.NamespaceB.StructInNestedNS fooStruct(NamespaceA.NamespaceB.StructInNestedNS obj) { int o = __offset(12); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
|
||||
|
||||
public static void startTableInFirstNS(FlatBufferBuilder builder) { builder.startTable(3); }
|
||||
public static void startTableInFirstNS(FlatBufferBuilder builder) { builder.startTable(5); }
|
||||
public static void addFooTable(FlatBufferBuilder builder, int fooTableOffset) { builder.addOffset(0, fooTableOffset, 0); }
|
||||
public static void addFooEnum(FlatBufferBuilder builder, byte fooEnum) { builder.addByte(1, fooEnum, 0); }
|
||||
public static void addFooStruct(FlatBufferBuilder builder, int fooStructOffset) { builder.addStruct(2, fooStructOffset, 0); }
|
||||
public static void addFooUnionType(FlatBufferBuilder builder, byte fooUnionType) { builder.addByte(2, fooUnionType, 0); }
|
||||
public static void addFooUnion(FlatBufferBuilder builder, int fooUnionOffset) { builder.addOffset(3, fooUnionOffset, 0); }
|
||||
public static void addFooStruct(FlatBufferBuilder builder, int fooStructOffset) { builder.addStruct(4, fooStructOffset, 0); }
|
||||
public static int endTableInFirstNS(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
|
||||
@@ -40,9 +40,26 @@ class TableInFirstNS : Table() {
|
||||
false
|
||||
}
|
||||
}
|
||||
val fooUnionType : UByte
|
||||
get() {
|
||||
val o = __offset(8)
|
||||
return if(o != 0) bb.get(o + bb_pos).toUByte() else 0u
|
||||
}
|
||||
fun mutateFooUnionType(fooUnionType: UByte) : Boolean {
|
||||
val o = __offset(8)
|
||||
return if (o != 0) {
|
||||
bb.put(o + bb_pos, fooUnionType.toByte())
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
fun fooUnion(obj: Table) : Table? {
|
||||
val o = __offset(10); return if (o != 0) __union(obj, o + bb_pos) else null
|
||||
}
|
||||
val fooStruct : NamespaceA.NamespaceB.StructInNestedNS? get() = fooStruct(NamespaceA.NamespaceB.StructInNestedNS())
|
||||
fun fooStruct(obj: NamespaceA.NamespaceB.StructInNestedNS) : NamespaceA.NamespaceB.StructInNestedNS? {
|
||||
val o = __offset(8)
|
||||
val o = __offset(12)
|
||||
return if (o != 0) {
|
||||
obj.__assign(o + bb_pos, bb)
|
||||
} else {
|
||||
@@ -56,10 +73,12 @@ class TableInFirstNS : Table() {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun startTableInFirstNS(builder: FlatBufferBuilder) = builder.startTable(3)
|
||||
fun startTableInFirstNS(builder: FlatBufferBuilder) = builder.startTable(5)
|
||||
fun addFooTable(builder: FlatBufferBuilder, fooTable: Int) = builder.addOffset(0, fooTable, 0)
|
||||
fun addFooEnum(builder: FlatBufferBuilder, fooEnum: Byte) = builder.addByte(1, fooEnum, 0)
|
||||
fun addFooStruct(builder: FlatBufferBuilder, fooStruct: Int) = builder.addStruct(2, fooStruct, 0)
|
||||
fun addFooUnionType(builder: FlatBufferBuilder, fooUnionType: UByte) = builder.addByte(2, fooUnionType.toByte(), 0)
|
||||
fun addFooUnion(builder: FlatBufferBuilder, fooUnion: Int) = builder.addOffset(3, fooUnion, 0)
|
||||
fun addFooStruct(builder: FlatBufferBuilder, fooStruct: Int) = builder.addStruct(4, fooStruct, 0)
|
||||
fun endTableInFirstNS(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
|
||||
@@ -37,8 +37,23 @@ function TableInFirstNS_mt:FooEnum()
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TableInFirstNS_mt:FooStruct()
|
||||
function TableInFirstNS_mt:FooUnionType()
|
||||
local o = self.view:Offset(8)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
function TableInFirstNS_mt:FooUnion()
|
||||
local o = self.view:Offset(10)
|
||||
if o ~= 0 then
|
||||
local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)
|
||||
self.view:Union(obj, o)
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function TableInFirstNS_mt:FooStruct()
|
||||
local o = self.view:Offset(12)
|
||||
if o ~= 0 then
|
||||
local x = o + self.view.pos
|
||||
local obj = require('NamespaceA.NamespaceB.StructInNestedNS').New()
|
||||
@@ -46,10 +61,12 @@ function TableInFirstNS_mt:FooStruct()
|
||||
return obj
|
||||
end
|
||||
end
|
||||
function TableInFirstNS.Start(builder) builder:StartObject(3) end
|
||||
function TableInFirstNS.Start(builder) builder:StartObject(5) end
|
||||
function TableInFirstNS.AddFooTable(builder, fooTable) builder:PrependUOffsetTRelativeSlot(0, fooTable, 0) end
|
||||
function TableInFirstNS.AddFooEnum(builder, fooEnum) builder:PrependInt8Slot(1, fooEnum, 0) end
|
||||
function TableInFirstNS.AddFooStruct(builder, fooStruct) builder:PrependStructSlot(2, fooStruct, 0) end
|
||||
function TableInFirstNS.AddFooUnionType(builder, fooUnionType) builder:PrependUint8Slot(2, fooUnionType, 0) end
|
||||
function TableInFirstNS.AddFooUnion(builder, fooUnion) builder:PrependUOffsetTRelativeSlot(3, fooUnion, 0) end
|
||||
function TableInFirstNS.AddFooStruct(builder, fooStruct) builder:PrependStructSlot(4, fooStruct, 0) end
|
||||
function TableInFirstNS.End(builder) return builder:EndObject() end
|
||||
|
||||
return TableInFirstNS -- return the module
|
||||
@@ -48,10 +48,28 @@ class TableInFirstNS extends Table
|
||||
return $o != 0 ? $this->bb->getSbyte($o + $this->bb_pos) : \NamespaceA\NamespaceB\EnumInNestedNS::A;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return byte
|
||||
*/
|
||||
public function getFooUnionType()
|
||||
{
|
||||
$o = $this->__offset(8);
|
||||
return $o != 0 ? $this->bb->getByte($o + $this->bb_pos) : \NamespaceA\NamespaceB\UnionInNestedNS::NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returnint
|
||||
*/
|
||||
public function getFooUnion($obj)
|
||||
{
|
||||
$o = $this->__offset(10);
|
||||
return $o != 0 ? $this->__union($obj, $o) : null;
|
||||
}
|
||||
|
||||
public function getFooStruct()
|
||||
{
|
||||
$obj = new StructInNestedNS();
|
||||
$o = $this->__offset(8);
|
||||
$o = $this->__offset(12);
|
||||
return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : 0;
|
||||
}
|
||||
|
||||
@@ -61,18 +79,20 @@ class TableInFirstNS extends Table
|
||||
*/
|
||||
public static function startTableInFirstNS(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(3);
|
||||
$builder->StartObject(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return TableInFirstNS
|
||||
*/
|
||||
public static function createTableInFirstNS(FlatBufferBuilder $builder, $foo_table, $foo_enum, $foo_struct)
|
||||
public static function createTableInFirstNS(FlatBufferBuilder $builder, $foo_table, $foo_enum, $foo_union_type, $foo_union, $foo_struct)
|
||||
{
|
||||
$builder->startObject(3);
|
||||
$builder->startObject(5);
|
||||
self::addFooTable($builder, $foo_table);
|
||||
self::addFooEnum($builder, $foo_enum);
|
||||
self::addFooUnionType($builder, $foo_union_type);
|
||||
self::addFooUnion($builder, $foo_union);
|
||||
self::addFooStruct($builder, $foo_struct);
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
@@ -98,6 +118,21 @@ class TableInFirstNS extends Table
|
||||
$builder->addSbyteX(1, $fooEnum, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param byte
|
||||
* @return void
|
||||
*/
|
||||
public static function addFooUnionType(FlatBufferBuilder $builder, $fooUnionType)
|
||||
{
|
||||
$builder->addByteX(2, $fooUnionType, 0);
|
||||
}
|
||||
|
||||
public static function addFooUnion(FlatBufferBuilder $builder, $offset)
|
||||
{
|
||||
$builder->addOffsetX(3, $offset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param int
|
||||
@@ -105,7 +140,7 @@ class TableInFirstNS extends Table
|
||||
*/
|
||||
public static function addFooStruct(FlatBufferBuilder $builder, $fooStruct)
|
||||
{
|
||||
$builder->addStructX(2, $fooStruct, 0);
|
||||
$builder->addStructX(4, $fooStruct, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,8 +38,25 @@ class TableInFirstNS(object):
|
||||
return 0
|
||||
|
||||
# TableInFirstNS
|
||||
def FooStruct(self):
|
||||
def FooUnionType(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
|
||||
if o != 0:
|
||||
return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
|
||||
return 0
|
||||
|
||||
# TableInFirstNS
|
||||
def FooUnion(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
|
||||
if o != 0:
|
||||
from flatbuffers.table import Table
|
||||
obj = Table(bytearray(), 0)
|
||||
self._tab.Union(obj, o)
|
||||
return obj
|
||||
return None
|
||||
|
||||
# TableInFirstNS
|
||||
def FooStruct(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
|
||||
if o != 0:
|
||||
x = o + self._tab.Pos
|
||||
obj = StructInNestedNS()
|
||||
@@ -47,14 +64,16 @@ class TableInFirstNS(object):
|
||||
return obj
|
||||
return None
|
||||
|
||||
def TableInFirstNSStart(builder): builder.StartObject(3)
|
||||
def TableInFirstNSStart(builder): builder.StartObject(5)
|
||||
def TableInFirstNSAddFooTable(builder, fooTable): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(fooTable), 0)
|
||||
def TableInFirstNSAddFooEnum(builder, fooEnum): builder.PrependInt8Slot(1, fooEnum, 0)
|
||||
def TableInFirstNSAddFooStruct(builder, fooStruct): builder.PrependStructSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fooStruct), 0)
|
||||
def TableInFirstNSAddFooUnionType(builder, fooUnionType): builder.PrependUint8Slot(2, fooUnionType, 0)
|
||||
def TableInFirstNSAddFooUnion(builder, fooUnion): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(fooUnion), 0)
|
||||
def TableInFirstNSAddFooStruct(builder, fooStruct): builder.PrependStructSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(fooStruct), 0)
|
||||
def TableInFirstNSEnd(builder): return builder.EndObject()
|
||||
|
||||
try:
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -64,6 +83,8 @@ class TableInFirstNST(object):
|
||||
def __init__(self):
|
||||
self.fooTable = None # type: Optional[TableInNestedNST]
|
||||
self.fooEnum = 0 # type: int
|
||||
self.fooUnionType = 0 # type: int
|
||||
self.fooUnion = None # type: Union[None, TableInNestedNST]
|
||||
self.fooStruct = None # type: Optional[StructInNestedNST]
|
||||
|
||||
@classmethod
|
||||
@@ -85,6 +106,8 @@ class TableInFirstNST(object):
|
||||
if tableInFirstNS.FooTable() is not None:
|
||||
self.fooTable = TableInNestedNST.InitFromObj(tableInFirstNS.FooTable())
|
||||
self.fooEnum = tableInFirstNS.FooEnum()
|
||||
self.fooUnionType = tableInFirstNS.FooUnionType()
|
||||
self.fooUnion = UnionInNestedNSCreator(self.fooUnionType, tableInFirstNS.FooUnion())
|
||||
if tableInFirstNS.FooStruct() is not None:
|
||||
self.fooStruct = StructInNestedNST.InitFromObj(tableInFirstNS.FooStruct())
|
||||
|
||||
@@ -92,10 +115,15 @@ class TableInFirstNST(object):
|
||||
def Pack(self, builder):
|
||||
if self.fooTable is not None:
|
||||
fooTable = self.fooTable.Pack(builder)
|
||||
if self.fooUnion is not None:
|
||||
fooUnion = self.fooUnion.Pack(builder)
|
||||
TableInFirstNSStart(builder)
|
||||
if self.fooTable is not None:
|
||||
TableInFirstNSAddFooTable(builder, fooTable)
|
||||
TableInFirstNSAddFooEnum(builder, self.fooEnum)
|
||||
TableInFirstNSAddFooUnionType(builder, self.fooUnionType)
|
||||
if self.fooUnion is not None:
|
||||
TableInFirstNSAddFooUnion(builder, fooUnion)
|
||||
if self.fooStruct is not None:
|
||||
fooStruct = self.fooStruct.Pack(builder)
|
||||
TableInFirstNSAddFooStruct(builder, fooStruct)
|
||||
|
||||
Reference in New Issue
Block a user