finished bool
}
+const fileIdentifierLength = 4
+
// NewBuilder initializes a Builder of size `initial_size`.
// The internal buffer is grown as needed.
func NewBuilder(initialSize int) *Builder {
existingVtable := UOffsetT(0)
// Trim vtable of trailing zeroes.
- i := len(b.vtable) - 1;
- for ; i >= 0 && b.vtable[i] == 0; i-- {}
- b.vtable = b.vtable[:i + 1];
+ i := len(b.vtable) - 1
+ for ; i >= 0 && b.vtable[i] == 0; i-- {
+ }
+ b.vtable = b.vtable[:i+1]
// Search backwards through existing vtables, because similar vtables
// are likely to have been recently appended. See
b.vtable[slotnum] = UOffsetT(b.Offset())
}
+// FinishWithFileIdentifier finalizes a buffer, pointing to the given `rootTable`.
+// as well as applys a file identifier
+func (b *Builder) FinishWithFileIdentifier(rootTable UOffsetT, fid []byte) {
+ if fid == nil || len(fid) != fileIdentifierLength {
+ panic("incorrect file identifier length")
+ }
+ // In order to add a file identifier to the flatbuffer message, we need
+ // to prepare an alignment and file identifier length
+ b.Prep(b.minalign, SizeInt32+fileIdentifierLength)
+ for i := fileIdentifierLength - 1; i >= 0; i-- {
+ // place the file identifier
+ b.PlaceByte(fid[i])
+ }
+ // finish
+ b.Finish(rootTable)
+}
+
// Finish finalizes a buffer, pointing to the given `rootTable`.
func (b *Builder) Finish(rootTable UOffsetT) {
b.assertNotNested()