Add support for fixed-size arrays (#5313)

This commit is contained in:
svenk177
2019-06-18 00:15:13 +02:00
committed by Wouter van Oortmerssen
parent 0d2cebccfe
commit e635141d5b
40 changed files with 2113 additions and 220 deletions

View File

@@ -0,0 +1,50 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
namespace MyGame.Example
{
using global::System;
using global::FlatBuffers;
public struct ArrayStruct : IFlatbufferObject
{
private Struct __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; }
public ArrayStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public float A { get { return __p.bb.GetFloat(__p.bb_pos + 0); } }
public void MutateA(float a) { __p.bb.PutFloat(__p.bb_pos + 0, a); }
public int B(int j) { return __p.bb.GetInt(__p.bb_pos + 4 + j * 4); }
public void MutateB(int j, int b) { __p.bb.PutInt(__p.bb_pos + 4 + j * 4, b); }
public sbyte C { get { return __p.bb.GetSbyte(__p.bb_pos + 64); } }
public void MutateC(sbyte c) { __p.bb.PutSbyte(__p.bb_pos + 64, c); }
public MyGame.Example.NestedStruct D(int j) { return (new MyGame.Example.NestedStruct()).__assign(__p.bb_pos + 68 + j * 12, __p.bb); }
public static Offset<MyGame.Example.ArrayStruct> CreateArrayStruct(FlatBufferBuilder builder, float A, int[] B, sbyte C, int[,] d_A, MyGame.Example.TestEnum[] d_B, MyGame.Example.TestEnum[,] d_C) {
builder.Prep(4, 92);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.Prep(4, 12);
builder.Pad(1);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.PutSbyte((sbyte)d_C[_idx0-1,_idx1-1]);
}
builder.PutSbyte((sbyte)d_B[_idx0-1]);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.PutInt(d_A[_idx0-1,_idx1-1]);
}
}
builder.Pad(3);
builder.PutSbyte(C);
for (int _idx0 = 15; _idx0 > 0; _idx0--) {
builder.PutInt(B[_idx0-1]);
}
builder.PutFloat(A);
return new Offset<MyGame.Example.ArrayStruct>(builder.Offset);
}
};
}

View File

@@ -0,0 +1,45 @@
// 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 ArrayStruct extends Struct {
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
public ArrayStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public float a() { return bb.getFloat(bb_pos + 0); }
public void mutateA(float a) { bb.putFloat(bb_pos + 0, a); }
public int b(int j) { return bb.getInt(bb_pos + 4 + j * 4); }
public void mutateB(int j, int b) { bb.putInt(bb_pos + 4 + j * 4, b); }
public byte c() { return bb.get(bb_pos + 64); }
public void mutateC(byte c) { bb.put(bb_pos + 64, c); }
public MyGame.Example.NestedStruct d(MyGame.Example.NestedStruct obj, int j) { return obj.__assign(bb_pos + 68 + j * 12, bb); }
public static int createArrayStruct(FlatBufferBuilder builder, float a, int[] b, byte c, int[][] d_a, byte[] d_b, byte[][] d_c) {
builder.prep(4, 92);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.prep(4, 12);
builder.pad(1);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.putByte(d_c[_idx0-1][_idx1-1]);
}
builder.putByte(d_b[_idx0-1]);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.putInt(d_a[_idx0-1][_idx1-1]);
}
}
builder.pad(3);
builder.putByte(c);
for (int _idx0 = 15; _idx0 > 0; _idx0--) {
builder.putInt(b[_idx0-1]);
}
builder.putFloat(a);
return builder.offset();
}
}

View File

