mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 07:50:59 +00:00
Better python generated code naming (#6336)
* Remove a lot of redundancy from the Python generated code. Update tutorial to reflect new Python generated code. * Add aliases for newly deprecated Python generated methods. This should help with backwards compatibility. * Fix incorrect names in deprecated comments.
This commit is contained in:
@@ -10,13 +10,17 @@ class TestSimpleTableWithEnum(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def GetRootAsTestSimpleTableWithEnum(cls, buf, offset=0):
|
||||
def GetRootAs(cls, buf, offset=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = TestSimpleTableWithEnum()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def GetRootAsTestSimpleTableWithEnum(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
@classmethod
|
||||
def TestSimpleTableWithEnumBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
|
||||
return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x4D\x4F\x4E\x53", size_prefixed=size_prefixed)
|
||||
|
||||
@@ -31,10 +35,18 @@ class TestSimpleTableWithEnum(object):
|
||||
return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
|
||||
return 2
|
||||
|
||||
def TestSimpleTableWithEnumStart(builder): builder.StartObject(1)
|
||||
def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependUint8Slot(0, color, 2)
|
||||
def TestSimpleTableWithEnumEnd(builder): return builder.EndObject()
|
||||
|
||||
def Start(builder): builder.StartObject(1)
|
||||
def TestSimpleTableWithEnumStart(builder):
|
||||
"""This method is deprecated. Please switch to Start."""
|
||||
return Start(builder)
|
||||
def AddColor(builder, color): builder.PrependUint8Slot(0, color, 2)
|
||||
def TestSimpleTableWithEnumAddColor(builder, color):
|
||||
"""This method is deprecated. Please switch to AddColor."""
|
||||
return AddColor(builder, color)
|
||||
def End(builder): return builder.EndObject()
|
||||
def TestSimpleTableWithEnumEnd(builder):
|
||||
"""This method is deprecated. Please switch to End."""
|
||||
return End(builder)
|
||||
|
||||
class TestSimpleTableWithEnumT(object):
|
||||
|
||||
@@ -62,7 +74,7 @@ class TestSimpleTableWithEnumT(object):
|
||||
|
||||
# TestSimpleTableWithEnumT
|
||||
def Pack(self, builder):
|
||||
TestSimpleTableWithEnumStart(builder)
|
||||
TestSimpleTableWithEnumAddColor(builder, self.color)
|
||||
testSimpleTableWithEnum = TestSimpleTableWithEnumEnd(builder)
|
||||
Start(builder)
|
||||
AddColor(builder, self.color)
|
||||
testSimpleTableWithEnum = End(builder)
|
||||
return testSimpleTableWithEnum
|
||||
|
||||
Reference in New Issue
Block a user