mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 08:35:45 +00:00
[Python] Fixed the issue with nested unions relying on InitFromBuf. (#7576)
* feat: Fixed the issue with nested unions relying on InitFromBuf. Problem: Issue #7569 Nested Unions were broken with the introduction of parsing buffers with an initial encoding offset. Fix: Revert the InitFromBuf method to the previous version and introduction of InitFromPackedBuf that allows users to read types from packed buffers applying the offset automatically. Test: Added in TestNestedUnionTables to test the encoding and decoding ability using a nested table with a union field. * fix: Uncommented generate code command
This commit is contained in:
@@ -120,11 +120,15 @@ class InParentNamespaceT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
inParentNamespace = InParentNamespace()
|
||||
inParentNamespace.Init(buf, pos+n)
|
||||
inParentNamespace.Init(buf, pos)
|
||||
return cls.InitFromObj(inParentNamespace)
|
||||
|
||||
@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, inParentNamespace):
|
||||
x = InParentNamespaceT()
|
||||
@@ -177,11 +181,15 @@ class MonsterT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
monster = Monster()
|
||||
monster.Init(buf, pos+n)
|
||||
monster.Init(buf, pos)
|
||||
return cls.InitFromObj(monster)
|
||||
|
||||
@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, monster):
|
||||
x = MonsterT()
|
||||
@@ -233,11 +241,15 @@ class TestT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
test = Test()
|
||||
test.Init(buf, pos+n)
|
||||
test.Init(buf, pos)
|
||||
return cls.InitFromObj(test)
|
||||
|
||||
@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, test):
|
||||
x = TestT()
|
||||
@@ -298,11 +310,15 @@ class TestSimpleTableWithEnumT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
testSimpleTableWithEnum = TestSimpleTableWithEnum()
|
||||
testSimpleTableWithEnum.Init(buf, pos+n)
|
||||
testSimpleTableWithEnum.Init(buf, pos)
|
||||
return cls.InitFromObj(testSimpleTableWithEnum)
|
||||
|
||||
@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, testSimpleTableWithEnum):
|
||||
x = TestSimpleTableWithEnumT()
|
||||
@@ -384,11 +400,15 @@ class Vec3T(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
vec3 = Vec3()
|
||||
vec3.Init(buf, pos+n)
|
||||
vec3.Init(buf, pos)
|
||||
return cls.InitFromObj(vec3)
|
||||
|
||||
@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, vec3):
|
||||
x = Vec3T()
|
||||
@@ -444,11 +464,15 @@ class AbilityT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
ability = Ability()
|
||||
ability.Init(buf, pos+n)
|
||||
ability.Init(buf, pos)
|
||||
return cls.InitFromObj(ability)
|
||||
|
||||
@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, ability):
|
||||
x = AbilityT()
|
||||
@@ -523,11 +547,15 @@ class StructOfStructsT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
structOfStructs = StructOfStructs()
|
||||
structOfStructs.Init(buf, pos+n)
|
||||
structOfStructs.Init(buf, pos)
|
||||
return cls.InitFromObj(structOfStructs)
|
||||
|
||||
@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, structOfStructs):
|
||||
x = StructOfStructsT()
|
||||
@@ -595,11 +623,15 @@ class StructOfStructsOfStructsT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
structOfStructsOfStructs = StructOfStructsOfStructs()
|
||||
structOfStructsOfStructs.Init(buf, pos+n)
|
||||
structOfStructsOfStructs.Init(buf, pos)
|
||||
return cls.InitFromObj(structOfStructsOfStructs)
|
||||
|
||||
@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, structOfStructsOfStructs):
|
||||
x = StructOfStructsOfStructsT()
|
||||
@@ -678,11 +710,15 @@ class StatT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
stat = Stat()
|
||||
stat.Init(buf, pos+n)
|
||||
stat.Init(buf, pos)
|
||||
return cls.InitFromObj(stat)
|
||||
|
||||
@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, stat):
|
||||
x = StatT()
|
||||
@@ -752,11 +788,15 @@ class ReferrableT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
referrable = Referrable()
|
||||
referrable.Init(buf, pos+n)
|
||||
referrable.Init(buf, pos)
|
||||
return cls.InitFromObj(referrable)
|
||||
|
||||
@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, referrable):
|
||||
x = ReferrableT()
|
||||
@@ -1726,11 +1766,15 @@ class MonsterT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
monster = Monster()
|
||||
monster.Init(buf, pos+n)
|
||||
monster.Init(buf, pos)
|
||||
return cls.InitFromObj(monster)
|
||||
|
||||
@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, monster):
|
||||
x = MonsterT()
|
||||
@@ -2364,11 +2408,15 @@ class TypeAliasesT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
typeAliases = TypeAliases()
|
||||
typeAliases.Init(buf, pos+n)
|
||||
typeAliases.Init(buf, pos)
|
||||
return cls.InitFromObj(typeAliases)
|
||||
|
||||
@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, typeAliases):
|
||||
x = TypeAliasesT()
|
||||
|
||||
Reference in New Issue
Block a user