mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 09:12:22 +00:00
fix(flatbuffers): use manual impl Default for struct object types (#8947)
* fix(flatbuffers): use manual impl Default for struct object types * fix: handle bool and float zero literals in struct object Default impl * fix: regenerate all test bindings with generate_code.py * fix: data type check on swift build * fix: test large array on struct and enum
This commit is contained in:
150
tests/MyGame/Example/LargeArrayStruct.cs
Normal file
150
tests/MyGame/Example/LargeArrayStruct.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
// <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::Google.FlatBuffers;
|
||||
|
||||
public struct LargeArrayStruct : IFlatbufferObject
|
||||
{
|
||||
private Struct __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); }
|
||||
public LargeArrayStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public byte D(int j) { return __p.bb.Get(__p.bb_pos + 0 + j * 1); }
|
||||
public const int DLength = 64;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<byte> GetDBytes() { return __p.bb.ToSpan(__p.bb_pos + 0, 64); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetDBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 0, 64);}
|
||||
#endif
|
||||
public void MutateD(int j, byte d) { __p.bb.Put(__p.bb_pos + 0 + j * 1, d); }
|
||||
public float E(int j) { return __p.bb.GetFloat(__p.bb_pos + 64 + j * 4); }
|
||||
public const int ELength = 64;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<float> GetEBytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, float>(__p.bb.ToSpan(__p.bb_pos + 64, 256)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetEBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 64, 256);}
|
||||
#endif
|
||||
public void MutateE(int j, float e) { __p.bb.PutFloat(__p.bb_pos + 64 + j * 4, e); }
|
||||
public bool F(int j) { return 0!=__p.bb.Get(__p.bb_pos + 320 + j * 1); }
|
||||
public const int FLength = 64;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<bool> GetFBytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, bool>(__p.bb.ToSpan(__p.bb_pos + 320, 64)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetFBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 320, 64);}
|
||||
#endif
|
||||
public void MutateF(int j, bool f) { __p.bb.Put(__p.bb_pos + 320 + j * 1, (byte)(f ? 1 : 0)); }
|
||||
public MyGame.Example.NestedStruct G(int j) { return (new MyGame.Example.NestedStruct()).__assign(__p.bb_pos + 384 + j * 32, __p.bb); }
|
||||
public MyGame.Example.TestEnum H(int j) { return (MyGame.Example.TestEnum)__p.bb.GetSbyte(__p.bb_pos + 2432 + j * 1); }
|
||||
public const int HLength = 64;
|
||||
#if ENABLE_SPAN_T
|
||||
public Span<MyGame.Example.TestEnum> GetHBytes() { return System.Runtime.InteropServices.MemoryMarshal.Cast<byte, MyGame.Example.TestEnum>(__p.bb.ToSpan(__p.bb_pos + 2432, 64)); }
|
||||
#else
|
||||
public ArraySegment<byte>? GetHBytes() { return __p.bb.ToArraySegment(__p.bb_pos + 2432, 64);}
|
||||
#endif
|
||||
public void MutateH(int j, MyGame.Example.TestEnum h) { __p.bb.PutSbyte(__p.bb_pos + 2432 + j * 1, (sbyte)h); }
|
||||
|
||||
public static Offset<MyGame.Example.LargeArrayStruct> CreateLargeArrayStruct(FlatBufferBuilder builder, byte[] D, float[] E, bool[] F, int[,] g_A, MyGame.Example.TestEnum[] g_B, MyGame.Example.TestEnum[,] g_C, long[,] g_D, MyGame.Example.TestEnum[] H) {
|
||||
builder.Prep(8, 2496);
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.PutSbyte((sbyte)H[_idx0-1]);
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.Prep(8, 32);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.PutLong(g_D[_idx0-1,_idx1-1]);
|
||||
}
|
||||
builder.Pad(5);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.PutSbyte((sbyte)g_C[_idx0-1,_idx1-1]);
|
||||
}
|
||||
builder.PutSbyte((sbyte)g_B[_idx0-1]);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.PutInt(g_A[_idx0-1,_idx1-1]);
|
||||
}
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.PutBool(F[_idx0-1]);
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.PutFloat(E[_idx0-1]);
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.PutByte(D[_idx0-1]);
|
||||
}
|
||||
return new Offset<MyGame.Example.LargeArrayStruct>(builder.Offset);
|
||||
}
|
||||
public LargeArrayStructT UnPack() {
|
||||
var _o = new LargeArrayStructT();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(LargeArrayStructT _o) {
|
||||
_o.D = new byte[64];
|
||||
for (var _j = 0; _j < 64; ++_j) { _o.D[_j] = this.D(_j); }
|
||||
_o.E = new float[64];
|
||||
for (var _j = 0; _j < 64; ++_j) { _o.E[_j] = this.E(_j); }
|
||||
_o.F = new bool[64];
|
||||
for (var _j = 0; _j < 64; ++_j) { _o.F[_j] = this.F(_j); }
|
||||
_o.G = new MyGame.Example.NestedStructT[64];
|
||||
for (var _j = 0; _j < 64; ++_j) { _o.G[_j] = this.G(_j).UnPack(); }
|
||||
_o.H = new MyGame.Example.TestEnum[64];
|
||||
for (var _j = 0; _j < 64; ++_j) { _o.H[_j] = this.H(_j); }
|
||||
}
|
||||
public static Offset<MyGame.Example.LargeArrayStruct> Pack(FlatBufferBuilder builder, LargeArrayStructT _o) {
|
||||
if (_o == null) return default(Offset<MyGame.Example.LargeArrayStruct>);
|
||||
var _d = _o.D;
|
||||
var _e = _o.E;
|
||||
var _f = _o.F;
|
||||
var _g_a = new int[64,2];
|
||||
for (var idx0 = 0; idx0 < 64; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_g_a[idx0,idx1] = _o.G[idx0].A[idx1];}}
|
||||
var _g_b = new MyGame.Example.TestEnum[64];
|
||||
for (var idx0 = 0; idx0 < 64; ++idx0) {_g_b[idx0] = _o.G[idx0].B;}
|
||||
var _g_c = new MyGame.Example.TestEnum[64,2];
|
||||
for (var idx0 = 0; idx0 < 64; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_g_c[idx0,idx1] = _o.G[idx0].C[idx1];}}
|
||||
var _g_d = new long[64,2];
|
||||
for (var idx0 = 0; idx0 < 64; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_g_d[idx0,idx1] = _o.G[idx0].D[idx1];}}
|
||||
var _h = _o.H;
|
||||
return CreateLargeArrayStruct(
|
||||
builder,
|
||||
_d,
|
||||
_e,
|
||||
_f,
|
||||
_g_a,
|
||||
_g_b,
|
||||
_g_c,
|
||||
_g_d,
|
||||
_h);
|
||||
}
|
||||
}
|
||||
|
||||
public class LargeArrayStructT
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("d")]
|
||||
public byte[] D { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("e")]
|
||||
public float[] E { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("f")]
|
||||
public bool[] F { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("g")]
|
||||
public MyGame.Example.NestedStructT[] G { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("h")]
|
||||
public MyGame.Example.TestEnum[] H { get; set; }
|
||||
|
||||
public LargeArrayStructT() {
|
||||
this.D = new byte[64];
|
||||
this.E = new float[64];
|
||||
this.F = new bool[64];
|
||||
this.G = new MyGame.Example.NestedStructT[64];
|
||||
this.H = new MyGame.Example.TestEnum[64];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
117
tests/MyGame/Example/LargeArrayStruct.java
Normal file
117
tests/MyGame/Example/LargeArrayStruct.java
Normal file
@@ -0,0 +1,117 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class LargeArrayStruct extends Struct {
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public LargeArrayStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public int d(int j) { return bb.get(bb_pos + 0 + j * 1); }
|
||||
public void mutateD(int j, int d) { bb.put(bb_pos + 0 + j * 1, (byte) d); }
|
||||
public float e(int j) { return bb.getFloat(bb_pos + 64 + j * 4); }
|
||||
public void mutateE(int j, float e) { bb.putFloat(bb_pos + 64 + j * 4, e); }
|
||||
public boolean f(int j) { return 0!=bb.get(bb_pos + 320 + j * 1); }
|
||||
public void mutateF(int j, boolean f) { bb.put(bb_pos + 320 + j * 1, (byte)(f ? 1 : 0)); }
|
||||
public MyGame.Example.NestedStruct g(int j) { return g(new MyGame.Example.NestedStruct(), j); }
|
||||
public MyGame.Example.NestedStruct g(MyGame.Example.NestedStruct obj, int j) { return obj.__assign(bb_pos + 384 + j * 32, bb); }
|
||||
public byte h(int j) { return bb.get(bb_pos + 2432 + j * 1); }
|
||||
public void mutateH(int j, byte h) { bb.put(bb_pos + 2432 + j * 1, h); }
|
||||
|
||||
public static int createLargeArrayStruct(FlatBufferBuilder builder, int[] d, float[] e, boolean[] f, int[][] g_a, byte[] g_b, byte[][] g_c, long[][] g_d, byte[] h) {
|
||||
builder.prep(8, 2496);
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.putByte(h[_idx0-1]);
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.prep(8, 32);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.putLong(g_d[_idx0-1][_idx1-1]);
|
||||
}
|
||||
builder.pad(5);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.putByte(g_c[_idx0-1][_idx1-1]);
|
||||
}
|
||||
builder.putByte(g_b[_idx0-1]);
|
||||
for (int _idx1 = 2; _idx1 > 0; _idx1--) {
|
||||
builder.putInt(g_a[_idx0-1][_idx1-1]);
|
||||
}
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.putBoolean(f[_idx0-1]);
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.putFloat(e[_idx0-1]);
|
||||
}
|
||||
for (int _idx0 = 64; _idx0 > 0; _idx0--) {
|
||||
builder.putByte((byte) d[_idx0-1]);
|
||||
}
|
||||
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 LargeArrayStruct get(int j) { return get(new LargeArrayStruct(), j); }
|
||||
public LargeArrayStruct get(LargeArrayStruct obj, int j) { return obj.__assign(__element(j), bb); }
|
||||
}
|
||||
public LargeArrayStructT unpack() {
|
||||
LargeArrayStructT _o = new LargeArrayStructT();
|
||||
unpackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void unpackTo(LargeArrayStructT _o) {
|
||||
int[] _oD = _o.getD();
|
||||
for (int _j = 0; _j < 64; ++_j) { _oD[_j] = d(_j); }
|
||||
float[] _oE = _o.getE();
|
||||
for (int _j = 0; _j < 64; ++_j) { _oE[_j] = e(_j); }
|
||||
boolean[] _oF = _o.getF();
|
||||
for (int _j = 0; _j < 64; ++_j) { _oF[_j] = f(_j); }
|
||||
MyGame.Example.NestedStructT[] _oG = _o.getG();
|
||||
for (int _j = 0; _j < 64; ++_j) { _oG[_j] = g(_j).unpack(); }
|
||||
byte[] _oH = _o.getH();
|
||||
for (int _j = 0; _j < 64; ++_j) { _oH[_j] = h(_j); }
|
||||
}
|
||||
public static int pack(FlatBufferBuilder builder, LargeArrayStructT _o) {
|
||||
if (_o == null) return 0;
|
||||
int[] _d = _o.getD();
|
||||
float[] _e = _o.getE();
|
||||
boolean[] _f = _o.getF();
|
||||
int[][] _g_a = new int[64][2];
|
||||
for (int idx0 = 0; idx0 < 64; ++idx0) {for (int idx1 = 0; idx1 < 2; ++idx1) {_g_a[idx0][idx1] = _o.getG()[idx0].getA()[idx1];}}
|
||||
byte[] _g_b = new byte[64];
|
||||
for (int idx0 = 0; idx0 < 64; ++idx0) {_g_b[idx0] = _o.getG()[idx0].getB();}
|
||||
byte[][] _g_c = new byte[64][2];
|
||||
for (int idx0 = 0; idx0 < 64; ++idx0) {for (int idx1 = 0; idx1 < 2; ++idx1) {_g_c[idx0][idx1] = _o.getG()[idx0].getC()[idx1];}}
|
||||
long[][] _g_d = new long[64][2];
|
||||
for (int idx0 = 0; idx0 < 64; ++idx0) {for (int idx1 = 0; idx1 < 2; ++idx1) {_g_d[idx0][idx1] = _o.getG()[idx0].getD()[idx1];}}
|
||||
byte[] _h = _o.getH();
|
||||
return createLargeArrayStruct(
|
||||
builder,
|
||||
_d,
|
||||
_e,
|
||||
_f,
|
||||
_g_a,
|
||||
_g_b,
|
||||
_g_c,
|
||||
_g_d,
|
||||
_h);
|
||||
}
|
||||
}
|
||||
|
||||
226
tests/MyGame/Example/LargeArrayStruct.py
Normal file
226
tests/MyGame/Example/LargeArrayStruct.py
Normal file
@@ -0,0 +1,226 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
from typing import Any
|
||||
from MyGame.Example.NestedStruct import NestedStruct
|
||||
np = import_numpy()
|
||||
|
||||
class LargeArrayStruct(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def SizeOf(cls) -> int:
|
||||
return 2496
|
||||
|
||||
# LargeArrayStruct
|
||||
def Init(self, buf: bytes, pos: int):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# LargeArrayStruct
|
||||
def D(self, j = None):
|
||||
if j is None:
|
||||
return [self._tab.Get(flatbuffers.number_types.Uint8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0 + i * 1)) for i in range(self.DLength())]
|
||||
elif j >= 0 and j < self.DLength():
|
||||
return self._tab.Get(flatbuffers.number_types.Uint8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0 + j * 1))
|
||||
else:
|
||||
return None
|
||||
|
||||
# LargeArrayStruct
|
||||
def DAsNumpy(self):
|
||||
return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Uint8Flags, self._tab.Pos + 0, self.DLength())
|
||||
|
||||
# LargeArrayStruct
|
||||
def DLength(self) -> int:
|
||||
return 64
|
||||
|
||||
# LargeArrayStruct
|
||||
def DIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
# LargeArrayStruct
|
||||
def E(self, j = None):
|
||||
if j is None:
|
||||
return [self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(64 + i * 4)) for i in range(self.ELength())]
|
||||
elif j >= 0 and j < self.ELength():
|
||||
return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(64 + j * 4))
|
||||
else:
|
||||
return None
|
||||
|
||||
# LargeArrayStruct
|
||||
def EAsNumpy(self):
|
||||
return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Float32Flags, self._tab.Pos + 64, self.ELength())
|
||||
|
||||
# LargeArrayStruct
|
||||
def ELength(self) -> int:
|
||||
return 64
|
||||
|
||||
# LargeArrayStruct
|
||||
def EIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
# LargeArrayStruct
|
||||
def F(self, j = None):
|
||||
if j is None:
|
||||
return [self._tab.Get(flatbuffers.number_types.BoolFlags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(320 + i * 1)) for i in range(self.FLength())]
|
||||
elif j >= 0 and j < self.FLength():
|
||||
return self._tab.Get(flatbuffers.number_types.BoolFlags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(320 + j * 1))
|
||||
else:
|
||||
return None
|
||||
|
||||
# LargeArrayStruct
|
||||
def FAsNumpy(self):
|
||||
return self._tab.GetArrayAsNumpy(flatbuffers.number_types.BoolFlags, self._tab.Pos + 320, self.FLength())
|
||||
|
||||
# LargeArrayStruct
|
||||
def FLength(self) -> int:
|
||||
return 64
|
||||
|
||||
# LargeArrayStruct
|
||||
def FIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
# LargeArrayStruct
|
||||
def G(self, i: int) -> NestedStruct:
|
||||
obj = NestedStruct()
|
||||
obj.Init(self._tab.Bytes, self._tab.Pos + 384 + i * 32)
|
||||
return obj
|
||||
|
||||
# LargeArrayStruct
|
||||
def GLength(self) -> int:
|
||||
return 64
|
||||
|
||||
# LargeArrayStruct
|
||||
def GIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
# LargeArrayStruct
|
||||
def H(self, j = None):
|
||||
if j is None:
|
||||
return [self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(2432 + i * 1)) for i in range(self.HLength())]
|
||||
elif j >= 0 and j < self.HLength():
|
||||
return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(2432 + j * 1))
|
||||
else:
|
||||
return None
|
||||
|
||||
# LargeArrayStruct
|
||||
def HAsNumpy(self):
|
||||
return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int8Flags, self._tab.Pos + 2432, self.HLength())
|
||||
|
||||
# LargeArrayStruct
|
||||
def HLength(self) -> int:
|
||||
return 64
|
||||
|
||||
# LargeArrayStruct
|
||||
def HIsNone(self) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def CreateLargeArrayStruct(builder, d, e, f, g_a, g_b, g_c, g_d, h):
|
||||
builder.Prep(8, 2496)
|
||||
for _idx0 in range(64 , 0, -1):
|
||||
builder.PrependInt8(h[_idx0-1])
|
||||
for _idx0 in range(64 , 0, -1):
|
||||
builder.Prep(8, 32)
|
||||
for _idx1 in range(2 , 0, -1):
|
||||
builder.PrependInt64(g_d[_idx0-1][_idx1-1])
|
||||
builder.Pad(5)
|
||||
for _idx1 in range(2 , 0, -1):
|
||||
builder.PrependInt8(g_c[_idx0-1][_idx1-1])
|
||||
builder.PrependInt8(g_b[_idx0-1])
|
||||
for _idx1 in range(2 , 0, -1):
|
||||
builder.PrependInt32(g_a[_idx0-1][_idx1-1])
|
||||
for _idx0 in range(64 , 0, -1):
|
||||
builder.PrependBool(f[_idx0-1])
|
||||
for _idx0 in range(64 , 0, -1):
|
||||
builder.PrependFloat32(e[_idx0-1])
|
||||
for _idx0 in range(64 , 0, -1):
|
||||
builder.PrependUint8(d[_idx0-1])
|
||||
return builder.Offset()
|
||||
|
||||
import MyGame.Example.NestedStruct
|
||||
try:
|
||||
from typing import List
|
||||
except:
|
||||
pass
|
||||
|
||||
class LargeArrayStructT(object):
|
||||
|
||||
# LargeArrayStructT
|
||||
def __init__(
|
||||
self,
|
||||
d = None,
|
||||
e = None,
|
||||
f = None,
|
||||
g = None,
|
||||
h = None,
|
||||
):
|
||||
self.d = d # type: Optional[List[int]]
|
||||
self.e = e # type: Optional[List[float]]
|
||||
self.f = f # type: Optional[List[bool]]
|
||||
self.g = g # type: Optional[List[MyGame.Example.NestedStruct.NestedStructT]]
|
||||
self.h = h # type: Optional[List[int]]
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
largeArrayStruct = LargeArrayStruct()
|
||||
largeArrayStruct.Init(buf, pos)
|
||||
return cls.InitFromObj(largeArrayStruct)
|
||||
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf, pos=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
|
||||
return cls.InitFromBuf(buf, pos+n)
|
||||
|
||||
@classmethod
|
||||
def InitFromObj(cls, largeArrayStruct):
|
||||
x = LargeArrayStructT()
|
||||
x._UnPack(largeArrayStruct)
|
||||
return x
|
||||
|
||||
# LargeArrayStructT
|
||||
def _UnPack(self, largeArrayStruct):
|
||||
if largeArrayStruct is None:
|
||||
return
|
||||
if not largeArrayStruct.DIsNone():
|
||||
if np is None:
|
||||
self.d = []
|
||||
for i in range(largeArrayStruct.DLength()):
|
||||
self.d.append(largeArrayStruct.D(i))
|
||||
else:
|
||||
self.d = largeArrayStruct.DAsNumpy()
|
||||
if not largeArrayStruct.EIsNone():
|
||||
if np is None:
|
||||
self.e = []
|
||||
for i in range(largeArrayStruct.ELength()):
|
||||
self.e.append(largeArrayStruct.E(i))
|
||||
else:
|
||||
self.e = largeArrayStruct.EAsNumpy()
|
||||
if not largeArrayStruct.FIsNone():
|
||||
if np is None:
|
||||
self.f = []
|
||||
for i in range(largeArrayStruct.FLength()):
|
||||
self.f.append(largeArrayStruct.F(i))
|
||||
else:
|
||||
self.f = largeArrayStruct.FAsNumpy()
|
||||
if not largeArrayStruct.GIsNone():
|
||||
self.g = []
|
||||
for i in range(largeArrayStruct.GLength()):
|
||||
if largeArrayStruct.G(i) is None:
|
||||
self.g.append(None)
|
||||
else:
|
||||
nestedStruct_ = MyGame.Example.NestedStruct.NestedStructT.InitFromObj(largeArrayStruct.G(i))
|
||||
self.g.append(nestedStruct_)
|
||||
if not largeArrayStruct.HIsNone():
|
||||
if np is None:
|
||||
self.h = []
|
||||
for i in range(largeArrayStruct.HLength()):
|
||||
self.h.append(largeArrayStruct.H(i))
|
||||
else:
|
||||
self.h = largeArrayStruct.HAsNumpy()
|
||||
|
||||
# LargeArrayStructT
|
||||
def Pack(self, builder):
|
||||
return CreateLargeArrayStruct(builder, self.d, self.e, self.f, self.g.a, self.g.b, self.g.c, self.g.d, self.h)
|
||||
60
tests/MyGame/Example/LargeArrayStruct.pyi
Normal file
60
tests/MyGame/Example/LargeArrayStruct.pyi
Normal file
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import flatbuffers
|
||||
import numpy as np
|
||||
|
||||
import typing
|
||||
from MyGame.Example.NestedStruct import NestedStruct, NestedStructT
|
||||
from MyGame.Example.TestEnum import TestEnum
|
||||
|
||||
uoffset: typing.TypeAlias = flatbuffers.number_types.UOffsetTFlags.py_type
|
||||
|
||||
class LargeArrayStruct(object):
|
||||
@classmethod
|
||||
def SizeOf(cls) -> int: ...
|
||||
|
||||
def Init(self, buf: bytes, pos: int) -> None: ...
|
||||
def D(self, i: int) -> typing.List[int]: ...
|
||||
def DAsNumpy(self) -> np.ndarray: ...
|
||||
def DLength(self) -> int: ...
|
||||
def DIsNone(self) -> bool: ...
|
||||
def E(self, i: int) -> typing.List[float]: ...
|
||||
def EAsNumpy(self) -> np.ndarray: ...
|
||||
def ELength(self) -> int: ...
|
||||
def EIsNone(self) -> bool: ...
|
||||
def F(self, i: int) -> typing.List[bool]: ...
|
||||
def FAsNumpy(self) -> np.ndarray: ...
|
||||
def FLength(self) -> int: ...
|
||||
def FIsNone(self) -> bool: ...
|
||||
def G(self, i: int) -> NestedStruct | None: ...
|
||||
def GLength(self) -> int: ...
|
||||
def GIsNone(self) -> bool: ...
|
||||
def H(self, i: int) -> typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]: ...
|
||||
def HAsNumpy(self) -> np.ndarray: ...
|
||||
def HLength(self) -> int: ...
|
||||
def HIsNone(self) -> bool: ...
|
||||
class LargeArrayStructT(object):
|
||||
d: typing.List[int]
|
||||
e: typing.List[float]
|
||||
f: typing.List[bool]
|
||||
g: typing.List[NestedStructT]
|
||||
h: typing.List[typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]]
|
||||
def __init__(
|
||||
self,
|
||||
d: typing.List[int] | None = ...,
|
||||
e: typing.List[float] | None = ...,
|
||||
f: typing.List[bool] | None = ...,
|
||||
g: typing.List['NestedStructT'] | None = ...,
|
||||
h: typing.List[typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]] | None = ...,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf: bytes, pos: int) -> LargeArrayStructT: ...
|
||||
@classmethod
|
||||
def InitFromPackedBuf(cls, buf: bytes, pos: int = 0) -> LargeArrayStructT: ...
|
||||
@classmethod
|
||||
def InitFromObj(cls, largeArrayStruct: LargeArrayStruct) -> LargeArrayStructT: ...
|
||||
def _UnPack(self, largeArrayStruct: LargeArrayStruct) -> None: ...
|
||||
def Pack(self, builder: flatbuffers.Builder) -> None: ...
|
||||
|
||||
def CreateLargeArrayStruct(builder: flatbuffers.Builder, d: int, e: float, f: bool, g_a: int, g_b: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C], g_c: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C], g_d: int, h: typing.Literal[TestEnum.A, TestEnum.B, TestEnum.C]) -> uoffset: ...
|
||||
|
||||
57
tests/MyGame/Example/LargeArrayStructT.java
Normal file
57
tests/MyGame/Example/LargeArrayStructT.java
Normal file
@@ -0,0 +1,57 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class LargeArrayStructT {
|
||||
private int[] d;
|
||||
private float[] e;
|
||||
private boolean[] f;
|
||||
private MyGame.Example.NestedStructT[] g;
|
||||
private byte[] h;
|
||||
|
||||
public int[] getD() { return d; }
|
||||
|
||||
public void setD(int[] d) { if (d != null && d.length == 64) this.d = d; }
|
||||
|
||||
public float[] getE() { return e; }
|
||||
|
||||
public void setE(float[] e) { if (e != null && e.length == 64) this.e = e; }
|
||||
|
||||
public boolean[] getF() { return f; }
|
||||
|
||||
public void setF(boolean[] f) { if (f != null && f.length == 64) this.f = f; }
|
||||
|
||||
public MyGame.Example.NestedStructT[] getG() { return g; }
|
||||
|
||||
public void setG(MyGame.Example.NestedStructT[] g) { if (g != null && g.length == 64) this.g = g; }
|
||||
|
||||
public byte[] getH() { return h; }
|
||||
|
||||
public void setH(byte[] h) { if (h != null && h.length == 64) this.h = h; }
|
||||
|
||||
|
||||
public LargeArrayStructT() {
|
||||
this.d = new int[64];
|
||||
this.e = new float[64];
|
||||
this.f = new boolean[64];
|
||||
this.g = new MyGame.Example.NestedStructT[64];
|
||||
this.h = new byte[64];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user