| # automatically generated by the FlatBuffers compiler, do not modify |
| |
| # namespace: union_name_test |
| |
| import flatbuffers |
| from flatbuffers.compat import import_numpy |
| np = import_numpy() |
| |
| class Foo(object): |
| __slots__ = ['_tab'] |
| |
| @classmethod |
| def GetRootAs(cls, buf, offset=0): |
| n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) |
| x = Foo() |
| x.Init(buf, n + offset) |
| return x |
| |
| @classmethod |
| def GetRootAsFoo(cls, buf, offset=0): |
| """This method is deprecated. Please switch to GetRootAs.""" |
| return cls.GetRootAs(buf, offset) |
| # Foo |
| def Init(self, buf, pos): |
| self._tab = flatbuffers.table.Table(buf, pos) |
| |
| # Foo |
| def Val(self): |
| o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) |
| if o != 0: |
| return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) |
| return 0 |
| |
| def FooStart(builder): |
| builder.StartObject(1) |
| |
| def Start(builder): |
| FooStart(builder) |
| |
| def FooAddVal(builder, val): |
| builder.PrependInt32Slot(0, val, 0) |
| |
| def AddVal(builder, val): |
| FooAddVal(builder, val) |
| |
| def FooEnd(builder): |
| return builder.EndObject() |
| |
| def End(builder): |
| return FooEnd(builder) |
| |
| |
| class FooT(object): |
| |
| # FooT |
| def __init__( |
| self, |
| val = 0, |
| ): |
| self.val = val # type: int |
| |
| @classmethod |
| def InitFromBuf(cls, buf, pos): |
| foo = Foo() |
| foo.Init(buf, pos) |
| return cls.InitFromObj(foo) |
| |
| @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, foo): |
| x = FooT() |
| x._UnPack(foo) |
| return x |
| |
| # FooT |
| def _UnPack(self, foo): |
| if foo is None: |
| return |
| self.val = foo.Val() |
| |
| # FooT |
| def Pack(self, builder): |
| FooStart(builder) |
| FooAddVal(builder, self.val) |
| foo = FooEnd(builder) |
| return foo |