mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 04:21:13 +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:
@@ -123,11 +123,15 @@ class ArrayStructT(object):
|
||||
|
||||
@classmethod
|
||||
def InitFromBuf(cls, buf, pos):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)
|
||||
arrayStruct = ArrayStruct()
|
||||
arrayStruct.Init(buf, pos+n)
|
||||
arrayStruct.Init(buf, pos)
|
||||
return cls.InitFromObj(arrayStruct)
|
||||
|
||||
@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, arrayStruct):
|
||||
x = ArrayStructT()
|
||||
|
||||
Reference in New Issue
Block a user