@@ -0,0 +1,41 @@
# automatically generated by the FlatBuffers compiler, do not modify
# namespace: Example
import flatbuffers
class ArrayStruct(object):
__slots__ = ['_tab']
# ArrayStruct
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)
# ArrayStruct
def A(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0))
# ArrayStruct
def B(self): return [self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4 + i * 4)) for i in range(15)]
# ArrayStruct
def C(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(64))
# ArrayStruct
def D(self, obj, i):
obj.Init(self._tab.Bytes, self._tab.Pos + 68 + i * 12)
return obj
def CreateArrayStruct(builder, a, b, c, d_a, d_b, d_c):
builder.Prep(4, 92)
for _idx0 in range(2 , 0, -1):
builder.Prep(4, 12)
builder.Pad(1)
for _idx1 in range(2 , 0, -1):
builder.PrependInt8(d_c[_idx0-1][_idx1-1])
builder.PrependInt8(d_b[_idx0-1])
for _idx1 in range(2 , 0, -1):
builder.PrependInt32(d_a[_idx0-1][_idx1-1])
builder.Pad(3)
builder.PrependInt8(c)
for _idx0 in range(15 , 0, -1):
builder.PrependInt32(b[_idx0-1])
builder.PrependFloat32(a)
return builder.Offset()

View File

@@ -0,0 +1,34 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
namespace MyGame.Example
{
using global::System;
using global::FlatBuffers;
public struct ArrayTable : IFlatbufferObject
{
private Table __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb) { return GetRootAsArrayTable(_bb, new ArrayTable()); }
public static ArrayTable GetRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { FlatBufferConstants.FLATBUFFERS_1_11_1(); return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
public static bool ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return Table.__has_identifier(_bb, "ARRT"); }
public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; }
public ArrayTable __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public MyGame.Example.ArrayStruct? A { get { int o = __p.__offset(4); return o != 0 ? (MyGame.Example.ArrayStruct?)(new MyGame.Example.ArrayStruct()).__assign(o + __p.bb_pos, __p.bb) : null; } }
public static void StartArrayTable(FlatBufferBuilder builder) { builder.StartTable(1); }
public static void AddA(FlatBufferBuilder builder, Offset<MyGame.Example.ArrayStruct> aOffset) { builder.AddStruct(0, aOffset.Value, 0); }
public static Offset<MyGame.Example.ArrayTable> EndArrayTable(FlatBufferBuilder builder) {
int o = builder.EndTable();
return new Offset<MyGame.Example.ArrayTable>(o);
}
public static void FinishArrayTableBuffer(FlatBufferBuilder builder, Offset<MyGame.Example.ArrayTable> offset) { builder.Finish(offset.Value, "ARRT"); }
public static void FinishSizePrefixedArrayTableBuffer(FlatBufferBuilder builder, Offset<MyGame.Example.ArrayTable> offset) { builder.FinishSizePrefixed(offset.Value, "ARRT"); }
};
}

View File

@@ -0,0 +1,30 @@
// 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 ArrayTable extends Table {
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb) { return getRootAsArrayTable(_bb, new ArrayTable()); }
public static ArrayTable getRootAsArrayTable(ByteBuffer _bb, ArrayTable obj) { Constants.FLATBUFFERS_1_11_1(); _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public static boolean ArrayTableBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "ARRT"); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; vtable_start = bb_pos - bb.getInt(bb_pos); vtable_size = bb.getShort(vtable_start); }
public ArrayTable __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public MyGame.Example.ArrayStruct a() { return a(new MyGame.Example.ArrayStruct()); }
public MyGame.Example.ArrayStruct a(MyGame.Example.ArrayStruct obj) { int o = __offset(4); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
public static void startArrayTable(FlatBufferBuilder builder) { builder.startTable(1); }
public static void addA(FlatBufferBuilder builder, int aOffset) { builder.addStruct(0, aOffset, 0); }
public static int endArrayTable(FlatBufferBuilder builder) {
int o = builder.endTable();
return o;
}
public static void finishArrayTableBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset, "ARRT"); }
public static void finishSizePrefixedArrayTableBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset, "ARRT"); }
}

View File

@@ -0,0 +1,34 @@
# automatically generated by the FlatBuffers compiler, do not modify
# namespace: Example
import flatbuffers
class ArrayTable(object):
__slots__ = ['_tab']
@classmethod
def GetRootAsArrayTable(cls, buf, offset):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = ArrayTable()
x.Init(buf, n + offset)
return x
# ArrayTable
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)
# ArrayTable
def A(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
if o != 0:
x = o + self._tab.Pos
from .ArrayStruct import ArrayStruct
obj = ArrayStruct()
obj.Init(self._tab.Bytes, x)
return obj
return None
def ArrayTableStart(builder): builder.StartObject(1)
def ArrayTableAddA(builder, a): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(a), 0)
def ArrayTableEnd(builder): return builder.EndObject()

