Package io.objectbox.flatbuffers
Class ArrayReadWriteBuf
java.lang.Object
io.objectbox.flatbuffers.ArrayReadWriteBuf
- All Implemented Interfaces:
ReadBuf,ReadWriteBuf
Implements
ReadBuf using an array of bytes
as a backing storage. Using array of bytes are
usually faster than ByteBuffer.
This class is not thread-safe, meaning that
it must operate on a single thread. Operating from
multiple thread leads into a undefined behavior-
Constructor Summary
ConstructorsConstructorDescriptionArrayReadWriteBuf(byte[] buffer) ArrayReadWriteBuf(byte[] buffer, int startPos) ArrayReadWriteBuf(int initialCapacity) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears (resets) the buffer so that it can be reused.byte[]data()Expose ReadBuf as an array of bytes.byteget(int index) Read a byte from data.booleangetBoolean(int index) Read boolean from data.doublegetDouble(int index) Read a 64-bit float from data.floatgetFloat(int index) Read a 32-bit float from data.intgetInt(int index) Read a 32-bit int from data.longgetLong(int index) Read a 64-bit long from data.shortgetShort(int index) Read a short from data.getString(int start, int size) Read an UTF-8 string from data.intlimit()Defines the size of the message in the buffer.voidput(byte value) Write a byte into the buffer atwritePosition().voidput(byte[] value, int start, int length) Put an array of bytes into the buffer atwritePosition().voidputBoolean(boolean value) Put a boolean into the buffer atwritePosition().voidputDouble(double value) Write a 64-bit float into the buffer atwritePosition().voidputFloat(float value) Write a 32-bit float into the buffer atwritePosition().voidputInt(int value) Write a 32-bit into in the buffer atwritePosition().voidputLong(long value) Write a 64-bit into in the buffer atwritePosition().voidputShort(short value) Write a 16-bit into in the buffer atwritePosition().booleanrequestCapacity(int capacity) Request capacity of the buffer.voidset(int index, byte value) Read a byte from data.voidset(int index, byte[] toCopy, int start, int length) Write an array of bytes into the buffer.voidsetBoolean(int index, boolean value) Write boolean into a given position on the buffer.voidsetDouble(int index, double value) Read a 64-bit float from data.voidsetFloat(int index, float value) Read a 32-bit float from data.voidsetInt(int index, int value) Read a 32-bit int from data.voidsetLong(int index, long value) Read a 64-bit long from data.voidsetShort(int index, short value) Read a short from data.int
-
Constructor Details
-
ArrayReadWriteBuf
public ArrayReadWriteBuf() -
ArrayReadWriteBuf
public ArrayReadWriteBuf(int initialCapacity) -
ArrayReadWriteBuf
public ArrayReadWriteBuf(byte[] buffer) -
ArrayReadWriteBuf
public ArrayReadWriteBuf(byte[] buffer, int startPos)
-
-
Method Details
-
clear
public void clear()Description copied from interface:ReadWriteBufClears (resets) the buffer so that it can be reused. Write position will be set to the start.- Specified by:
clearin interfaceReadWriteBuf
-
getBoolean
public boolean getBoolean(int index) Description copied from interface:ReadBufRead boolean from data. Booleans as stored as single byte- Specified by:
getBooleanin interfaceReadBuf- Parameters:
index- position of the element in ReadBuf- Returns:
- boolean element
-
get
public byte get(int index) Description copied from interface:ReadBufRead a byte from data. -
getShort
public short getShort(int index) Description copied from interface:ReadBufRead a short from data. -
getInt
public int getInt(int index) Description copied from interface:ReadBufRead a 32-bit int from data. -
getLong
public long getLong(int index) Description copied from interface:ReadBufRead a 64-bit long from data. -
getFloat
public float getFloat(int index) Description copied from interface:ReadBufRead a 32-bit float from data. -
getDouble
public double getDouble(int index) Description copied from interface:ReadBufRead a 64-bit float from data. -
getString
Description copied from interface:ReadBufRead an UTF-8 string from data. -
data
public byte[] data()Description copied from interface:ReadBufExpose ReadBuf as an array of bytes. This method is meant to be as efficient as possible, so for a array-backed ReadBuf, it should return its own internal data. In case access to internal data is not possible, a copy of the data into an array of bytes might occur. -
putBoolean
public void putBoolean(boolean value) Description copied from interface:ReadWriteBufPut a boolean into the buffer atwritePosition(). Booleans as stored as single byte. Write position will be incremented.- Specified by:
putBooleanin interfaceReadWriteBuf
-
put
public void put(byte[] value, int start, int length) Description copied from interface:ReadWriteBufPut an array of bytes into the buffer atwritePosition(). Write position will be incremented.- Specified by:
putin interfaceReadWriteBuf- Parameters:
value- the data to be copiedstart- initial position on value to be copiedlength- amount of bytes to be copied
-
put
public void put(byte value) Description copied from interface:ReadWriteBufWrite a byte into the buffer atwritePosition(). Write position will be incremented.- Specified by:
putin interfaceReadWriteBuf
-
putShort
public void putShort(short value) Description copied from interface:ReadWriteBufWrite a 16-bit into in the buffer atwritePosition(). Write position will be incremented.- Specified by:
putShortin interfaceReadWriteBuf
-
putInt
public void putInt(int value) Description copied from interface:ReadWriteBufWrite a 32-bit into in the buffer atwritePosition(). Write position will be incremented.- Specified by:
putIntin interfaceReadWriteBuf
-
putLong
public void putLong(long value) Description copied from interface:ReadWriteBufWrite a 64-bit into in the buffer atwritePosition(). Write position will be incremented.- Specified by:
putLongin interfaceReadWriteBuf
-
putFloat
public void putFloat(float value) Description copied from interface:ReadWriteBufWrite a 32-bit float into the buffer atwritePosition(). Write position will be incremented.- Specified by:
putFloatin interfaceReadWriteBuf
-
putDouble
public void putDouble(double value) Description copied from interface:ReadWriteBufWrite a 64-bit float into the buffer atwritePosition(). Write position will be incremented.- Specified by:
putDoublein interfaceReadWriteBuf
-
setBoolean
public void setBoolean(int index, boolean value) Description copied from interface:ReadWriteBufWrite boolean into a given position on the buffer. Booleans as stored as single byte.- Specified by:
setBooleanin interfaceReadWriteBuf- Parameters:
index- position of the element in buffer
-
set
public void set(int index, byte value) Description copied from interface:ReadWriteBufRead a byte from data.- Specified by:
setin interfaceReadWriteBuf- Parameters:
index- position of the element in the buffer
-
set
public void set(int index, byte[] toCopy, int start, int length) Description copied from interface:ReadWriteBufWrite an array of bytes into the buffer.- Specified by:
setin interfaceReadWriteBuf- Parameters:
index- initial position of the buffer to be writtentoCopy- the data to be copiedstart- initial position on value to be copiedlength- amount of bytes to be copied
-
setShort
public void setShort(int index, short value) Description copied from interface:ReadWriteBufRead a short from data.- Specified by:
setShortin interfaceReadWriteBuf- Parameters:
index- position of the element in ReadBuf
-
setInt
public void setInt(int index, int value) Description copied from interface:ReadWriteBufRead a 32-bit int from data.- Specified by:
setIntin interfaceReadWriteBuf- Parameters:
index- position of the element in ReadBuf
-
setLong
public void setLong(int index, long value) Description copied from interface:ReadWriteBufRead a 64-bit long from data.- Specified by:
setLongin interfaceReadWriteBuf- Parameters:
index- position of the element in ReadBuf
-
setFloat
public void setFloat(int index, float value) Description copied from interface:ReadWriteBufRead a 32-bit float from data.- Specified by:
setFloatin interfaceReadWriteBuf- Parameters:
index- position of the element in ReadBuf
-
setDouble
public void setDouble(int index, double value) Description copied from interface:ReadWriteBufRead a 64-bit float from data.- Specified by:
setDoublein interfaceReadWriteBuf- Parameters:
index- position of the element in ReadBuf
-
limit
public int limit()Description copied from interface:ReadWriteBufDefines the size of the message in the buffer. It also determines last position that buffer can be read or write. Last byte to be accessed is in positionlimit() -1.- Specified by:
limitin interfaceReadBuf- Specified by:
limitin interfaceReadWriteBuf- Returns:
- indicate last position
-
writePosition
public int writePosition()- Specified by:
writePositionin interfaceReadWriteBuf
-
requestCapacity
public boolean requestCapacity(int capacity) Description copied from interface:ReadWriteBufRequest capacity of the buffer. In case buffer is already larger than the requested, this method will just return true. Otherwise It might try to resize the buffer.- Specified by:
requestCapacityin interfaceReadWriteBuf- Returns:
- true if buffer is able to offer the requested capacity
-