Skip to content

Commit e6f9f70

Browse files
FlatBuffers update: version 2.0.8.
1 parent 38740fd commit e6f9f70

15 files changed

+51
-77
lines changed

objectbox-java/src/main/java/io/objectbox/flatbuffers/ByteBufferReadWriteBuf.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.nio.ByteBuffer;
44
import java.nio.ByteOrder;
5-
import java.nio.Buffer;
65

76
public class ByteBufferReadWriteBuf implements ReadWriteBuf {
87

@@ -15,7 +14,7 @@ public ByteBufferReadWriteBuf(ByteBuffer bb) {
1514

1615
@Override
1716
public void clear() {
18-
((Buffer) buffer).clear();
17+
buffer.clear();
1918
}
2019

2120
@Override
@@ -118,9 +117,9 @@ public void set(int index, byte value) {
118117
public void set(int index, byte[] value, int start, int length) {
119118
requestCapacity(index + (length - start));
120119
int curPos = buffer.position();
121-
((Buffer) buffer).position(index);
120+
buffer.position(index);
122121
buffer.put(value, start, length);
123-
((Buffer) buffer).position(curPos);
122+
buffer.position(curPos);
124123
}
125124

126125
@Override

objectbox-java/src/main/java/io/objectbox/flatbuffers/ByteBufferUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static io.objectbox.flatbuffers.Constants.*;
2020

2121
import java.nio.ByteBuffer;
22-
import java.nio.Buffer;
2322

2423
/// @file
2524
/// @addtogroup flatbuffers_java_api
@@ -50,7 +49,7 @@ public static int getSizePrefix(ByteBuffer bb) {
5049
*/
5150
public static ByteBuffer removeSizePrefix(ByteBuffer bb) {
5251
ByteBuffer s = bb.duplicate();
53-
((Buffer) s).position(s.position() + SIZE_PREFIX_LENGTH);
52+
s.position(s.position() + SIZE_PREFIX_LENGTH);
5453
return s;
5554
}
5655

objectbox-java/src/main/java/io/objectbox/flatbuffers/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class Constants {
4646
Changes to the Java implementation need to be sure to change
4747
the version here and in the code generator on every possible
4848
incompatible change */
49-
public static void FLATBUFFERS_2_0_0() {}
49+
public static void FLATBUFFERS_2_0_8() {}
5050
}
5151

5252
/// @endcond

objectbox-java/src/main/java/io/objectbox/flatbuffers/FlatBufferBuilder.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public FlatBufferBuilder(int initial_size, ByteBufferFactory bb_factory,
9292
this.bb_factory = bb_factory;
9393
if (existing_bb != null) {
9494
bb = existing_bb;
95-
((Buffer) bb).clear();
95+
bb.clear();
9696
bb.order(ByteOrder.LITTLE_ENDIAN);
9797
} else {
9898
bb = bb_factory.newByteBuffer(initial_size);
@@ -154,7 +154,7 @@ public FlatBufferBuilder(ByteBuffer existing_bb) {
154154
public FlatBufferBuilder init(ByteBuffer existing_bb, ByteBufferFactory bb_factory){
155155
this.bb_factory = bb_factory;
156156
bb = existing_bb;
157-
((Buffer) bb).clear();
157+
bb.clear();
158158
bb.order(ByteOrder.LITTLE_ENDIAN);
159159
minalign = 1;
160160
space = bb.capacity();
@@ -235,7 +235,7 @@ public static boolean isFieldPresent(Table table, int offset) {
235235
*/
236236
public void clear(){
237237
space = bb.capacity();
238-
((Buffer) bb).clear();
238+
bb.clear();
239239
minalign = 1;
240240
while(vtable_in_use > 0) vtable[--vtable_in_use] = 0;
241241
vtable_in_use = 0;
@@ -273,10 +273,10 @@ static ByteBuffer growByteBuffer(ByteBuffer bb, ByteBufferFactory bb_factory) {
273273
new_buf_size = (old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1;
274274
}
275275

276-
((Buffer) bb).position(0);
276+
bb.position(0);
277277
ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size);
278-
new_buf_size = ((Buffer) nbb).clear().capacity(); // Ensure the returned buffer is treated as empty
279-
((Buffer) nbb).position(new_buf_size - old_buf_size);
278+
new_buf_size = nbb.clear().capacity(); // Ensure the returned buffer is treated as empty
279+
nbb.position(new_buf_size - old_buf_size);
280280
nbb.put(bb);
281281
return nbb;
282282
}
@@ -527,7 +527,7 @@ public ByteBuffer createUnintializedVector(int elem_size, int num_elems, int ali
527527
int length = elem_size * num_elems;
528528
startVector(elem_size, num_elems, alignment);
529529

530-
((Buffer) bb).position(space -= length);
530+
bb.position(space -= length);
531531

532532
// Slice and limit the copy vector to point to the 'array'
533533
ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
@@ -602,7 +602,7 @@ public int createString(CharSequence s) {
602602
int length = utf8.encodedLength(s);
603603
addByte((byte)0);
604604
startVector(1, length, 1);
605-
((Buffer) bb).position(space -= length);
605+
bb.position(space -= length);
606606
utf8.encodeUtf8(s, bb);
607607
return endVector();
608608
}
@@ -617,7 +617,7 @@ public int createString(ByteBuffer s) {
617617
int length = s.remaining();
618618
addByte((byte)0);
619619
startVector(1, length, 1);
620-
((Buffer) bb).position(space -= length);
620+
bb.position(space -= length);
621621
bb.put(s);
622622
return endVector();
623623
}
@@ -631,7 +631,7 @@ public int createString(ByteBuffer s) {
631631
public int createByteVector(byte[] arr) {
632632
int length = arr.length;
633633
startVector(1, length, 1);
634-
((Buffer) bb).position(space -= length);
634+
bb.position(space -= length);
635635
bb.put(arr);
636636
return endVector();
637637
}
@@ -646,7 +646,7 @@ public int createByteVector(byte[] arr) {
646646
*/
647647
public int createByteVector(byte[] arr, int offset, int length) {
648648
startVector(1, length, 1);
649-
((Buffer) bb).position(space -= length);
649+
bb.position(space -= length);
650650
bb.put(arr, offset, length);
651651
return endVector();
652652
}
@@ -663,7 +663,7 @@ public int createByteVector(byte[] arr, int offset, int length) {
663663
public int createByteVector(ByteBuffer byteBuffer) {
664664
int length = byteBuffer.remaining();
665665
startVector(1, length, 1);
666-
((Buffer) bb).position(space -= length);
666+
bb.position(space -= length);
667667
bb.put(byteBuffer);
668668
return endVector();
669669
}
@@ -953,7 +953,7 @@ protected void finish(int root_table, boolean size_prefix) {
953953
if (size_prefix) {
954954
addInt(bb.capacity() - space);
955955
}
956-
((Buffer) bb).position(space);
956+
bb.position(space);
957957
finished = true;
958958
}
959959

@@ -1067,7 +1067,7 @@ private int dataStart() {
10671067
public byte[] sizedByteArray(int start, int length){
10681068
finished();
10691069
byte[] array = new byte[length];
1070-
((Buffer) bb).position(start);
1070+
bb.position(start);
10711071
bb.get(array);
10721072
return array;
10731073
}
@@ -1090,7 +1090,7 @@ public byte[] sizedByteArray() {
10901090
public InputStream sizedInputStream() {
10911091
finished();
10921092
ByteBuffer duplicate = bb.duplicate();
1093-
((Buffer) duplicate).position(space);
1093+
duplicate.position(space);
10941094
duplicate.limit(bb.capacity());
10951095
return new ByteBufferBackedInputStream(duplicate);
10961096
}

objectbox-java/src/main/java/io/objectbox/flatbuffers/FlexBuffers.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.math.BigInteger;
2525
import java.nio.ByteBuffer;
26-
import java.nio.Buffer;
2726
import java.nio.charset.StandardCharsets;
2827

2928
/// @file
@@ -689,7 +688,7 @@ public static Blob empty() {
689688
*/
690689
public ByteBuffer data() {
691690
ByteBuffer dup = ByteBuffer.wrap(bb.data());
692-
((Buffer) dup).position(end);
691+
dup.position(end);
693692
dup.limit(end + size());
694693
return dup.asReadOnlyBuffer().slice();
695694
}
@@ -789,7 +788,12 @@ int compareTo(byte[] other) {
789788
if (io == other.length) {
790789
// in our buffer we have an additional \0 byte
791790
// but this does not exist in regular Java strings, so we return now
792-
return c1 - c2;
791+
int cmp = c1 - c2;
792+
if (cmp != 0 || bb.get(ia) == '\0') {
793+
return cmp;
794+
} else {
795+
return 1;
796+
}
793797
}
794798
}
795799
while (c1 == c2);
@@ -962,7 +966,12 @@ private int compareBytes(ReadBuf bb, int start, byte[] other) {
962966
if (l2 == other.length) {
963967
// in our buffer we have an additional \0 byte
964968
// but this does not exist in regular Java strings, so we return now
965-
return c1 - c2;
969+
int cmp = c1 - c2;
970+
if (cmp != 0 || bb.get(l1) == '\0') {
971+
return cmp;
972+
} else {
973+
return 1;
974+
}
966975
}
967976
}
968977
while (c1 == c2);

objectbox-java/src/main/java/io/objectbox/flatbuffers/FlexBuffersBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public int startVector() {
451451
/**
452452
* Finishes a vector, but writing the information in the buffer
453453
* @param key key used to store element in map
454-
* @param start reference for begining of the vector. Returned by {@link startVector()}
454+
* @param start reference for beginning of the vector. Returned by {@link startVector()}
455455
* @param typed boolean indicating whether vector is typed
456456
* @param fixed boolean indicating whether vector is fixed
457457
* @return Reference to the vector
@@ -602,7 +602,7 @@ public int startMap() {
602602
/**
603603
* Finishes a map, but writing the information in the buffer
604604
* @param key key used to store element in map
605-
* @param start reference for begining of the map. Returned by {@link startMap()}
605+
* @param start reference for beginning of the map. Returned by {@link startMap()}
606606
* @return Reference to the map
607607
*/
608608
public int endMap(String key, int start) {
@@ -763,7 +763,7 @@ private static int elemWidth(int type, int minBitWidth, long iValue, int bufSize
763763
// Compute relative offset.
764764
long offset = offsetLoc - iValue;
765765
// Does it fit?
766-
int bitWidth = widthUInBits((int) offset);
766+
int bitWidth = widthUInBits(offset);
767767
if (((1L) << bitWidth) == byteWidth)
768768
return bitWidth;
769769
}

objectbox-java/src/main/java/io/objectbox/flatbuffers/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
This is a copy of the [FlatBuffers](https://github.com/google/flatbuffers) for Java source code in a custom package
44
to avoid conflicts with FlatBuffers generated Java code from users of this library.
55

6-
Current version: see `Constants.java`.
6+
Current version: `2.0.8` (Note: version in `Constants.java` may be lower).
77

88
Copy a different version using the script in `scripts\update-flatbuffers.sh`.
99
It expects FlatBuffers source files in the `../flatbuffers` directory (e.g. check out
10-
the desired FlatBuffers tag from https://github.com/google/flatbuffers next to this repo).
10+
the desired FlatBuffers tag from https://github.com/objectbox/flatbuffers next to this repo).
1111
The Java library is expected in `objectbox-java`, e.g. run the script from the root of this repo.
1212

1313
## Licensing

objectbox-java/src/main/java/io/objectbox/flatbuffers/Table.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static io.objectbox.flatbuffers.Constants.*;
2020
import java.nio.ByteBuffer;
21-
import java.nio.Buffer;
2221
import java.nio.ByteOrder;
2322

2423
/// @cond FLATBUFFERS_INTERNAL
@@ -153,7 +152,7 @@ protected ByteBuffer __vector_as_bytebuffer(int vector_offset, int elem_size) {
153152
if (o == 0) return null;
154153
ByteBuffer bb = this.bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
155154
int vectorstart = __vector(o);
156-
((Buffer) bb).position(vectorstart);
155+
bb.position(vectorstart);
157156
bb.limit(vectorstart + __vector_len(o) * elem_size);
158157
return bb;
159158
}
@@ -175,7 +174,7 @@ protected ByteBuffer __vector_in_bytebuffer(ByteBuffer bb, int vector_offset, in
175174
int vectorstart = __vector(o);
176175
bb.rewind();
177176
bb.limit(vectorstart + __vector_len(o) * elem_size);
178-
((Buffer) bb).position(vectorstart);
177+
bb.position(vectorstart);
179178
return bb;
180179
}
181180

objectbox-java/src/main/java/io/objectbox/flatbuffers/Utf8Old.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package io.objectbox.flatbuffers;
1818

1919
import java.nio.ByteBuffer;
20-
import java.nio.Buffer;
2120
import java.nio.CharBuffer;
2221
import java.nio.charset.CharacterCodingException;
2322
import java.nio.charset.CharsetDecoder;
@@ -56,7 +55,7 @@ public int encodedLength(CharSequence in) {
5655
if (cache.lastOutput == null || cache.lastOutput.capacity() < estimated) {
5756
cache.lastOutput = ByteBuffer.allocate(Math.max(128, estimated));
5857
}
59-
((Buffer) cache.lastOutput).clear();
58+
cache.lastOutput.clear();
6059
cache.lastInput = in;
6160
CharBuffer wrap = (in instanceof CharBuffer) ?
6261
(CharBuffer) in : CharBuffer.wrap(in);
@@ -68,7 +67,7 @@ public int encodedLength(CharSequence in) {
6867
throw new IllegalArgumentException("bad character encoding", e);
6968
}
7069
}
71-
((Buffer) cache.lastOutput).flip();
70+
cache.lastOutput.flip();
7271
return cache.lastOutput.remaining();
7372
}
7473

@@ -88,7 +87,7 @@ public String decodeUtf8(ByteBuffer buffer, int offset, int length) {
8887
CharsetDecoder decoder = CACHE.get().decoder;
8988
decoder.reset();
9089
buffer = buffer.duplicate();
91-
((Buffer) buffer).position(offset);
90+
buffer.position(offset);
9291
buffer.limit(offset + length);
9392
try {
9493
CharBuffer result = decoder.decode(buffer);

objectbox-java/src/main/java/io/objectbox/flatbuffers/Utf8Safe.java

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,6 @@
1-
// Protocol Buffers - Google's data interchange format
2-
// Copyright 2008 Google Inc. All rights reserved.
3-
// https://developers.google.com/protocol-buffers/
4-
//
5-
// Redistribution and use in source and binary forms, with or without
6-
// modification, are permitted provided that the following conditions are
7-
// met:
8-
//
9-
// * Redistributions of source code must retain the above copyright
10-
// notice, this list of conditions and the following disclaimer.
11-
// * Redistributions in binary form must reproduce the above
12-
// copyright notice, this list of conditions and the following disclaimer
13-
// in the documentation and/or other materials provided with the
14-
// distribution.
15-
// * Neither the name of Google Inc. nor the names of its
16-
// contributors may be used to endorse or promote products derived from
17-
// this software without specific prior written permission.
18-
//
19-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-
311
package io.objectbox.flatbuffers;
322

333
import java.nio.ByteBuffer;
34-
import java.nio.Buffer;
354
import static java.lang.Character.MAX_SURROGATE;
365
import static java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT;
376
import static java.lang.Character.MIN_SURROGATE;
@@ -311,7 +280,7 @@ private static void encodeUtf8Buffer(CharSequence in, ByteBuffer out) {
311280
}
312281
if (inIx == inLength) {
313282
// Successfully encoded the entire string.
314-
((Buffer) out).position(outIx + inIx);
283+
out.position(outIx + inIx);
315284
return;
316285
}
317286

@@ -354,7 +323,7 @@ private static void encodeUtf8Buffer(CharSequence in, ByteBuffer out) {
354323
}
355324

356325
// Successfully encoded the entire string.
357-
((Buffer) out).position(outIx);
326+
out.position(outIx);
358327
} catch (IndexOutOfBoundsException e) {
359328
// TODO(nathanmittler): Consider making the API throw IndexOutOfBoundsException instead.
360329

@@ -435,7 +404,7 @@ public void encodeUtf8(CharSequence in, ByteBuffer out) {
435404
int start = out.arrayOffset();
436405
int end = encodeUtf8Array(in, out.array(), start + out.position(),
437406
out.remaining());
438-
((Buffer) out).position(end - start);
407+
out.position(end - start);
439408
} else {
440409
encodeUtf8Buffer(in, out);
441410
}

0 commit comments

Comments
 (0)