public class FlexBuffersBuilder extends Object
This class presents all necessary APIs to create com.google.flatbuffers.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.
| Modifier and Type | Field and Description |
|---|---|
static int |
BUILDER_FLAG_NONE
No keys or strings will be shared
|
static int |
BUILDER_FLAG_SHARE_ALL
Reserved for the future.
|
static int |
BUILDER_FLAG_SHARE_KEY_VECTORS
Reserved for the future.
|
static int |
BUILDER_FLAG_SHARE_KEYS
Keys will be shared between elements.
|
static int |
BUILDER_FLAG_SHARE_KEYS_AND_STRINGS
Strings and keys will be shared between elements.
|
static int |
BUILDER_FLAG_SHARE_STRINGS
Strings will be shared between elements.
|
| Constructor and Description |
|---|
FlexBuffersBuilder()
Constructs a newly allocated
com.google.flatbuffers.FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS
set. |
FlexBuffersBuilder(ByteBuffer bb)
Constructs a newly allocated
com.google.flatbuffers.FlexBuffersBuilder. |
FlexBuffersBuilder(ByteBuffer bb,
int flags)
Deprecated.
|
FlexBuffersBuilder(int bufSize)
Constructs a newly allocated
com.google.flatbuffers.FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS
set. |
FlexBuffersBuilder(ReadWriteBuf bb,
int flags) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Reset the com.google.flatbuffers.FlexBuffersBuilder by purging all data that it holds.
|
int |
endMap(String key,
int start)
Finishes a map, but writing the information in the buffer
|
int |
endVector(String key,
int start,
boolean typed,
boolean fixed)
Finishes a vector, but writing the information in the buffer
|
ByteBuffer |
finish()
Finish writing the message into the buffer.
|
ReadWriteBuf |
getBuffer()
Return `ByteBuffer` containing FlexBuffer message.
|
int |
putBlob(byte[] value)
Adds a byte array into the message
|
int |
putBlob(String key,
byte[] val)
Adds a byte array into the message
|
void |
putBoolean(boolean val)
Insert a single boolean into the buffer
|
void |
putBoolean(String key,
boolean val)
Insert a single boolean into the buffer
|
void |
putFloat(double value)
Adds a 64-bit float into the buff.
|
void |
putFloat(float value)
Adds a 32-bit float into the buff.
|
void |
putFloat(String key,
double val)
Adds a 64-bit float into the buff.
|
void |
putFloat(String key,
float val)
Adds a 32-bit float into the buff.
|
void |
putInt(int val)
Adds an integer into the buff
|
void |
putInt(long value)
Adds a 64-bit integer into the buff
|
void |
putInt(String key,
int val)
Adds a integer into the buff
|
void |
putInt(String key,
long val)
Adds a integer into the buff
|
void |
putNull()
Insert a null value into the buffer
|
void |
putNull(String key)
Insert a null value into the buffer
|
int |
putString(String value)
Adds a String into the buffer
|
int |
putString(String key,
String val)
Adds a String into the buffer
|
void |
putUInt(int value)
Adds a unsigned integer into the buff.
|
void |
putUInt(long value)
Adds a unsigned integer (stored in a signed 64-bit integer) into the buff.
|
void |
putUInt64(BigInteger value)
Adds a 64-bit unsigned integer (stored as
BigInteger) into the buff. |
int |
startMap()
Start a new map in the buffer.
|
int |
startVector()
Start a new vector in the buffer.
|
public static final int BUILDER_FLAG_NONE
public static final int BUILDER_FLAG_SHARE_ALL
public static final int BUILDER_FLAG_SHARE_KEY_VECTORS
public static final int BUILDER_FLAG_SHARE_KEYS
public static final int BUILDER_FLAG_SHARE_KEYS_AND_STRINGS
public static final int BUILDER_FLAG_SHARE_STRINGS
public FlexBuffersBuilder()
com.google.flatbuffers.FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS
set.public FlexBuffersBuilder(ByteBuffer bb)
com.google.flatbuffers.FlexBuffersBuilder. By default same keys will be
serialized only oncebb - `ByteBuffer` that will hold the message@Deprecated public FlexBuffersBuilder(ByteBuffer bb, int flags)
com.google.flatbuffers.FlexBuffersBuilder.bb - `ByteBuffer` that will hold the messageflags - Share flagspublic FlexBuffersBuilder(int bufSize)
com.google.flatbuffers.FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS
set.bufSize - size of buffer in bytes.public FlexBuffersBuilder(ReadWriteBuf bb, int flags)
public void clear()
public int endMap(String key, int start)
key - key used to store element in mapstart - reference for beginning of the map. Returned by {link startMap()}public int endVector(String key, int start, boolean typed, boolean fixed)
key - key used to store element in mapstart - reference for beginning of the vector. Returned by {link startVector()}typed - boolean indicating whether vector is typedfixed - boolean indicating whether vector is fixedpublic ByteBuffer finish()
public ReadWriteBuf getBuffer()
#finish() must be called before
calling this function otherwise an assert will trigger.public int putBlob(byte[] value)
value - byte arraypublic int putBlob(String key, byte[] val)
key - key used to store element in mapval - byte arraypublic void putBoolean(boolean val)
val - true or falsepublic void putBoolean(String key, boolean val)
key - key used to store element in mapval - true or falsepublic void putFloat(double value)
value - float representing valuepublic void putFloat(float value)
value - float representing valuepublic void putFloat(String key, double val)
key - key used to store element in mapval - float representing valuepublic void putFloat(String key, float val)
key - key used to store element in mapval - float representing valuepublic void putInt(int val)
val - integerpublic void putInt(long value)
value - integerpublic void putInt(String key, int val)
key - key used to store element in mapval - integerpublic void putInt(String key, long val)
key - key used to store element in mapval - 64-bit integerpublic void putNull()
public void putNull(String key)
key - key used to store element in mappublic int putString(String value)
value - stringpublic int putString(String key, String val)
key - key used to store element in mapval - stringpublic void putUInt(int value)
value - integer representing unsigned valuepublic void putUInt(long value)
value - integer representing unsigned valuepublic void putUInt64(BigInteger value)
BigInteger) into the buff. Warning: This
operation might be very slow.value - integer representing unsigned valuepublic int startMap()
public int startVector()