forked from BigfootDev/flatbuffers
To read and build flexbuffers on Java, one needs to wrap the data using ByteBuffer. But for the common case of having ByteBuffers backed by arrays, accessing from a ByteBuffer might be inefficient. So this change introduces two interfaces: ReadBuf and ReadWriteBuf. It allows one to read and writes data directly on an array. It also allow other buffer implementations to be used with flexbuffers. Another change is that FlexBuffersBuilder backed by array allows the buffer to grow with the increase of the message size. Something that could not be done with ByteBuffer.
82 lines
2.0 KiB
Java
82 lines
2.0 KiB
Java
package com.google.flatbuffers;
|
|
|
|
/**
|
|
* Represent a chunk of data, where FlexBuffers will read from.
|
|
*/
|
|
interface ReadBuf {
|
|
|
|
/**
|
|
* Read boolean from data. Booleans as stored as single byte
|
|
* @param index position of the element in ReadBuf
|
|
* @return boolean element
|
|
*/
|
|
boolean getBoolean(int index);
|
|
|
|
/**
|
|
* Read a byte from data.
|
|
* @param index position of the element in ReadBuf
|
|
* @return a byte
|
|
*/
|
|
byte get(int index);
|
|
|
|
/**
|
|
* Read a short from data.
|
|
* @param index position of the element in ReadBuf
|
|
* @return a short
|
|
*/
|
|
short getShort(int index);
|
|
|
|
/**
|
|
* Read a 32-bit int from data.
|
|
* @param index position of the element in ReadBuf
|
|
* @return an int
|
|
*/
|
|
int getInt(int index);
|
|
|
|
/**
|
|
* Read a 64-bit long from data.
|
|
* @param index position of the element in ReadBuf
|
|
* @return a long
|
|
*/
|
|
long getLong(int index);
|
|
|
|
/**
|
|
* Read a 32-bit float from data.
|
|
* @param index position of the element in ReadBuf
|
|
* @return a float
|
|
*/
|
|
float getFloat(int index);
|
|
|
|
/**
|
|
* Read a 64-bit float from data.
|
|
* @param index position of the element in ReadBuf
|
|
* @return a double
|
|
*/
|
|
double getDouble(int index);
|
|
|
|
/**
|
|
* Read an UTF-8 string from data.
|
|
* @param start initial element of the string
|
|
* @param size size of the string in bytes.
|
|
* @return a {@code String}
|
|
*/
|
|
String getString(int start, int size);
|
|
|
|
/**
|
|
* 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.
|
|
* @return ReadBuf as an array of bytes
|
|
*/
|
|
byte[] data();
|
|
|
|
/**
|
|
* Defines the size of the message in the buffer. It also determines last position that buffer
|
|
* can be read. Last byte to be accessed is in position {@code limit() -1}.
|
|
* @return indicate last position
|
|
*/
|
|
int limit();
|
|
|
|
}
|