public class FlexBuffersBuilder extends Object
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.
| 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
FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS set. |
FlexBuffersBuilder(ByteBuffer bb)
Constructs a newly allocated
FlexBuffersBuilder. |
FlexBuffersBuilder(ByteBuffer bb,
int flags)
Deprecated.
|
FlexBuffersBuilder(int bufSize)
Constructs a newly allocated
FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS set. |
FlexBuffersBuilder(com.google.flatbuffers.ReadWriteBuf bb,
int flags) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
com.google.flatbuffers.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 a 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
|
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_KEYS
public static final int BUILDER_FLAG_SHARE_STRINGS
public static final int BUILDER_FLAG_SHARE_KEYS_AND_STRINGS
public static final int BUILDER_FLAG_SHARE_KEY_VECTORS
public static final int BUILDER_FLAG_SHARE_ALL
public FlexBuffersBuilder(int bufSize)
FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS set.bufSize - size of buffer in bytes.public FlexBuffersBuilder()
FlexBuffersBuilder with BUILDER_FLAG_SHARE_KEYS set.@Deprecated public FlexBuffersBuilder(ByteBuffer bb, int flags)
FlexBuffersBuilder.bb - `ByteBuffer` that will hold the messageflags - Share flagspublic FlexBuffersBuilder(com.google.flatbuffers.ReadWriteBuf bb,
int flags)
public FlexBuffersBuilder(ByteBuffer bb)
FlexBuffersBuilder.
By default same keys will be serialized only oncebb - `ByteBuffer` that will hold the messagepublic com.google.flatbuffers.ReadWriteBuf getBuffer()
#finish() must be called before calling this
function otherwise an assert will trigger.public 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 putInt(int val)
val - 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 putInt(long value)
value - integerpublic 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 void putFloat(float value)
value - float representing valuepublic void putFloat(String key, float val)
key - key used to store element in mapvalue - float representing valuepublic void putFloat(double value)
value - float representing valuepublic void putFloat(String key, double val)
key - key used to store element in mapvalue - float representing valuepublic int putString(String value)
value - stringpublic int putString(String key, String val)
key - key used to store element in mapvalue - stringpublic int putBlob(byte[] value)
value - byte arraypublic int putBlob(String key, byte[] val)
key - key used to store element in mapvalue - byte arraypublic int startVector()
public int endVector(String key, int start, boolean typed, boolean fixed)
key - key used to store element in mapstart - reference for begining of the vector. Returned by startVector()typed - boolean indicating wether vector is typedfixed - boolean indicating wether vector is fixedpublic ByteBuffer finish()
public int startMap()
public int endMap(String key, int start)
key - key used to store element in mapstart - reference for begining of the map. Returned by startMap()Copyright © 2020. All rights reserved.