Package io.objectbox.flatbuffers
Class ByteBufferReadWriteBuf
java.lang.Object
io.objectbox.flatbuffers.ByteBufferReadWriteBuf
- All Implemented Interfaces:
ReadBuf
,ReadWriteBuf
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears (resets) the buffer so that it can be reused.byte[]
data()
Expose ReadBuf as an array of bytes.byte
get
(int index) Read a byte from data.boolean
getBoolean
(int index) Read boolean from data.double
getDouble
(int index) Read a 64-bit float from data.float
getFloat
(int index) Read a 32-bit float from data.int
getInt
(int index) Read a 32-bit int from data.long
getLong
(int index) Read a 64-bit long from data.short
getShort
(int index) Read a short from data.getString
(int start, int size) Read an UTF-8 string from data.int
limit()
Defines the size of the message in the buffer.void
put
(byte value) Write a byte into the buffer atwritePosition()
.void
put
(byte[] value, int start, int length) Put an array of bytes into the buffer atwritePosition()
.void
putBoolean
(boolean value) Put a boolean into the buffer atwritePosition()
.void
putDouble
(double value) Write a 64-bit float into the buffer atwritePosition()
.void
putFloat
(float value) Write a 32-bit float into the buffer atwritePosition()
.void
putInt
(int value) Write a 32-bit into in the buffer atwritePosition()
.void
putLong
(long value) Write a 64-bit into in the buffer atwritePosition()
.void
putShort
(short value) Write a 16-bit into in the buffer atwritePosition()
.boolean
requestCapacity
(int capacity) Request capacity of the buffer.void
set
(int index, byte value) Read a byte from data.void
set
(int index, byte[] value, int start, int length) Write an array of bytes into the buffer.void
setBoolean
(int index, boolean value) Write boolean into a given position on the buffer.void
setDouble
(int index, double value) Read a 64-bit float from data.void
setFloat
(int index, float value) Read a 32-bit float from data.void
setInt
(int index, int value) Read a 32-bit int from data.void
setLong
(int index, long value) Read a 64-bit long from data.void
setShort
(int index, short value) Read a short from data.int
-
Constructor Details
-
ByteBufferReadWriteBuf
-
-
Method Details
-
clear
public void clear()Description copied from interface:ReadWriteBuf
Clears (resets) the buffer so that it can be reused. Write position will be set to the start.- Specified by:
clear
in interfaceReadWriteBuf
-
getBoolean
public boolean getBoolean(int index) Description copied from interface:ReadBuf
Read boolean from data. Booleans as stored as single byte- Specified by:
getBoolean
in interfaceReadBuf
- Parameters:
index
- position of the element in ReadBuf- Returns:
- boolean element
-
get
public byte get(int index) Description copied from interface:ReadBuf
Read a byte from data. -
getShort
public short getShort(int index) Description copied from interface:ReadBuf
Read a short from data. -
getInt
public int getInt(int index) Description copied from interface:ReadBuf
Read a 32-bit int from data. -
getLong
public long getLong(int index) Description copied from interface:ReadBuf
Read a 64-bit long from data. -
getFloat
public float getFloat(int index) Description copied from interface:ReadBuf
Read a 32-bit float from data. -
getDouble
public double getDouble(int index) Description copied from interface:ReadBuf
Read a 64-bit float from data. -
getString
Description copied from interface:ReadBuf
Read an UTF-8 string from data. -
data
public byte[] data()Description copied from interface:ReadBuf
Expose 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:ReadWriteBuf
Put a boolean into the buffer atwritePosition()
. Booleans as stored as single byte. Write position will be incremented.- Specified by:
putBoolean
in interfaceReadWriteBuf
-
put
public void put(byte[] value, int start, int length) Description copied from interface:ReadWriteBuf
Put an array of bytes into the buffer atwritePosition()
. Write position will be incremented.- Specified by:
put
in 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:ReadWriteBuf
Write a byte into the buffer atwritePosition()
. Write position will be incremented.- Specified by:
put
in interfaceReadWriteBuf
-
putShort
public void putShort(short value) Description copied from interface:ReadWriteBuf
Write a 16-bit into in the buffer atwritePosition()
. Write position will be incremented.- Specified by:
putShort
in interfaceReadWriteBuf
-
putInt
public void putInt(int value) Description copied from interface:ReadWriteBuf
Write a 32-bit into in the buffer atwritePosition()
. Write position will be incremented.- Specified by:
putInt
in interfaceReadWriteBuf
-
putLong
public void putLong(long value) Description copied from interface:ReadWriteBuf
Write a 64-bit into in the buffer atwritePosition()
. Write position will be incremented.- Specified by:
putLong
in interfaceReadWriteBuf
-
putFloat
public void putFloat(float value) Description copied from interface:ReadWriteBuf
Write a 32-bit float into the buffer atwritePosition()
. Write position will be incremented.- Specified by:
putFloat
in interfaceReadWriteBuf
-
putDouble
public void putDouble(double value) Description copied from interface:ReadWriteBuf
Write a 64-bit float into the buffer atwritePosition()
. Write position will be incremented.- Specified by:
putDouble
in interfaceReadWriteBuf
-
setBoolean
public void setBoolean(int index, boolean value) Description copied from interface:ReadWriteBuf
Write boolean into a given position on the buffer. Booleans as stored as single byte.- Specified by:
setBoolean
in interfaceReadWriteBuf
- Parameters:
index
- position of the element in buffer
-
set
public void set(int index, byte value) Description copied from interface:ReadWriteBuf
Read a byte from data.- Specified by:
set
in interfaceReadWriteBuf
- Parameters:
index
- position of the element in the buffer
-
set
public void set(int index, byte[] value, int start, int length) Description copied from interface:ReadWriteBuf
Write an array of bytes into the buffer.- Specified by:
set
in interfaceReadWriteBuf
- Parameters:
index
- initial position of the buffer to be writtenvalue
- 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:ReadWriteBuf
Read a short from data.- Specified by:
setShort
in interfaceReadWriteBuf
- Parameters:
index
- position of the element in ReadBuf
-
setInt
public void setInt(int index, int value) Description copied from interface:ReadWriteBuf
Read a 32-bit int from data.- Specified by:
setInt
in interfaceReadWriteBuf
- Parameters:
index
- position of the element in ReadBuf
-
setLong
public void setLong(int index, long value) Description copied from interface:ReadWriteBuf
Read a 64-bit long from data.- Specified by:
setLong
in interfaceReadWriteBuf
- Parameters:
index
- position of the element in ReadBuf
-
setFloat
public void setFloat(int index, float value) Description copied from interface:ReadWriteBuf
Read a 32-bit float from data.- Specified by:
setFloat
in interfaceReadWriteBuf
- Parameters:
index
- position of the element in ReadBuf
-
setDouble
public void setDouble(int index, double value) Description copied from interface:ReadWriteBuf
Read a 64-bit float from data.- Specified by:
setDouble
in interfaceReadWriteBuf
- Parameters:
index
- position of the element in ReadBuf
-
writePosition
public int writePosition()- Specified by:
writePosition
in interfaceReadWriteBuf
-
limit
public int limit()Description copied from interface:ReadWriteBuf
Defines 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:
limit
in interfaceReadBuf
- Specified by:
limit
in interfaceReadWriteBuf
- Returns:
- indicate last position
-
requestCapacity
public boolean requestCapacity(int capacity) Description copied from interface:ReadWriteBuf
Request 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:
requestCapacity
in interfaceReadWriteBuf
- Returns:
- true if buffer is able to offer the requested capacity
-