self.minalign = 1
self.currentVTable = nil
self.objectEnd = nil
- self.head = #self.bytes -- place the head at the end of the binary array
+ self.head = self.bytes.size -- place the head at the end of the binary array
-- clear vtables instead of making a new table
local vtable = self.vtables
while i >= 1 do
local vt2Offset = self.vtables[i]
- local vt2Start = #self.bytes - vt2Offset
+ local vt2Start = self.bytes.size - vt2Offset
local vt2lenstr = self.bytes:Slice(vt2Start, vt2Start+1)
local vt2Len = string_unpack(VOffsetT.packFmt, vt2lenstr, 1)
vBytes = vBytes * 2
self:PrependVOffsetT(vBytes)
- local objectStart = #self.bytes - objectOffset
+ local objectStart = self.bytes.size - objectOffset
self.bytes:Set(SOffsetT:Pack(self:Offset() - objectOffset),objectStart)
table.insert(self.vtables, self:Offset())
else
- local objectStart = #self.bytes - objectOffset
+ local objectStart = self.bytes.size - objectOffset
self.head = objectStart
self.bytes:Set(SOffsetT:Pack(exisitingVTable - objectOffset),self.head)
end
end
local function growByteBuffer(self, desiredSize)
- local s = #self.bytes
+ local s = self.bytes.size
assert(s < MAX_BUFFER_SIZE, "Flat Buffers cannot grow buffer beyond 2 gigabytes")
local newsize = s
repeat
end
function mt:Offset()
- return #self.bytes - self.head
+ return self.bytes.size - self.head
end
function mt:Pad(n)
local h = self.head
- local k = #self.bytes - h + additionalBytes
+ local k = self.bytes.size - h + additionalBytes
local alignsize = getAlignSize(k, size)
local desiredSize = alignsize + size + additionalBytes
while self.head < desiredSize do
- local oldBufSize = #self.bytes
+ local oldBufSize = self.bytes.size
growByteBuffer(self, desiredSize)
- local updatedHead = self.head + #self.bytes - oldBufSize
+ local updatedHead = self.head + self.bytes.size - oldBufSize
self.head = updatedHead
end
self:Prep(self.minalign, sizePrefix and 8 or 4)
self:PrependUOffsetTRelative(rootTable)
if sizePrefix then
- local size = #self.bytes - self.head
+ local size = self.bytes.size - self.head
Int32:EnforceNumber(size)
self:PrependInt32(size)
end
package.path = string.format("../lua/?.lua;./?.lua;%s",package.path)
+local compat = require("flatbuffers.compat")
local performBenchmarkTests = false
if sizePrefix then
local size = flatbuffers.N.Int32:Unpack(buf, offset)
- assert(size == #buf - offset - 4)
+ assert(size == buf.size - offset - 4)
offset = offset + flatbuffers.N.Int32.bytewidth
end