mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 14:27:05 +00:00
[Lobster] file_identifier support
This commit is contained in:
@@ -175,25 +175,30 @@ class builder:
|
||||
while current_vtable.length <= slotnum: current_vtable.push(0)
|
||||
current_vtable[slotnum] = head
|
||||
|
||||
def __Finish(root_table:offset, size_prefix:int):
|
||||
def __Finish(root_table:offset, size_prefix:int, file_identifier:string?):
|
||||
// Finish finalizes a buffer, pointing to the given root_table
|
||||
assert not finished
|
||||
assert not nested
|
||||
var prep_size = sz_32
|
||||
if file_identifier:
|
||||
prep_size += sz_32
|
||||
if size_prefix:
|
||||
prep_size += sz_32
|
||||
Prep(minalign, prep_size)
|
||||
if file_identifier:
|
||||
assert file_identifier.length == 4
|
||||
buf, head = buf.write_substring_back(head, file_identifier, false)
|
||||
PrependUOffsetTRelative(root_table)
|
||||
if size_prefix:
|
||||
PrependInt32(head)
|
||||
finished = true
|
||||
return Start()
|
||||
|
||||
def Finish(root_table:offset):
|
||||
return __Finish(root_table, false)
|
||||
def Finish(root_table:offset, file_identifier:string? = nil):
|
||||
return __Finish(root_table, false, file_identifier)
|
||||
|
||||
def FinishSizePrefixed(root_table:offset):
|
||||
return __Finish(root_table, true)
|
||||
def FinishSizePrefixed(root_table:offset, file_identifier:string? = nil):
|
||||
return __Finish(root_table, true, file_identifier)
|
||||
|
||||
def PrependBool(x):
|
||||
buf, head = buf.write_int8_le_back(head, x)
|
||||
@@ -299,3 +304,9 @@ class builder:
|
||||
// elsewhere.
|
||||
assert x.o == head
|
||||
Slot(v)
|
||||
|
||||
def has_identifier(buf:string, file_identifier:string):
|
||||
assert file_identifier.length == 4
|
||||
return buf.length >= 8 and buf.substring(4, 4) == file_identifier
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user