View File

@@ -0,0 +1,40 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
namespace MyGame.Example
{
using global::System;
using global::FlatBuffers;
public struct NestedStruct : IFlatbufferObject
{
private Struct __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; }
public NestedStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public int A(int j) { return __p.bb.GetInt(__p.bb_pos + 0 + j * 4); }
public void MutateA(int j, int a) { __p.bb.PutInt(__p.bb_pos + 0 + j * 4, a); }
public MyGame.Example.TestEnum B { get { return (MyGame.Example.TestEnum)__p.bb.GetSbyte(__p.bb_pos + 8); } }
public void MutateB(MyGame.Example.TestEnum b) { __p.bb.PutSbyte(__p.bb_pos + 8, (sbyte)b); }
public MyGame.Example.TestEnum C(int j) { return (MyGame.Example.TestEnum)__p.bb.GetSbyte(__p.bb_pos + 9 + j * 1); }
public void MutateC(int j, MyGame.Example.TestEnum c) { __p.bb.PutSbyte(__p.bb_pos + 9 + j * 1, (sbyte)c); }
public static Offset<MyGame.Example.NestedStruct> CreateNestedStruct(FlatBufferBuilder builder, int[] A, MyGame.Example.TestEnum B, MyGame.Example.TestEnum[] C) {
builder.Prep(4, 12);
builder.Pad(1);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.PutSbyte((sbyte)C[_idx0-1]);
}
builder.PutSbyte((sbyte)B);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.PutInt(A[_idx0-1]);
}
return new Offset<MyGame.Example.NestedStruct>(builder.Offset);
}
};
}

View File

@@ -0,0 +1,35 @@
// 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 NestedStruct extends Struct {
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
public NestedStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public int a(int j) { return bb.getInt(bb_pos + 0 + j * 4); }
public void mutateA(int j, int a) { bb.putInt(bb_pos + 0 + j * 4, a); }
public byte b() { return bb.get(bb_pos + 8); }
public void mutateB(byte b) { bb.put(bb_pos + 8, b); }
public byte c(int j) { return bb.get(bb_pos + 9 + j * 1); }
public void mutateC(int j, byte c) { bb.put(bb_pos + 9 + j * 1, c); }
public static int createNestedStruct(FlatBufferBuilder builder, int[] a, byte b, byte[] c) {
builder.prep(4, 12);
builder.pad(1);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.putByte(c[_idx0-1]);
}
builder.putByte(b);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.putInt(a[_idx0-1]);
}
return builder.offset();
}
}

View File

@@ -0,0 +1,29 @@
# automatically generated by the FlatBuffers compiler, do not modify
# namespace: Example
import flatbuffers
class NestedStruct(object):
__slots__ = ['_tab']
# NestedStruct
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)
# NestedStruct
def A(self): return [self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0 + i * 4)) for i in range(2)]
# NestedStruct
def B(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(8))
# NestedStruct
def C(self): return [self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(9 + i * 1)) for i in range(2)]
def CreateNestedStruct(builder, a, b, c):
builder.Prep(4, 12)
builder.Pad(1)
for _idx0 in range(2 , 0, -1):
builder.PrependInt8(c[_idx0-1])
builder.PrependInt8(b)
for _idx0 in range(2 , 0, -1):
builder.PrependInt32(a[_idx0-1])
return builder.Offset()

View File

@@ -0,0 +1,16 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
namespace MyGame.Example
{
public enum TestEnum : sbyte
{
A = 0,
B = 1,
C = 2,
};
}

View File

@@ -0,0 +1,15 @@
// automatically generated by the FlatBuffers compiler, do not modify
package MyGame.Example;
public final class TestEnum {
private TestEnum() { }
public static final byte A = 0;
public static final byte B = 1;
public static final byte C = 2;
public static final String[] names = { "A", "B", "C", };
public static String name(int e) { return names[e]; }
}

View File

@@ -0,0 +1,9 @@
# automatically generated by the FlatBuffers compiler, do not modify
# namespace: Example
class TestEnum(object):
A = 0
B = 1
C = 2