mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
[Java][FlexBuffers] Abstract buffer access from ByteBuffer (#5743)
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.
This commit is contained in:
@@ -123,7 +123,7 @@ final public class Utf8Safe extends Utf8 {
|
||||
return utf8Length;
|
||||
}
|
||||
|
||||
private static String decodeUtf8Array(byte[] bytes, int index, int size) {
|
||||
public static String decodeUtf8Array(byte[] bytes, int index, int size) {
|
||||
// Bitwise OR combines the sign bits so any negative value fails the check.
|
||||
if ((index | size | bytes.length - index - size) < 0) {
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
@@ -197,7 +197,7 @@ final public class Utf8Safe extends Utf8 {
|
||||
return new String(resultArr, 0, resultPos);
|
||||
}
|
||||
|
||||
private static String decodeUtf8Buffer(ByteBuffer buffer, int offset,
|
||||
public static String decodeUtf8Buffer(ByteBuffer buffer, int offset,
|
||||
int length) {
|
||||
// Bitwise OR combines the sign bits so any negative value fails the check.
|
||||
if ((offset | length | buffer.limit() - offset - length) < 0) {
|
||||
|
||||
Reference in New Issue
Block a user