FlatBuffers
An open source project by FPL.
com.google.flatbuffers.FlatBufferBuilder Class Reference

Class that helps you build a FlatBuffer. More...

Detailed Description

Class that helps you build a FlatBuffer.

See the section "Use in Java/C#" in the main FlatBuffers documentation.

Public Member Functions

void addBoolean (boolean x)
 Add a boolean to the buffer, properly aligned, and grows the buffer (if necessary). More...
 
void addByte (byte x)
 Add a byte to the buffer, properly aligned, and grows the buffer (if necessary). More...
 
void addDouble (double x)
 Add a double to the buffer, properly aligned, and grows the buffer (if necessary). More...
 
void addFloat (float x)
 Add a float to the buffer, properly aligned, and grows the buffer (if necessary). More...
 
void addInt (int x)
 Add an int to the buffer, properly aligned, and grows the buffer (if necessary). More...
 
void addLong (long x)
 Add a long to the buffer, properly aligned, and grows the buffer (if necessary). More...
 
void addOffset (int off)
 Adds on offset, relative to where it will be written. More...
 
void addShort (short x)
 Add a short to the buffer, properly aligned, and grows the buffer (if necessary). More...
 
void clear ()
 Reset the FlatBufferBuilder by purging all data that it holds.
 
int createByteVector (byte[] arr)
 Create a byte array in the buffer. More...
 
int createString (CharSequence s)
 Encode the string s in the buffer using UTF-8. More...
 
int createString (ByteBuffer s)
 Create a string in the buffer from an already encoded UTF-8 string in a ByteBuffer. More...
 
ByteBuffer createUnintializedVector (int elem_size, int num_elems, int alignment)
 Create a new array/vector and return a ByteBuffer to be filled later. More...
 
int createVectorOfTables (int[] offsets)
 Create a vector of tables. More...
 
ByteBuffer dataBuffer ()
 Get the ByteBuffer representing the FlatBuffer. More...
 
void finish (int root_table)
 Finalize a buffer, pointing to the given root_table. More...
 
void finish (int root_table, String file_identifier)
 Finalize a buffer, pointing to the given root_table. More...
 
 FlatBufferBuilder (int initial_size)
 Start with a buffer of size initial_size, then grow as required. More...
 
 FlatBufferBuilder ()
 Start with a buffer of 1KiB, then grow as required.
 
 FlatBufferBuilder (ByteBuffer existing_bb)
 Alternative constructor allowing reuse of ByteBuffers. More...
 
FlatBufferBuilder forceDefaults (boolean forceDefaults)
 In order to save space, fields that are set to their default value don't get serialized into the buffer. More...
 
FlatBufferBuilder init (ByteBuffer existing_bb)
 Alternative initializer that allows reusing this object on an existing ByteBuffer. More...
 
byte[] sizedByteArray (int start, int length)
 A utility function to copy and return the ByteBuffer data from start to start + length as a byte[]. More...
 
byte[] sizedByteArray ()
 A utility function to copy and return the ByteBuffer data as a byte[]. More...
 

Constructor & Destructor Documentation

com.google.flatbuffers.FlatBufferBuilder.FlatBufferBuilder ( int  initial_size)
inline

Start with a buffer of size initial_size, then grow as required.

Parameters
initial_sizeThe initial size of the internal buffer to use.
com.google.flatbuffers.FlatBufferBuilder.FlatBufferBuilder ( ByteBuffer  existing_bb)
inline

Alternative constructor allowing reuse of ByteBuffers.

The builder can still grow the buffer as necessary. User classes should make sure to call dataBuffer() to obtain the resulting encoded message.

Parameters
existing_bbThe byte buffer to reuse.

Member Function Documentation

void com.google.flatbuffers.FlatBufferBuilder.addBoolean ( boolean  x)
inline

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

Parameters
xA boolean to put into the buffer.
void com.google.flatbuffers.FlatBufferBuilder.addByte ( byte  x)
inline

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

