mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 01:07:29 +00:00
Port FlatBuffers to Python.
Implement code generation and self-contained runtime library for Python.
The test suite verifies:
- Correctness of generated Python code by comparing output to that of
the other language ports.
- The exact bytes in the Builder buffer during many scenarios.
- Vtable deduplication correctness.
- Edge cases for table construction, via a fuzzer derived from the Go
implementation.
- All code is simultaneously valid in Python 2.6, 2.7, and 3.4.
The test suite includes benchmarks for:
- Building 'gold' data.
- Parsing 'gold' data.
- Deduplicating vtables.
All tests pass on this author's system for the following Python
implementations:
- CPython 2.6.7
- CPython 2.7.8
- CPython 3.4.2
- PyPy 2.5.0 (CPython 2.7.8 compatible)
This commit is contained in:
44
tests/MyGame/Example/Vec3.py
Normal file
44
tests/MyGame/Example/Vec3.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# automatically generated, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
import flatbuffers
|
||||
|
||||
class Vec3(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
# Vec3
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# Vec3
|
||||
def X(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0))
|
||||
# Vec3
|
||||
def Y(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4))
|
||||
# Vec3
|
||||
def Z(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(8))
|
||||
# Vec3
|
||||
def Test1(self): return self._tab.Get(flatbuffers.number_types.Float64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(16))
|
||||
# Vec3
|
||||
def Test2(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(24))
|
||||
# Vec3
|
||||
def Test3(self, obj):
|
||||
obj.Init(self._tab.Bytes, self._tab.Pos + 26)
|
||||
return obj
|
||||
|
||||
|
||||
def CreateVec3(builder, x, y, z, test1, test2, Test_a, Test_b):
|
||||
builder.Prep(16, 32)
|
||||
builder.Pad(2)
|
||||
builder.Prep(2, 4)
|
||||
builder.Pad(1)
|
||||
builder.PrependInt8(Test_b)
|
||||
builder.PrependInt16(Test_a)
|
||||
builder.Pad(1)
|
||||
builder.PrependInt8(test2)
|
||||
builder.PrependFloat64(test1)
|
||||
builder.Pad(4)
|
||||
builder.PrependFloat32(z)
|
||||
builder.PrependFloat32(y)
|
||||
builder.PrependFloat32(x)
|
||||
return builder.Offset()
|
||||
Reference in New Issue
Block a user