Fix incorrect padding in arrays of structs (Issue #5484) (#5491)

This commit is contained in:
svenk177
2019-08-23 19:46:47 +02:00
committed by Wouter van Oortmerssen
parent b97b342f59
commit 4525c91be3
16 changed files with 228 additions and 57 deletions

View File

@@ -21,13 +21,25 @@ public struct ArrayStruct : IFlatbufferObject
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 MyGame.Example.NestedStruct D(int j) { return (new MyGame.Example.NestedStruct()).__assign(__p.bb_pos + 72 + j * 32, __p.bb); }
public int E { get { return __p.bb.GetInt(__p.bb_pos + 136); } }
public void MutateE(int e) { __p.bb.PutInt(__p.bb_pos + 136, e); }
public long F(int j) { return __p.bb.GetLong(__p.bb_pos + 144 + j * 8); }
public void MutateF(int j, long f) { __p.bb.PutLong(__p.bb_pos + 144 + j * 8, f); }
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);
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, long[,] d_D, int E, long[] F) {
builder.Prep(8, 160);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.Prep(4, 12);
builder.Pad(1);
builder.PutLong(F[_idx0-1]);
}
builder.Pad(4);
builder.PutInt(E);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.Prep(8, 32);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.PutLong(d_D[_idx0-1,_idx1-1]);
}
builder.Pad(5);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.PutSbyte((sbyte)d_C[_idx0-1,_idx1-1]);
}
@@ -36,7 +48,7 @@ public struct ArrayStruct : IFlatbufferObject
builder.PutInt(d_A[_idx0-1,_idx1-1]);
}
}
builder.Pad(3);
builder.Pad(7);
builder.PutSbyte(C);
for (int _idx0 = 15; _idx0 > 0; _idx0--) {
builder.PutInt(B[_idx0-1]);

View File

@@ -18,13 +18,25 @@ public final class ArrayStruct extends Struct {
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 MyGame.Example.NestedStruct d(MyGame.Example.NestedStruct obj, int j) { return obj.__assign(bb_pos + 72 + j * 32, bb); }
public int e() { return bb.getInt(bb_pos + 136); }
public void mutateE(int e) { bb.putInt(bb_pos + 136, e); }
public long f(int j) { return bb.getLong(bb_pos + 144 + j * 8); }
public void mutateF(int j, long f) { bb.putLong(bb_pos + 144 + j * 8, f); }
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);
public static int createArrayStruct(FlatBufferBuilder builder, float a, int[] b, byte c, int[][] d_a, byte[] d_b, byte[][] d_c, long[][] d_d, int e, long[] f) {
builder.prep(8, 160);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.prep(4, 12);
builder.pad(1);
builder.putLong(f[_idx0-1]);
}
builder.pad(4);
builder.putInt(e);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.prep(8, 32);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.putLong(d_d[_idx0-1][_idx1-1]);
}
builder.pad(5);
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
builder.putByte(d_c[_idx0-1][_idx1-1]);
}
@@ -33,7 +45,7 @@ public final class ArrayStruct extends Struct {
builder.putInt(d_a[_idx0-1][_idx1-1]);
}
}
builder.pad(3);
builder.pad(7);
builder.putByte(c);
for (int _idx0 = 15; _idx0 > 0; _idx0--) {
builder.putInt(b[_idx0-1]);

View File

@@ -19,21 +19,31 @@ class ArrayStruct(object):
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)
obj.Init(self._tab.Bytes, self._tab.Pos + 72 + i * 32)
return obj
# ArrayStruct
def E(self): return self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(136))
# ArrayStruct
def F(self): return [self._tab.Get(flatbuffers.number_types.Int64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(144 + i * 8)) for i in range(2)]
def CreateArrayStruct(builder, a, b, c, d_a, d_b, d_c):
builder.Prep(4, 92)
def CreateArrayStruct(builder, a, b, c, d_a, d_b, d_c, d_d, e, f):
builder.Prep(8, 160)
for _idx0 in range(2 , 0, -1):
builder.Prep(4, 12)
builder.Pad(1)
builder.PrependInt64(f[_idx0-1])
builder.Pad(4)
builder.PrependInt32(e)
for _idx0 in range(2 , 0, -1):
builder.Prep(8, 32)
for _idx1 in range(2 , 0, -1):
builder.PrependInt64(d_d[_idx0-1][_idx1-1])
builder.Pad(5)
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.Pad(7)
builder.PrependInt8(c)
for _idx0 in range(15 , 0, -1):
builder.PrependInt32(b[_idx0-1])

View File

@@ -21,10 +21,15 @@ public struct NestedStruct : IFlatbufferObject
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 long D(int j) { return __p.bb.GetLong(__p.bb_pos + 16 + j * 8); }
public void MutateD(int j, long d) { __p.bb.PutLong(__p.bb_pos + 16 + j * 8, d); }
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);
public static Offset<MyGame.Example.NestedStruct> CreateNestedStruct(FlatBufferBuilder builder, int[] A, MyGame.Example.TestEnum B, MyGame.Example.TestEnum[] C, long[] D) {
builder.Prep(8, 32);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.PutLong(D[_idx0-1]);
}
builder.Pad(5);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.PutSbyte((sbyte)C[_idx0-1]);
}

View File

@@ -18,10 +18,15 @@ public final class NestedStruct extends Struct {
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 long d(int j) { return bb.getLong(bb_pos + 16 + j * 8); }
public void mutateD(int j, long d) { bb.putLong(bb_pos + 16 + j * 8, d); }
public static int createNestedStruct(FlatBufferBuilder builder, int[] a, byte b, byte[] c) {
builder.prep(4, 12);
builder.pad(1);
public static int createNestedStruct(FlatBufferBuilder builder, int[] a, byte b, byte[] c, long[] d) {
builder.prep(8, 32);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.putLong(d[_idx0-1]);
}
builder.pad(5);
for (int _idx0 = 2; _idx0 > 0; _idx0--) {
builder.putByte(c[_idx0-1]);
}

View File

@@ -17,10 +17,14 @@ class NestedStruct(object):
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)]
# NestedStruct
def D(self): return [self._tab.Get(flatbuffers.number_types.Int64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(16 + i * 8)) for i in range(2)]
def CreateNestedStruct(builder, a, b, c):
builder.Prep(4, 12)
builder.Pad(1)
def CreateNestedStruct(builder, a, b, c, d):
builder.Prep(8, 32)
for _idx0 in range(2 , 0, -1):
builder.PrependInt64(d[_idx0-1])
builder.Pad(5)
for _idx0 in range(2 , 0, -1):
builder.PrependInt8(c[_idx0-1])
builder.PrependInt8(b)