Parameters
xA byte to put into the buffer.
void com.google.flatbuffers.FlatBufferBuilder.addDouble ( double  x)
inline

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

Parameters
xA double to put into the buffer.
void com.google.flatbuffers.FlatBufferBuilder.addFloat ( float  x)
inline

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

Parameters
xA float to put into the buffer.
void com.google.flatbuffers.FlatBufferBuilder.addInt ( int  x)
inline

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

Parameters
xAn int to put into the buffer.
void com.google.flatbuffers.FlatBufferBuilder.addLong ( long  x)
inline

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

Parameters
xA long to put into the buffer.
void com.google.flatbuffers.FlatBufferBuilder.addOffset ( int  off)
inline

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

Parameters
offThe offset to add.
void com.google.flatbuffers.FlatBufferBuilder.addShort ( short  x)
inline

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

Parameters
xA short to put into the buffer.
int com.google.flatbuffers.FlatBufferBuilder.createByteVector ( byte[]  arr)
inline

Create a byte array in the buffer.

Parameters
arrA source array with data
Returns
The offset in the buffer where the encoded array starts.
int com.google.flatbuffers.FlatBufferBuilder.createString ( CharSequence  s)
inline

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

If

s

is already a CharBuffer, this method is allocation free.

Parameters
sThe string to encode.
Returns
The offset in the buffer where the encoded string starts.
int com.google.flatbuffers.FlatBufferBuilder.createString ( ByteBuffer  s)
inline

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

Parameters
sAn already encoded UTF-8 string as a ByteBuffer.
Returns
The offset in the buffer where the encoded string starts.
ByteBuffer com.google.flatbuffers.FlatBufferBuilder.createUnintializedVector ( int  elem_size,
int  num_elems,
int  alignment 
)
inline

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.

Parameters
elem_sizethe size of each element in bytes.
num_elemsnumber of elements in the vector.
alignmentbyte alignment.
Returns
ByteBuffer with position and limit set to the space allocated for the array.
int com.google.flatbuffers.FlatBufferBuilder.createVectorOfTables ( int[]  offsets)
inline

Create a vector of tables.

Parameters
offsetsOffsets of the tables.
Returns
Returns offset of the vector.
ByteBuffer com.google.flatbuffers.FlatBufferBuilder.dataBuffer ( )
inline

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.

Returns
The ByteBuffer representing the FlatBuffer
void com.google.flatbuffers.FlatBufferBuilder.finish ( int  root_table)
inline

Finalize a buffer, pointing to the given root_table.

Parameters
root_tableAn offset to be added to the buffer.
void com.google.flatbuffers.FlatBufferBuilder.finish ( int  root_table,
String  file_identifier 
)
inline

Finalize a buffer, pointing to the given root_table.

Parameters
root_tableAn offset to be added to the buffer.
file_identifierA FlatBuffer file identifier to be added to the buffer before root_table.
FlatBufferBuilder com.google.flatbuffers.FlatBufferBuilder.forceDefaults ( boolean  forceDefaults)
inline

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.

Parameters
forceDefaultsWhen set to true, always serializes default values.
Returns
Returns this.
FlatBufferBuilder com.google.flatbuffers.FlatBufferBuilder.init ( ByteBuffer  existing_bb)
inline

Alternative initializer that allows reusing this object on an existing ByteBuffer.

This method resets the builder's internal state, but keeps objects that have been allocated for temporary storage.

Parameters
existing_bbThe byte buffer to reuse.
Returns
Returns this.
byte [] com.google.flatbuffers.FlatBufferBuilder.sizedByteArray ( int  start,
int  length 
)
inline

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

Parameters
startStart copying at this offset.
lengthHow many bytes to copy.
Returns
A range copy of the data buffer.
Exceptions
IndexOutOfBoundsExceptionIf the range of bytes is ouf of bound.
byte [] com.google.flatbuffers.FlatBufferBuilder.sizedByteArray ( )
inline

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

Returns
A full copy of the data buffer.

The documentation for this class was generated from the following file: