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

Helper class that builds FlexBuffers. More...

Detailed Description

Helper class that builds FlexBuffers.

This class presents all necessary APIs to create FlexBuffers. A ByteBuffer will be used to store the data. It can be created internally, or passed down in the constructor.

There are some limitations when compared to original implementation in C++. Most notably:

  • No support for mutations (might change in the future).

  • Buffer size limited to Integer#MAX_VALUE

  • Since Java does not support unsigned type, all unsigned operations accepts an immediate higher representation of similar type.

Public Member Functions

void clear ()
 Reset the FlexBuffersBuilder by purging all data that it holds.
 
int endMap (String key, int start)
 Finishes a map, but writing the information in the buffer. More...
 
int endVector (String key, int start, boolean typed, boolean fixed)
 Finishes a vector, but writing the information in the buffer. More...
 
ByteBuffer finish ()
 Finish writing the message into the buffer. More...
 
 FlexBuffersBuilder ()
 Constructs a newly allocated. More...
 
 FlexBuffersBuilder (ByteBuffer bb)
 Constructs a newly allocated. More...
 
 FlexBuffersBuilder (ByteBuffer bb, int flags)
 Constructs a newly allocated. More...
 
 FlexBuffersBuilder (int bufSize)
 Constructs a newly allocated. More...
 
 FlexBuffersBuilder (ReadWriteBuf bb, int flags)
 
ReadWriteBuf getBuffer ()
 Return ByteBuffer containing FlexBuffer message. More...
 
int putBlob (byte[] value)
 Adds a byte array into the message. More...
 
int putBlob (String key, byte[] val)
 Adds a byte array into the message. More...
 
void putBoolean (boolean val)
 Insert a single boolean into the buffer. More...
 
void putBoolean (String key, boolean val)
 Insert a single boolean into the buffer. More...
 
void putFloat (double value)
 Adds a 64-bit float into the buff. More...
 
void putFloat (float value)
 Adds a 32-bit float into the buff. More...
 
void putFloat (String key, double val)
 Adds a 64-bit float into the buff. More...
 
void putFloat (String key, float val)
 Adds a 32-bit float into the buff. More...
 
void putInt (int val)
 Adds a integer into the buff. More...
 
void putInt (long value)
 Adds a 64-bit integer into the buff. More...
 
void putInt (String key, int val)
 Adds a integer into the buff. More...
 
void putInt (String key, long val)
 Adds a integer into the buff. More...
 
int putString (String key, String val)
 Adds a String into the buffer. More...
 
int putString (String value)
 Adds a String into the buffer. More...
 
void putUInt (int value)
 Adds a unsigned integer into the buff. More...
 
void putUInt (long value)
 Adds a unsigned integer (stored in a signed 64-bit integer) into the buff. More...
 
void putUInt64 (BigInteger value)
 Adds a 64-bit unsigned integer (stored as BigInteger) into the buff. More...
 
int startMap ()
 Start a new map in the buffer. More...
 
int startVector ()
 Start a new vector in the buffer. More...
 

Static Public Attributes

static final int BUILDER_FLAG_NONE = 0
 No keys or strings will be shared.
 
static final int BUILDER_FLAG_SHARE_ALL = 7
 Reserved for the future.
 
static final int BUILDER_FLAG_SHARE_KEY_VECTORS = 4
 Reserved for the future.
 
static final int BUILDER_FLAG_SHARE_KEYS = 1
 Keys will be shared between elements. More...
 
static final int BUILDER_FLAG_SHARE_KEYS_AND_STRINGS = 3
 Strings and keys will be shared between elements.
 
static final int BUILDER_FLAG_SHARE_STRINGS = 2
 Strings will be shared between elements. More...
 

Constructor & Destructor Documentation

◆ FlexBuffersBuilder() [1/4]

com.google.flatbuffers.FlexBuffersBuilder.FlexBuffersBuilder ( int  bufSize)
inline

Constructs a newly allocated.

FlexBuffersBuilder()
Constructs a newly allocated.
Definition: FlexBuffersBuilder.java:125

with BUILDER_FLAG_SHARE_KEYS set.

Parameters
bufSizesize of buffer in bytes.

◆ FlexBuffersBuilder() [2/4]

com.google.flatbuffers.FlexBuffersBuilder.FlexBuffersBuilder ( )
inline

Constructs a newly allocated.

with BUILDER_FLAG_SHARE_KEYS set.

◆ FlexBuffersBuilder() [3/4]

com.google.flatbuffers.FlexBuffersBuilder.FlexBuffersBuilder ( ByteBuffer  bb,
int  flags 
)
inline

Constructs a newly allocated.

.

Parameters
bbByteBuffer that will hold the message
flagsShare flags

◆ FlexBuffersBuilder() [4/4]

com.google.flatbuffers.FlexBuffersBuilder.FlexBuffersBuilder ( ByteBuffer  bb)
inline

Constructs a newly allocated.

. By default same keys will be serialized only once

Parameters
bbByteBuffer that will hold the message

Member Function Documentation

◆ endMap()

int com.google.flatbuffers.FlexBuffersBuilder.endMap ( String  key,
int  start 
)
inline

Finishes a map, but writing the information in the buffer.

Parameters
keykey used to store element in map
startreference for begining of the map. Returned by startMap()
Returns
Reference to the map

◆ endVector()

int com.google.flatbuffers.FlexBuffersBuilder.endVector ( String  key,
int  start,
boolean  typed,
boolean  fixed 
)
inline

Finishes a vector, but writing the information in the buffer.

Parameters
keykey used to store element in map
startreference for begining of the vector. Returned by startVector()
typedboolean indicating whether vector is typed
fixedboolean indicating whether vector is fixed
Returns
Reference to the vector

◆ finish()

ByteBuffer com.google.flatbuffers.FlexBuffersBuilder.finish ( )
inline

Finish writing the message into the buffer.

After that no other element must be inserted into the buffer. Also, you must call this function before start using the FlexBuffer message

Returns
ByteBuffer containing the FlexBuffer message

◆ getBuffer()

ReadWriteBuf com.google.flatbuffers.FlexBuffersBuilder.getBuffer ( )
inline

Return ByteBuffer containing FlexBuffer message.

#finish()

must be called before calling this function otherwise an assert will trigger.

Returns
ByteBuffer with finished message

◆ putBlob() [1/2]

int com.google.flatbuffers.FlexBuffersBuilder.putBlob ( byte[]  value)
inline

Adds a byte array into the message.

Parameters
valuebyte array
Returns
position in buffer as the start of byte array

◆ putBlob() [2/2]

int com.google.flatbuffers.FlexBuffersBuilder.putBlob ( String  key,
byte[]  val 
)
inline

Adds a byte array into the message.

Parameters
keykey used to store element in map
valuebyte array
Returns
position in buffer as the start of byte array

◆ putBoolean() [1/2]

void com.google.flatbuffers.FlexBuffersBuilder.putBoolean ( boolean  val)
inline

Insert a single boolean into the buffer.

Parameters
valtrue or false

◆ putBoolean() [2/2]

void com.google.flatbuffers.FlexBuffersBuilder.putBoolean ( String  key,
boolean  val 
)
inline

Insert a single boolean into the buffer.

Parameters
keykey used to store element in map
valtrue or false

◆ putFloat() [1/4]

void com.google.flatbuffers.FlexBuffersBuilder.putFloat ( double  value)
inline

Adds a 64-bit float into the buff.

Parameters
valuefloat representing value

◆ putFloat() [2/4]

void com.google.flatbuffers.FlexBuffersBuilder.putFloat ( float  value)
inline

Adds a 32-bit float into the buff.

Parameters
valuefloat representing value

◆ putFloat() [3/4]

void com.google.flatbuffers.FlexBuffersBuilder.putFloat ( String  key,
double  val 
)
inline

Adds a 64-bit float into the buff.

Parameters
keykey used to store element in map
valuefloat representing value

◆ putFloat() [4/4]

void com.google.flatbuffers.FlexBuffersBuilder.putFloat ( String  key,
float  val 
)
inline

Adds a 32-bit float into the buff.

Parameters
keykey used to store element in map
valuefloat representing value

◆ putInt() [1/4]

void com.google.flatbuffers.FlexBuffersBuilder.putInt ( int  val)
inline

Adds a integer into the buff.

Parameters
valinteger

◆ putInt() [2/4]

void com.google.flatbuffers.FlexBuffersBuilder.putInt ( long  value)
inline

Adds a 64-bit integer into the buff.

Parameters
valueinteger

◆ putInt() [3/4]

void com.google.flatbuffers.FlexBuffersBuilder.putInt ( String  key,
int  val 
)
inline

Adds a integer into the buff.

Parameters
keykey used to store element in map
valinteger

◆ putInt() [4/4]

void com.google.flatbuffers.FlexBuffersBuilder.putInt ( String  key,
long  val 
)
inline

Adds a integer into the buff.

Parameters
keykey used to store element in map
val64-bit integer

◆ putString() [1/2]

int com.google.flatbuffers.FlexBuffersBuilder.putString ( String  key,
String  val 
)
inline

Adds a String into the buffer.

Parameters
keykey used to store element in map
valuestring
Returns
start position of string in the buffer

◆ putString() [2/2]

int com.google.flatbuffers.FlexBuffersBuilder.putString ( String  value)
inline

Adds a String into the buffer.

Parameters
valuestring
Returns
start position of string in the buffer

◆ putUInt() [1/2]

void com.google.flatbuffers.FlexBuffersBuilder.putUInt ( int  value)
inline

Adds a unsigned integer into the buff.

Parameters
valueinteger representing unsigned value

◆ putUInt() [2/2]

void com.google.flatbuffers.FlexBuffersBuilder.putUInt ( long  value)
inline

Adds a unsigned integer (stored in a signed 64-bit integer) into the buff.

Parameters
valueinteger representing unsigned value

◆ putUInt64()

void com.google.flatbuffers.FlexBuffersBuilder.putUInt64 ( BigInteger  value)
inline

Adds a 64-bit unsigned integer (stored as BigInteger) into the buff.

Warning: This operation might be very slow.

Parameters
valueinteger representing unsigned value

◆ startMap()

int com.google.flatbuffers.FlexBuffersBuilder.startMap ( )
inline

Start a new map in the buffer.

Returns
a reference indicating position of the map in buffer. This reference must be passed along when the map is finished using endMap()

◆ startVector()

int com.google.flatbuffers.FlexBuffersBuilder.startVector ( )
inline

Start a new vector in the buffer.

Returns
a reference indicating position of the vector in buffer. This reference must be passed along when the vector is finished using endVector()

Member Data Documentation

◆ BUILDER_FLAG_SHARE_KEYS

final int com.google.flatbuffers.FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS = 1
static

Keys will be shared between elements.

Identical keys will only be serialized once, thus possibly saving space. But serialization performance might be slower and consumes more memory.

◆ BUILDER_FLAG_SHARE_STRINGS

final int com.google.flatbuffers.FlexBuffersBuilder.BUILDER_FLAG_SHARE_STRINGS = 2
static

Strings will be shared between elements.

Identical strings will only be serialized once, thus possibly saving space. But serialization performance might be slower and consumes more memory. This is ideal if you expect many repeated strings on the message.


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