FlatBufferBuilder

class FlatBufferBuilder @JvmOverloads constructor(initialSize: Int = 1024, buffer: ReadWriteBuffer = ArrayReadWriteBuffer(initialSize))

Class that helps you build a FlatBuffer. See the section "Use in Kotlin" in the main FlatBuffers documentation.

Constructors

Link copied to clipboard
constructor(initialSize: Int = 1024, buffer: ReadWriteBuffer = ArrayReadWriteBuffer(initialSize))

Functions

Link copied to clipboard
fun add(off: Offset<*>)

Adds on offset, relative to where it will be written.

fun add(off: VectorOffset<*>)
fun add(o: Int, x: VectorOffset<*>, d: Int)
fun add(o: Int, x: Boolean, d: Boolean)
fun add(o: Int, x: Byte, d: Byte)
fun add(o: Int, x: Double, d: Double)
fun add(o: Int, x: Float, d: Float)
fun add(o: Int, x: Int, d: Int)
fun add(o: Int, x: Long, d: Long)
fun add(o: Int, x: Short, d: Short)
fun add(o: Int, x: UByte, d: UByte)
fun add(o: Int, x: UInt, d: UInt)
fun add(o: Int, x: ULong, d: ULong)
fun add(o: Int, x: UShort, d: UShort)

fun add(x: Boolean)

Add a Boolean to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: Byte)

Add a Byte to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: Double)

Add a Double to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: Float)

Add a Float to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: Int)

Add an Int to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: Long)

Add a long to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: Short)

Add a Short to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: UByte)

Add a UByte to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: UInt)

Add an Unit to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: ULong)

Add a ULong to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(x: UShort)

Add a UShort to the buffer, properly aligned, and grows the buffer (if necessary).

fun add(o: Int, x: Offset<*>, d: Int)

Add an offset to a table at o into its vtable, with value x and default d.

fun add(o: Int, x: Boolean, d: Boolean?)

Add a Boolean to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: Byte, d: Byte?)

Add a Byte to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: Double, d: Double?)

Add a Double to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: Float, d: Float?)

Add a Float to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: Int, d: Int?)

Add a Int to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: Long, d: Long?)

Add a Long to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: Short, d: Short?)

Add a Short to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: UByte, d: UByte?)

Add a UByte to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: UInt, d: UInt?)

Add a UInt to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: ULong, d: ULong?)

Add a ULong to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

fun add(o: Int, x: UShort, d: UShort?)

Add a UShort to a table at o into its vtable, with value x and default d. If force_defaults is false, compare x against the default value d. If x contains the default value, it can be skipped.

Link copied to clipboard
fun addStruct(vOffset: Int, x: Offset<*>, d: Offset<*>)
fun addStruct(vOffset: Int, x: Int, d: Int)
fun addStruct(vOffset: Int, x: Int, d: Int?)

fun addStruct(vOffset: Int, x: Offset<*>, d: Offset<*>?)

Add a struct to the table. Structs are stored inline, so nothing additional is being added.

Link copied to clipboard
fun clear()

Reset the FlatBufferBuilder by purging all data that it holds.

Link copied to clipboard
fun createByteVector(data: ReadBuffer, from: Int = 0, until: Int = data.limit): VectorOffset<Byte>
fun createByteVector(arr: ByteArray, offset: Int, length: Int): VectorOffset<Byte>

Create a byte array in the buffer.

Link copied to clipboard

Encode the String s in the buffer using UTF-8. If a String with this exact contents has already been serialized using this method, instead simply returns the offset of the existing String.

Link copied to clipboard

Create a vector of sorted by the key tables.

Link copied to clipboard

Create a string in the buffer from an already encoded UTF-8 string in a ByteBuffer.

Encode the CharSequence s in the buffer using UTF-8.

Link copied to clipboard
fun createUnintializedVector(elemSize: Int, numElems: Int, alignment: Int): ReadWriteBuffer

Create a new array/vector and return a ByteBuffer to be filled later. Call endVector after this method to get an offset to the beginning of vector.

Link copied to clipboard

Create a vector of tables.

Link copied to clipboard

Get the ByteBuffer representing the FlatBuffer. Only call this after you've called finish(). The actual data starts at the ByteBuffer's current position, not necessarily at 0.

Link copied to clipboard
Link copied to clipboard
fun <T> endTable(): Offset<T>

Finish off writing the object that is under construction.

Link copied to clipboard

Finish off the creation of an array and all its elements. The array must be created with .startVector.

Link copied to clipboard
fun finish(rootTable: Offset<*>)
fun finish(rootTable: Offset<*>, fileIdentifier: String)

Finalize a buffer, pointing to the given root_table.

Link copied to clipboard
fun finished()

Should not be accessing the final buffer before it is finished.

Link copied to clipboard
fun finishSizePrefixed(rootTable: Offset<*>)
fun finishSizePrefixed(rootTable: Offset<*>, fileIdentifier: String)

Finalize a buffer, pointing to the given root_table, with the size prefixed.

Link copied to clipboard

In order to save space, fields that are set to their default value don't get serialized into the buffer. Forcing defaults provides a way to manually disable this optimization.

Link copied to clipboard

Helper function to test if a field is present in the table

Link copied to clipboard
fun nested(obj: Int)

Structures are always stored inline, they need to be created right where they're used. You'll get this assertion failure if you created it elsewhere.

Link copied to clipboard
fun notNested()

Should not be creating any other object, string or vector while an object is being constructed.

Link copied to clipboard
fun offset(): Int

Offset relative to the end of the buffer.

Link copied to clipboard
fun pad(byteSize: Int)

Add zero valued bytes to prepare a new entry to be added.

Link copied to clipboard
fun prep(size: Int, additionalBytes: Int)

Prepare to write an element of size after additional_bytes have been written, e.g. if you write a string, you need to align such the int length field is aligned to com.google.flatbuffers.Int.SIZE_BYTES, and the string data follows it directly. If all you need to do is alignment, additional_bytes will be 0.

Link copied to clipboard
fun put(x: Boolean)

Add a boolean to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: Byte)

Add a Byte to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: Double)

Add a Double to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: Float)

Add a Float to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: Int)

Add an Int to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: Long)

Add a Long to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: Short)

Add a Short to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: UByte)

Add a UByte to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: UInt)

Add an UInt to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: ULong)

Add a ULong to the buffer, backwards from the current location. Doesn't align nor check for space.

fun put(x: UShort)

Add a UShort to the buffer, backwards from the current location. Doesn't align nor check for space.

Link copied to clipboard
fun required(table: Offset<*>, field: Int, fileName: String? = null)

Checks that a required field has been set in a given table that has just been constructed.

Link copied to clipboard
fun sizedByteArray(start: Int = space, length: Int = buffer.capacity - space): ByteArray

A utility function to copy and return the ByteBuffer data as a byte[].

Link copied to clipboard
fun slot(vOffset: Int)

Set the current vtable at voffset to the current location in the buffer.

Link copied to clipboard
fun startString(numElems: Int)
Link copied to clipboard
fun startTable(numFields: Int)

Start encoding a new object in the buffer. Users will not usually need to call this directly. The FlatBuffers compiler will generate helper methods that call this method internally.

Link copied to clipboard
fun startVector(elemSize: Int, numElems: Int, alignment: Int)

Start a new array/vector of objects. Users usually will not call this directly. The FlatBuffers compiler will create a start/end method for vector types in generated code.