• rw's avatar
    Port FlatBuffers to Python. · 48dfc69e
    rw authored
    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)
    48dfc69e
Test.py 688 Bytes
# automatically generated, do not modify

# namespace: Example

import flatbuffers

class Test(object):
    __slots__ = ['_tab']

    # Test
    def Init(self, buf, pos):
        self._tab = flatbuffers.table.Table(buf, pos)

    # Test
    def A(self): return self._tab.Get(flatbuffers.number_types.Int16Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0))
    # Test
    def B(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(2))

def CreateTest(builder, a, b):
    builder.Prep(2, 4)
    builder.Pad(1)
    builder.PrependInt8(b)
    builder.PrependInt16(a)
    return builder.Offset()