mirror of
https://github.com/vee1e/flatbuffers.git
synced 2026-09-01 17:57:25 +00:00
MaxBufferSize() changed to MAX_BUFFER_SIZE. Also buffer will never grow more MAX_BUFFER_SIZE.
This commit is contained in:
parent
a1d801c375
commit
7bcbb19569
1 changed files with 10 additions and 9 deletions
|
|
@ -87,13 +87,20 @@ class Builder(object):
|
||||||
__slots__ = ("Bytes", "current_vtable", "head", "minalign", "objectEnd",
|
__slots__ = ("Bytes", "current_vtable", "head", "minalign", "objectEnd",
|
||||||
"vtables")
|
"vtables")
|
||||||
|
|
||||||
|
"""
|
||||||
|
Maximum buffer size constant, in bytes.
|
||||||
|
Builder will never allow it's buffer grow over this size.
|
||||||
|
Currently equals 2Gb.
|
||||||
|
"""
|
||||||
|
MAX_BUFFER_SIZE = 2**31
|
||||||
|
|
||||||
def __init__(self, initialSize):
|
def __init__(self, initialSize):
|
||||||
"""
|
"""
|
||||||
Initializes a Builder of size `initial_size`.
|
Initializes a Builder of size `initial_size`.
|
||||||
The internal buffer is grown as needed.
|
The internal buffer is grown as needed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not (0 <= initialSize <= self.MaxBufferSize()):
|
if not (0 <= initialSize <= Builder.MAX_BUFFER_SIZE):
|
||||||
msg = "flatbuffers: Cannot create Builder larger than 2 gigabytes."
|
msg = "flatbuffers: Cannot create Builder larger than 2 gigabytes."
|
||||||
raise BuilderSizeError(msg)
|
raise BuilderSizeError(msg)
|
||||||
|
|
||||||
|
|
@ -104,12 +111,6 @@ class Builder(object):
|
||||||
self.objectEnd = None
|
self.objectEnd = None
|
||||||
self.vtables = []
|
self.vtables = []
|
||||||
|
|
||||||
def MaxBufferSize(self):
|
|
||||||
"""
|
|
||||||
Maximum buffer size is 2Gb.
|
|
||||||
"""
|
|
||||||
return 2**31
|
|
||||||
|
|
||||||
def Output(self):
|
def Output(self):
|
||||||
"""
|
"""
|
||||||
Output returns the portion of the buffer that has been used for
|
Output returns the portion of the buffer that has been used for
|
||||||
|
|
@ -244,11 +245,11 @@ class Builder(object):
|
||||||
def growByteBuffer(self):
|
def growByteBuffer(self):
|
||||||
"""Doubles the size of the byteslice, and copies the old data towards
|
"""Doubles the size of the byteslice, and copies the old data towards
|
||||||
the end of the new buffer (since we build the buffer backwards)."""
|
the end of the new buffer (since we build the buffer backwards)."""
|
||||||
if not len(self.Bytes) <= self.MaxBufferSize():
|
if not len(self.Bytes) <= Builder.MAX_BUFFER_SIZE:
|
||||||
msg = "flatbuffers: cannot grow buffer beyond 2 gigabytes"
|
msg = "flatbuffers: cannot grow buffer beyond 2 gigabytes"
|
||||||
raise BuilderSizeError(msg)
|
raise BuilderSizeError(msg)
|
||||||
|
|
||||||
newSize = len(self.Bytes) * 2
|
newSize = min( len(self.Bytes) * 2, Builder.MAX_BUFFER_SIZE )
|
||||||
if newSize == 0:
|
if newSize == 0:
|
||||||
newSize = 1
|
newSize = 1
|
||||||
bytes2 = bytearray(newSize)
|
bytes2 = bytearray(newSize)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue