forked from BigfootDev/flatbuffers
[Python] Improve python API (#8781)
* Fix generate_code script path * [Python] Make StartVector public Make StartVector vector public since it is already being used in generated code * [Python] Improve vector creation for Python API Makes Python API for vectors cleaner like Rust and Swift --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -422,7 +422,6 @@ class Builder(object):
|
||||
off2 = self.Offset() - off + N.UOffsetTFlags.bytewidth
|
||||
self.PlaceUOffsetT(off2)
|
||||
|
||||
## @cond FLATBUFFERS_INTERNAL
|
||||
def StartVector(self, elemSize, numElems, alignment):
|
||||
"""StartVector initializes bookkeeping for writing a new vector.
|
||||
|
||||
@@ -438,8 +437,6 @@ class Builder(object):
|
||||
self.Prep(alignment, elemSize * numElems) # In case alignment > int.
|
||||
return self.Offset()
|
||||
|
||||
## @endcond
|
||||
|
||||
def EndVector(self, numElems=None):
|
||||
"""EndVector writes data necessary to finish vector construction."""
|
||||
|
||||
@@ -556,6 +553,21 @@ class Builder(object):
|
||||
self.vectorNumElems = x.size
|
||||
return self.EndVector()
|
||||
|
||||
def CreateVectorOfTables(self, offsets):
|
||||
"""CreateVectorOfTables writes a vector of offsets such as tables or strings.
|
||||
|
||||
Args:
|
||||
offsets: Iterable of offsets returned from previous builder operations.
|
||||
Each element should be an integer compatible with UOffsetT.
|
||||
"""
|
||||
|
||||
offsets = list(offsets)
|
||||
self.StartVector(N.UOffsetTFlags.bytewidth, len(offsets),
|
||||
N.UOffsetTFlags.bytewidth)
|
||||
for off in reversed(offsets):
|
||||
self.PrependUOffsetTRelative(off)
|
||||
return self.EndVector()
|
||||
|
||||
## @cond FLATBUFFERS_INTERNAL
|
||||
def assertNested(self):
|
||||
"""Check that we are in the process of building an object."""
|
||||
|
||||
Reference in New Issue
Block a user