From be9d562d57e832bf858bd104306878294e2c9fa1 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 9 Jul 2024 19:56:25 +0200 Subject: [PATCH] Remove some unused fbs files --- third_party/flatbuffers/java/pom.xml | 197 --- .../google/flatbuffers/ArrayReadWriteBuf.java | 252 --- .../com/google/flatbuffers/BaseVector.java | 96 -- .../com/google/flatbuffers/BooleanVector.java | 49 - .../flatbuffers/ByteBufferReadWriteBuf.java | 170 -- .../google/flatbuffers/ByteBufferUtil.java | 58 - .../com/google/flatbuffers/ByteVector.java | 60 - .../com/google/flatbuffers/Constants.java | 52 - .../com/google/flatbuffers/DoubleVector.java | 49 - .../google/flatbuffers/FlatBufferBuilder.java | 1120 ------------ .../com/google/flatbuffers/FlexBuffers.java | 1221 ------------- .../flatbuffers/FlexBuffersBuilder.java | 802 --------- .../com/google/flatbuffers/FloatVector.java | 49 - .../com/google/flatbuffers/IntVector.java | 60 - .../com/google/flatbuffers/LongVector.java | 49 - .../java/com/google/flatbuffers/ReadBuf.java | 81 - .../com/google/flatbuffers/ReadWriteBuf.java | 142 -- .../com/google/flatbuffers/ShortVector.java | 60 - .../com/google/flatbuffers/StringVector.java | 52 - .../java/com/google/flatbuffers/Struct.java | 61 - .../java/com/google/flatbuffers/Table.java | 322 ---- .../com/google/flatbuffers/UnionVector.java | 52 - .../java/com/google/flatbuffers/Utf8.java | 247 --- .../java/com/google/flatbuffers/Utf8Old.java | 106 -- .../java/com/google/flatbuffers/Utf8Safe.java | 421 ----- .../reflection/AdvancedFeatures.java | 16 - .../flatbuffers/reflection/BaseType.java | 33 - .../google/flatbuffers/reflection/Enum.java | 135 -- .../flatbuffers/reflection/EnumVal.java | 116 -- .../google/flatbuffers/reflection/Field.java | 155 -- .../flatbuffers/reflection/KeyValue.java | 88 - .../google/flatbuffers/reflection/Object.java | 137 -- .../flatbuffers/reflection/RPCCall.java | 115 -- .../google/flatbuffers/reflection/Schema.java | 127 -- .../flatbuffers/reflection/SchemaFile.java | 102 -- .../flatbuffers/reflection/Service.java | 124 -- .../google/flatbuffers/reflection/Type.java | 79 - .../java/src/test/java/DictionaryLookup | 1 - .../java/src/test/java/JavaTest.java | 1533 ----------------- .../flatbuffers/java/src/test/java/MyGame | 1 - .../flatbuffers/java/src/test/java/NamespaceA | 1 - .../flatbuffers/java/src/test/java/NamespaceC | 1 - .../java/src/test/java/optional_scalars | 1 - .../java/src/test/java/union_vector | 1 - .../src/test/resources/monsterdata_test.mon | Bin 600 -> 0 bytes 45 files changed, 8594 deletions(-) delete mode 100644 third_party/flatbuffers/java/pom.xml delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ArrayReadWriteBuf.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BaseVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BooleanVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferReadWriteBuf.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferUtil.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Constants.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/DoubleVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffers.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffersBuilder.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FloatVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/IntVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/LongVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadBuf.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadWriteBuf.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ShortVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/StringVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Struct.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Table.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/UnionVector.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Old.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Safe.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/AdvancedFeatures.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/BaseType.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Enum.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/EnumVal.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Field.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/KeyValue.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Object.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/RPCCall.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Schema.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/SchemaFile.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Service.java delete mode 100644 third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Type.java delete mode 120000 third_party/flatbuffers/java/src/test/java/DictionaryLookup delete mode 100644 third_party/flatbuffers/java/src/test/java/JavaTest.java delete mode 120000 third_party/flatbuffers/java/src/test/java/MyGame delete mode 120000 third_party/flatbuffers/java/src/test/java/NamespaceA delete mode 120000 third_party/flatbuffers/java/src/test/java/NamespaceC delete mode 120000 third_party/flatbuffers/java/src/test/java/optional_scalars delete mode 120000 third_party/flatbuffers/java/src/test/java/union_vector delete mode 100644 third_party/flatbuffers/java/src/test/resources/monsterdata_test.mon diff --git a/third_party/flatbuffers/java/pom.xml b/third_party/flatbuffers/java/pom.xml deleted file mode 100644 index 1e7dbbc1f..000000000 --- a/third_party/flatbuffers/java/pom.xml +++ /dev/null @@ -1,197 +0,0 @@ - - - 4.0.0 - com.google.flatbuffers - flatbuffers-java - 24.3.25 - bundle - FlatBuffers Java API - - Memory Efficient Serialization Library - - - - Wouter van Oortmerssen - - - Derek Bailey - dbaileychess@gmail.com - - - - UTF-8 - - https://github.com/google/flatbuffers - - - Apache License V2.0 - https://raw.githubusercontent.com/google/flatbuffers/master/LICENSE - repo - - - - https://github.com/google/flatbuffers - - scm:git:https://github.com/google/flatbuffers.git - - HEAD - - - - junit - junit - 4.13.1 - test - - - com.google.truth - truth - 1.1.3 - test - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - - - maven-surefire-plugin - - - **/*Test.java - - - 2.22.2 - - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.3.0 - - -Xdoclint:none - -Xdoclint:none - - - - attach-javadocs - - jar - - - - - - org.apache.felix - maven-bundle-plugin - 5.1.2 - true - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-gpg-plugin - 3.0.1 - - - sign-artifacts - verify - - sign - - - - --pinentry-mode - loopback - - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - true - false - release - deploy - - - - - - - jdk9 - - [1.9,) - - - - - maven-compiler-plugin - - 8 - - MyGame/Example/MonsterStorageGrpc.java - MyGame/OtherNameSpace/TableBT.java - - - 3.8.1 - - - - - - jdk8 - - 1.8 - - - 8 - 8 - - - - - maven-compiler-plugin - - - MyGame/Example/MonsterStorageGrpc.java - MyGame/OtherNameSpace/TableBT.java - - - 3.8.1 - - - - - - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ArrayReadWriteBuf.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ArrayReadWriteBuf.java deleted file mode 100644 index b7573d6e1..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ArrayReadWriteBuf.java +++ /dev/null @@ -1,252 +0,0 @@ -package com.google.flatbuffers; - -import java.util.Arrays; - -/** - * Implements {@code ReadBuf} using an array of bytes - * as a backing storage. Using array of bytes are - * usually faster than {@code 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 - */ -public class ArrayReadWriteBuf implements ReadWriteBuf { - - private byte[] buffer; - private int writePos; - - public ArrayReadWriteBuf() { - this(10); - } - - public ArrayReadWriteBuf(int initialCapacity) { - this(new byte[initialCapacity]); - } - - public ArrayReadWriteBuf(byte[] buffer) { - this.buffer = buffer; - this.writePos = 0; - } - - public ArrayReadWriteBuf(byte[] buffer, int startPos) { - this.buffer = buffer; - this.writePos = startPos; - } - - @Override - public void clear() { - this.writePos = 0; - } - - @Override - public boolean getBoolean(int index) { - return buffer[index] != 0; - } - - @Override - public byte get(int index) { - return buffer[index]; - } - - @Override - public short getShort(int index) { - return (short) ((buffer[index+ 1] << 8) | (buffer[index] & 0xff)); - } - - @Override - public int getInt(int index) { - return (((buffer[index + 3]) << 24) | - ((buffer[index + 2] & 0xff) << 16) | - ((buffer[index + 1] & 0xff) << 8) | - ((buffer[index] & 0xff))); - } - - @Override - public long getLong(int index) { - return ((((long) buffer[index++] & 0xff)) | - (((long) buffer[index++] & 0xff) << 8) | - (((long) buffer[index++] & 0xff) << 16) | - (((long) buffer[index++] & 0xff) << 24) | - (((long) buffer[index++] & 0xff) << 32) | - (((long) buffer[index++] & 0xff) << 40) | - (((long) buffer[index++] & 0xff) << 48) | - (((long) buffer[index]) << 56)); - } - - @Override - public float getFloat(int index) { - return Float.intBitsToFloat(getInt(index)); - } - - @Override - public double getDouble(int index) { - return Double.longBitsToDouble(getLong(index)); - } - - @Override - public String getString(int start, int size) { - return Utf8Safe.decodeUtf8Array(buffer, start, size); - } - - @Override - public byte[] data() { - return buffer; - } - - - @Override - public void putBoolean(boolean value) { - setBoolean(writePos, value); - writePos++; - } - - @Override - public void put(byte[] value, int start, int length) { - set(writePos, value, start, length); - writePos+=length; - } - - @Override - public void put(byte value) { - set(writePos, value); - writePos++; - } - - @Override - public void putShort(short value) { - setShort(writePos, value); - writePos +=2; - } - - @Override - public void putInt(int value) { - setInt(writePos, value); - writePos +=4; - } - - @Override - public void putLong(long value) { - setLong(writePos, value); - writePos +=8; - } - - @Override - public void putFloat(float value) { - setFloat(writePos, value); - writePos +=4; - } - - @Override - public void putDouble(double value) { - setDouble(writePos, value); - writePos +=8; - } - - @Override - public void setBoolean(int index, boolean value) { - set(index, value ? (byte)1 : (byte)0); - } - - @Override - public void set(int index, byte value) { - requestCapacity(index + 1); - buffer[index] = value; - } - - @Override - public void set(int index, byte[] toCopy, int start, int length) { - requestCapacity(index + (length - start)); - System.arraycopy(toCopy, start, buffer, index, length); - } - - @Override - public void setShort(int index, short value) { - requestCapacity(index + 2); - - buffer[index++] = (byte) ((value) & 0xff); - buffer[index ] = (byte) ((value >> 8) & 0xff); - } - - @Override - public void setInt(int index, int value) { - requestCapacity(index + 4); - - buffer[index++] = (byte) ((value) & 0xff); - buffer[index++] = (byte) ((value >> 8) & 0xff); - buffer[index++] = (byte) ((value >> 16) & 0xff); - buffer[index ] = (byte) ((value >> 24) & 0xff); - } - - @Override - public void setLong(int index, long value) { - requestCapacity(index + 8); - - int i = (int) value; - buffer[index++] = (byte) ((i) & 0xff); - buffer[index++] = (byte) ((i >> 8) & 0xff); - buffer[index++] = (byte) ((i >> 16) & 0xff); - buffer[index++] = (byte) ((i >> 24) & 0xff); - i = (int) (value >> 32); - buffer[index++] = (byte) ((i) & 0xff); - buffer[index++] = (byte) ((i >> 8) & 0xff); - buffer[index++] = (byte) ((i >> 16) & 0xff); - buffer[index ] = (byte) ((i >> 24) & 0xff); - } - - @Override - public void setFloat(int index, float value) { - requestCapacity(index + 4); - - int iValue = Float.floatToRawIntBits(value); - buffer[index++] = (byte) ((iValue) & 0xff); - buffer[index++] = (byte) ((iValue >> 8) & 0xff); - buffer[index++] = (byte) ((iValue >> 16) & 0xff); - buffer[index ] = (byte) ((iValue >> 24) & 0xff); - } - - @Override - public void setDouble(int index, double value) { - requestCapacity(index + 8); - - long lValue = Double.doubleToRawLongBits(value); - int i = (int) lValue; - buffer[index++] = (byte) ((i) & 0xff); - buffer[index++] = (byte) ((i >> 8) & 0xff); - buffer[index++] = (byte) ((i >> 16) & 0xff); - buffer[index++] = (byte) ((i >> 24) & 0xff); - i = (int) (lValue >> 32); - buffer[index++] = (byte) ((i) & 0xff); - buffer[index++] = (byte) ((i >> 8) & 0xff); - buffer[index++] = (byte) ((i >> 16) & 0xff); - buffer[index ] = (byte) ((i >> 24) & 0xff); - } - - @Override - public int limit() { - return writePos; - } - - @Override - public int writePosition() { - return writePos; - } - - @Override - public boolean requestCapacity(int capacity) { - if (capacity < 0) { - throw new IllegalArgumentException("Capacity may not be negative (likely a previous int overflow)"); - } - if (buffer.length >= capacity) { - return true; - } - // implemented in the same growing fashion as ArrayList - int oldCapacity = buffer.length; - int newCapacity = oldCapacity + (oldCapacity >> 1); - if (newCapacity < capacity) { // Note: this also catches newCapacity int overflow - newCapacity = capacity; - } - buffer = Arrays.copyOf(buffer, newCapacity); - return true; - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BaseVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BaseVector.java deleted file mode 100644 index 9230da79d..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BaseVector.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import java.nio.ByteBuffer; - -/// @cond FLATBUFFERS_INTERNAL - -/** - * All vector access objects derive from this class, and add their own accessors. - */ -public class BaseVector { - /** Used to hold the vector data position. */ - private int vector; - /** Used to hold the vector size. */ - private int length; - /** Used to hold the vector element size in table. */ - private int element_size; - /** The underlying ByteBuffer to hold the data of the vector. */ - protected ByteBuffer bb; - - /** - * Get the start data of a vector. - * - * @return Returns the start of the vector data. - */ - protected int __vector() { - return vector; - } - - /** - * Gets the element position in vector's ByteBuffer. - * - * @param j An `int` index of element into a vector. - * @return Returns the position of the vector element in a ByteBuffer. - */ - protected int __element(int j) { - return vector + j * element_size; - } - - /** - * Re-init the internal state with an external buffer {@code ByteBuffer}, an offset within and - * element size. - * - * This method exists primarily to allow recycling vector instances without risking memory leaks - * due to {@code ByteBuffer} references. - */ - protected void __reset(int _vector, int _element_size, ByteBuffer _bb) { - bb = _bb; - if (bb != null) { - vector = _vector; - length = bb.getInt(_vector - Constants.SIZEOF_INT); - element_size = _element_size; - } else { - vector = 0; - length = 0; - element_size = 0; - } - } - - /** - * Resets the internal state with a null {@code ByteBuffer} and a zero position. - * - * This method exists primarily to allow recycling vector instances without risking memory leaks - * due to {@code ByteBuffer} references. The instance will be unusable until it is assigned - * again to a {@code ByteBuffer}. - */ - public void reset() { - __reset(0, 0, null); - } - - /** - * Get the length of a vector. - * - * @return Returns the length of the vector. - */ - public int length() { - return length; - } -} - -/// @endcond diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BooleanVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BooleanVector.java deleted file mode 100644 index 1c2a4cda3..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/BooleanVector.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of booleans. - */ -public final class BooleanVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public BooleanVector __assign(int _vector, ByteBuffer _bb) { - __reset(_vector, Constants.SIZEOF_BYTE, _bb); return this; - } - - /** - * Reads the boolean at the given index. - * - * @param j The index from which the boolean will be read. - * @return the boolean value at the given index. - */ - public boolean get(int j) { - return 0 != bb.get(__element(j)); - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferReadWriteBuf.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferReadWriteBuf.java deleted file mode 100644 index aaf72fe81..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferReadWriteBuf.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.google.flatbuffers; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -public class ByteBufferReadWriteBuf implements ReadWriteBuf { - - private final ByteBuffer buffer; - - public ByteBufferReadWriteBuf(ByteBuffer bb) { - this.buffer = bb; - this.buffer.order(ByteOrder.LITTLE_ENDIAN); - } - - @Override - public void clear() { - buffer.clear(); - } - - @Override - public boolean getBoolean(int index) { - return get(index) != 0; - } - - @Override - public byte get(int index) { - return buffer.get(index); - } - - @Override - public short getShort(int index) { - return buffer.getShort(index); - } - - @Override - public int getInt(int index) { - return buffer.getInt(index); - } - - @Override - public long getLong(int index) { - return buffer.getLong(index); - } - - @Override - public float getFloat(int index) { - return buffer.getFloat(index); - } - - @Override - public double getDouble(int index) { - return buffer.getDouble(index); - } - - @Override - public String getString(int start, int size) { - return Utf8Safe.decodeUtf8Buffer(buffer, start, size); - } - - @Override - public byte[] data() { - return buffer.array(); - } - - @Override - public void putBoolean(boolean value) { - buffer.put(value ? (byte)1 : (byte)0); - } - - @Override - public void put(byte[] value, int start, int length) { - buffer.put(value, start, length); - } - - @Override - public void put(byte value) { - buffer.put(value); - } - - @Override - public void putShort(short value) { - buffer.putShort(value); - } - - @Override - public void putInt(int value) { - buffer.putInt(value); - } - - @Override - public void putLong(long value) { - buffer.putLong(value); - } - - @Override - public void putFloat(float value) { - buffer.putFloat(value); - } - - @Override - public void putDouble(double value) { - buffer.putDouble(value); - } - - @Override - public void setBoolean(int index, boolean value) { - set(index, value ? (byte)1 : (byte)0); - } - - @Override - public void set(int index, byte value) { - requestCapacity(index + 1); - buffer.put(index, value); - } - - @Override - public void set(int index, byte[] value, int start, int length) { - requestCapacity(index + (length - start)); - int curPos = buffer.position(); - buffer.position(index); - buffer.put(value, start, length); - buffer.position(curPos); - } - - @Override - public void setShort(int index, short value) { - requestCapacity(index + 2); - buffer.putShort(index, value); - } - - @Override - public void setInt(int index, int value) { - requestCapacity(index + 4); - buffer.putInt(index, value); - } - - @Override - public void setLong(int index, long value) { - requestCapacity(index + 8); - buffer.putLong(index, value); - } - - @Override - public void setFloat(int index, float value) { - requestCapacity(index + 4); - buffer.putFloat(index, value); - } - - @Override - public void setDouble(int index, double value) { - requestCapacity(index + 8); - buffer.putDouble(index, value); - } - - @Override - public int writePosition() { - return buffer.position(); - } - - @Override - public int limit() { - return buffer.limit(); - } - - @Override - public boolean requestCapacity(int capacity) { - return capacity <= buffer.limit(); - } - -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferUtil.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferUtil.java deleted file mode 100644 index 624dc4e2f..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteBufferUtil.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2017 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; - -import java.nio.ByteBuffer; - -/// @file -/// @addtogroup flatbuffers_java_api -/// @{ - -/** - * Class that collects utility functions around `ByteBuffer`. - */ -public class ByteBufferUtil { - - /** - * Extract the size prefix from a `ByteBuffer`. - * - * @param bb a size-prefixed buffer - * @return the size prefix - */ - public static int getSizePrefix(ByteBuffer bb) { - return bb.getInt(bb.position()); - } - - /** - * Create a duplicate of a size-prefixed `ByteBuffer` that has its position - * advanced just past the size prefix. - * - * @param bb a size-prefixed buffer - * @return a new buffer on the same underlying data that has skipped the - * size prefix - */ - public static ByteBuffer removeSizePrefix(ByteBuffer bb) { - ByteBuffer s = bb.duplicate(); - s.position(s.position() + SIZE_PREFIX_LENGTH); - return s; - } - -} - -/// @} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteVector.java deleted file mode 100644 index 8bc715b3c..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ByteVector.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of signed or unsigned 8-bit values. - */ -public final class ByteVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param vector Start data of a vector. - * @param bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public ByteVector __assign(int vector, ByteBuffer bb) { - __reset(vector, Constants.SIZEOF_BYTE, bb); return this; - } - - /** - * Reads the byte at the given index. - * - * @param j The index from which the byte will be read. - * @return the 8-bit value at the given index. - */ - public byte get(int j) { - return bb.get(__element(j)); - } - - /** - * Reads the byte at the given index, zero-extends it to type int, and returns the result, - * which is therefore in the range 0 through 255. - * - * @param j The index from which the byte will be read. - * @return the unsigned 8-bit at the given index. - */ - public int getAsUnsigned(int j) { - return (int) get(j) & 0xFF; - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Constants.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Constants.java deleted file mode 100644 index c7bae316b..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Constants.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -/// @cond FLATBUFFERS_INTERNAL - -/** - * Class that holds shared constants - */ -public class Constants { - // Java doesn't seem to have these. - /** The number of bytes in an `byte`. */ - static final int SIZEOF_BYTE = 1; - /** The number of bytes in a `short`. */ - static final int SIZEOF_SHORT = 2; - /** The number of bytes in an `int`. */ - static final int SIZEOF_INT = 4; - /** The number of bytes in an `float`. */ - static final int SIZEOF_FLOAT = 4; - /** The number of bytes in an `long`. */ - static final int SIZEOF_LONG = 8; - /** The number of bytes in an `double`. */ - static final int SIZEOF_DOUBLE = 8; - /** The number of bytes in a file identifier. */ - static final int FILE_IDENTIFIER_LENGTH = 4; - /** The number of bytes in a size prefix. */ - public static final int SIZE_PREFIX_LENGTH = 4; - /** A version identifier to force a compile error if someone - accidentally tries to build generated code with a runtime of - two mismatched version. Versions need to always match, as - the runtime and generated code are modified in sync. - Changes to the Java implementation need to be sure to change - the version here and in the code generator on every possible - incompatible change */ - public static void FLATBUFFERS_24_3_25() {} -} - -/// @endcond diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/DoubleVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/DoubleVector.java deleted file mode 100644 index fd4a3a48a..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/DoubleVector.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of double values. - */ -public final class DoubleVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public DoubleVector __assign(int _vector, ByteBuffer _bb) { - __reset(_vector, Constants.SIZEOF_DOUBLE, _bb); return this; - } - - /** - * Reads the double value at the given index. - * - * @param j The index from which the double value will be read. - * @return the double value at the given index. - */ - public double get(int j) { - return bb.getDouble(__element(j)); - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java deleted file mode 100644 index a954d9fbb..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java +++ /dev/null @@ -1,1120 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.*; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.lang.Integer; - -/// @file -/// @addtogroup flatbuffers_java_api -/// @{ - -/** - * Class that helps you build a FlatBuffer. See the section - * "Use in Java/C#" in the main FlatBuffers documentation. - */ -public class FlatBufferBuilder { - /// @cond FLATBUFFERS_INTERNAL - ByteBuffer bb; // Where we construct the FlatBuffer. - int space; // Remaining space in the ByteBuffer. - int minalign = 1; // Minimum alignment encountered so far. - int[] vtable = null; // The vtable for the current table. - int vtable_in_use = 0; // The amount of fields we're actually using. - boolean nested = false; // Whether we are currently serializing a table. - boolean finished = false; // Whether the buffer is finished. - int object_start; // Starting offset of the current struct/table. - int[] vtables = new int[16]; // List of offsets of all vtables. - int num_vtables = 0; // Number of entries in `vtables` in use. - int vector_num_elems = 0; // For the current vector being built. - boolean force_defaults = false; // False omits default values from the serialized data. - ByteBufferFactory bb_factory; // Factory for allocating the internal buffer - final Utf8 utf8; // UTF-8 encoder to use - Map string_pool; // map used to cache shared strings. - /// @endcond - - - /** - * Maximum size of buffer to allocate. If we're allocating arrays on the heap, - * the header size of the array counts towards its maximum size. - */ - private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8; - - /** - * Default buffer size that is allocated if an initial size is not given, or is - * non positive. - */ - private static final int DEFAULT_BUFFER_SIZE = 1024; - - /** - * Start with a buffer of size `initial_size`, then grow as required. - * - * @param initial_size The initial size of the internal buffer to use. - * @param bb_factory The factory to be used for allocating the internal buffer - */ - public FlatBufferBuilder(int initial_size, ByteBufferFactory bb_factory) { - this(initial_size, bb_factory, null, Utf8.getDefault()); - } - - /** - * Start with a buffer of size `initial_size`, then grow as required. - * - * @param initial_size The initial size of the internal buffer to use. - * @param bb_factory The factory to be used for allocating the internal buffer - * @param existing_bb The byte buffer to reuse. - * @param utf8 The Utf8 codec - */ - public FlatBufferBuilder(int initial_size, ByteBufferFactory bb_factory, - ByteBuffer existing_bb, Utf8 utf8) { - if (initial_size <= 0) { - initial_size = DEFAULT_BUFFER_SIZE; - } - this.bb_factory = bb_factory; - if (existing_bb != null) { - bb = existing_bb; - bb.clear(); - bb.order(ByteOrder.LITTLE_ENDIAN); - } else { - bb = bb_factory.newByteBuffer(initial_size); - } - this.utf8 = utf8; - space = bb.capacity(); - } - - /** - * Start with a buffer of size `initial_size`, then grow as required. - * - * @param initial_size The initial size of the internal buffer to use. - */ - public FlatBufferBuilder(int initial_size) { - this(initial_size, HeapByteBufferFactory.INSTANCE, null, Utf8.getDefault()); - } - - /** - * Start with a buffer of 1KiB, then grow as required. - */ - public FlatBufferBuilder() { - this(DEFAULT_BUFFER_SIZE); - } - - /** - * Alternative constructor allowing reuse of {@link ByteBuffer}s. The builder - * can still grow the buffer as necessary. User classes should make sure - * to call {@link #dataBuffer()} to obtain the resulting encoded message. - * - * @param existing_bb The byte buffer to reuse. - * @param bb_factory The factory to be used for allocating a new internal buffer if - * the existing buffer needs to grow - */ - public FlatBufferBuilder(ByteBuffer existing_bb, ByteBufferFactory bb_factory) { - this(existing_bb.capacity(), bb_factory, existing_bb, Utf8.getDefault()); - } - - /** - * Alternative constructor allowing reuse of {@link ByteBuffer}s. The builder - * can still grow the buffer as necessary. User classes should make sure - * to call {@link #dataBuffer()} to obtain the resulting encoded message. - * - * @param existing_bb The byte buffer to reuse. - */ - public FlatBufferBuilder(ByteBuffer existing_bb) { - this(existing_bb, new HeapByteBufferFactory()); - } - - /** - * Alternative initializer that allows reusing this object on an existing - * `ByteBuffer`. This method resets the builder's internal state, but keeps - * objects that have been allocated for temporary storage. - * - * @param existing_bb The byte buffer to reuse. - * @param bb_factory The factory to be used for allocating a new internal buffer if - * the existing buffer needs to grow - * @return Returns `this`. - */ - public FlatBufferBuilder init(ByteBuffer existing_bb, ByteBufferFactory bb_factory){ - this.bb_factory = bb_factory; - bb = existing_bb; - bb.clear(); - bb.order(ByteOrder.LITTLE_ENDIAN); - minalign = 1; - space = bb.capacity(); - vtable_in_use = 0; - nested = false; - finished = false; - object_start = 0; - num_vtables = 0; - vector_num_elems = 0; - if (string_pool != null) { - string_pool.clear(); - } - return this; - } - - /** - * An interface that provides a user of the FlatBufferBuilder class the ability to specify - * the method in which the internal buffer gets allocated. This allows for alternatives - * to the default behavior, which is to allocate memory for a new byte-array - * backed `ByteBuffer` array inside the JVM. - * - * The FlatBufferBuilder class contains the HeapByteBufferFactory class to - * preserve the default behavior in the event that the user does not provide - * their own implementation of this interface. - */ - public static abstract class ByteBufferFactory { - /** - * Create a `ByteBuffer` with a given capacity. - * The returned ByteBuf must have a ByteOrder.LITTLE_ENDIAN ByteOrder. - * - * @param capacity The size of the `ByteBuffer` to allocate. - * @return Returns the new `ByteBuffer` that was allocated. - */ - public abstract ByteBuffer newByteBuffer(int capacity); - - /** - * Release a ByteBuffer. Current {@link FlatBufferBuilder} - * released any reference to it, so it is safe to dispose the buffer - * or return it to a pool. - * It is not guaranteed that the buffer has been created - * with {@link #newByteBuffer(int) }. - * - * @param bb the buffer to release - */ - public void releaseByteBuffer(ByteBuffer bb) { - } - } - - /** - * An implementation of the ByteBufferFactory interface that is used when - * one is not provided by the user. - * - * Allocate memory for a new byte-array backed `ByteBuffer` array inside the JVM. - */ - public static final class HeapByteBufferFactory extends ByteBufferFactory { - - public static final HeapByteBufferFactory INSTANCE = new HeapByteBufferFactory(); - - @Override - public ByteBuffer newByteBuffer(int capacity) { - return ByteBuffer.allocate(capacity).order(ByteOrder.LITTLE_ENDIAN); - } - } - - /** - * Helper function to test if a field is present in the table - * - * @param table Flatbuffer table - * @param offset virtual table offset - * @return true if the filed is present - */ - public static boolean isFieldPresent(Table table, int offset) { - return table.__offset(offset) != 0; - } - - /** - * Reset the FlatBufferBuilder by purging all data that it holds. - */ - public void clear(){ - space = bb.capacity(); - bb.clear(); - minalign = 1; - while(vtable_in_use > 0) vtable[--vtable_in_use] = 0; - vtable_in_use = 0; - nested = false; - finished = false; - object_start = 0; - num_vtables = 0; - vector_num_elems = 0; - if (string_pool != null) { - string_pool.clear(); - } - } - - /** - * Doubles the size of the backing {@link ByteBuffer} and copies the old data towards the - * end of the new buffer (since we build the buffer backwards). - * - * @param bb The current buffer with the existing data. - * @param bb_factory The factory to be used for allocating the new internal buffer - * @return A new byte buffer with the old data copied copied to it. The data is - * located at the end of the buffer. - */ - static ByteBuffer growByteBuffer(ByteBuffer bb, ByteBufferFactory bb_factory) { - int old_buf_size = bb.capacity(); - - int new_buf_size; - - if (old_buf_size == 0) { - new_buf_size = DEFAULT_BUFFER_SIZE; - } - else { - if (old_buf_size == MAX_BUFFER_SIZE) { // Ensure we don't grow beyond what fits in an int. - throw new AssertionError("FlatBuffers: cannot grow buffer beyond 2 gigabytes."); - } - new_buf_size = (old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1; - } - - bb.position(0); - ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size); - new_buf_size = nbb.clear().capacity(); // Ensure the returned buffer is treated as empty - nbb.position(new_buf_size - old_buf_size); - nbb.put(bb); - return nbb; - } - - /** - * Offset relative to the end of the buffer. - * - * @return Offset relative to the end of the buffer. - */ - public int offset() { - return bb.capacity() - space; - } - - /** - * Add zero valued bytes to prepare a new entry to be added. - * - * @param byte_size Number of bytes to add. - */ - public void pad(int byte_size) { - for (int i = 0; i < byte_size; i++) bb.put(--space, (byte)0); - } - - /** - * Prepare to write an element of `size` after `additional_bytes` - * have been written, e.g. if you write a string, you need to align such - * the int length field is aligned to {@link com.google.flatbuffers.Constants#SIZEOF_INT}, and - * the string data follows it directly. If all you need to do is alignment, `additional_bytes` - * will be 0. - * - * @param size This is the of the new element to write. - * @param additional_bytes The padding size. - */ - public void prep(int size, int additional_bytes) { - // Track the biggest thing we've ever aligned to. - if (size > minalign) minalign = size; - // Find the amount of alignment needed such that `size` is properly - // aligned after `additional_bytes` - int align_size = ((~(bb.capacity() - space + additional_bytes)) + 1) & (size - 1); - // Reallocate the buffer if needed. - while (space < align_size + size + additional_bytes) { - int old_buf_size = bb.capacity(); - ByteBuffer old = bb; - bb = growByteBuffer(old, bb_factory); - if (old != bb) { - bb_factory.releaseByteBuffer(old); - } - space += bb.capacity() - old_buf_size; - } - pad(align_size); - } - - /** - * Add a `boolean` to the buffer, backwards from the current location. Doesn't align nor - * check for space. - * - * @param x A `boolean` to put into the buffer. - */ - public void putBoolean(boolean x) { bb.put (space -= Constants.SIZEOF_BYTE, (byte)(x ? 1 : 0)); } - - /** - * Add a `byte` to the buffer, backwards from the current location. Doesn't align nor - * check for space. - * - * @param x A `byte` to put into the buffer. - */ - public void putByte (byte x) { bb.put (space -= Constants.SIZEOF_BYTE, x); } - - /** - * Add a `short` to the buffer, backwards from the current location. Doesn't align nor - * check for space. - * - * @param x A `short` to put into the buffer. - */ - public void putShort (short x) { bb.putShort (space -= Constants.SIZEOF_SHORT, x); } - - /** - * Add an `int` to the buffer, backwards from the current location. Doesn't align nor - * check for space. - * - * @param x An `int` to put into the buffer. - */ - public void putInt (int x) { bb.putInt (space -= Constants.SIZEOF_INT, x); } - - /** - * Add a `long` to the buffer, backwards from the current location. Doesn't align nor - * check for space. - * - * @param x A `long` to put into the buffer. - */ - public void putLong (long x) { bb.putLong (space -= Constants.SIZEOF_LONG, x); } - - /** - * Add a `float` to the buffer, backwards from the current location. Doesn't align nor - * check for space. - * - * @param x A `float` to put into the buffer. - */ - public void putFloat (float x) { bb.putFloat (space -= Constants.SIZEOF_FLOAT, x); } - - /** - * Add a `double` to the buffer, backwards from the current location. Doesn't align nor - * check for space. - * - * @param x A `double` to put into the buffer. - */ - public void putDouble (double x) { bb.putDouble(space -= Constants.SIZEOF_DOUBLE, x); } - /// @endcond - - /** - * Add a `boolean` to the buffer, properly aligned, and grows the buffer (if necessary). - * - * @param x A `boolean` to put into the buffer. - */ - public void addBoolean(boolean x) { prep(Constants.SIZEOF_BYTE, 0); putBoolean(x); } - - /** - * Add a `byte` to the buffer, properly aligned, and grows the buffer (if necessary). - * - * @param x A `byte` to put into the buffer. - */ - public void addByte (byte x) { prep(Constants.SIZEOF_BYTE, 0); putByte (x); } - - /** - * Add a `short` to the buffer, properly aligned, and grows the buffer (if necessary). - * - * @param x A `short` to put into the buffer. - */ - public void addShort (short x) { prep(Constants.SIZEOF_SHORT, 0); putShort (x); } - - /** - * Add an `int` to the buffer, properly aligned, and grows the buffer (if necessary). - * - * @param x An `int` to put into the buffer. - */ - public void addInt (int x) { prep(Constants.SIZEOF_INT, 0); putInt (x); } - - /** - * Add a `long` to the buffer, properly aligned, and grows the buffer (if necessary). - * - * @param x A `long` to put into the buffer. - */ - public void addLong (long x) { prep(Constants.SIZEOF_LONG, 0); putLong (x); } - - /** - * Add a `float` to the buffer, properly aligned, and grows the buffer (if necessary). - * - * @param x A `float` to put into the buffer. - */ - public void addFloat (float x) { prep(Constants.SIZEOF_FLOAT, 0); putFloat (x); } - - /** - * Add a `double` to the buffer, properly aligned, and grows the buffer (if necessary). - * - * @param x A `double` to put into the buffer. - */ - public void addDouble (double x) { prep(Constants.SIZEOF_DOUBLE, 0); putDouble (x); } - - /** - * Adds on offset, relative to where it will be written. - * - * @param off The offset to add. - */ - public void addOffset(int off) { - prep(SIZEOF_INT, 0); // Ensure alignment is already done. - assert off <= offset(); - off = offset() - off + SIZEOF_INT; - putInt(off); - } - - /// @cond FLATBUFFERS_INTERNAL - /** - * Start a new array/vector of objects. Users usually will not call - * this directly. The `FlatBuffers` compiler will create a start/end - * method for vector types in generated code. - *

- * The expected sequence of calls is: - *

    - *
  1. Start the array using this method.
  2. - *
  3. Call {@link #addOffset(int)} `num_elems` number of times to set - * the offset of each element in the array.
  4. - *
  5. Call {@link #endVector()} to retrieve the offset of the array.
  6. - *
- *

- * For example, to create an array of strings, do: - *

{@code
-    * // Need 10 strings
-    * FlatBufferBuilder builder = new FlatBufferBuilder(existingBuffer);
-    * int[] offsets = new int[10];
-    *
-    * for (int i = 0; i < 10; i++) {
-    *   offsets[i] = fbb.createString(" " + i);
-    * }
-    *
-    * // Have the strings in the buffer, but don't have a vector.
-    * // Add a vector that references the newly created strings:
-    * builder.startVector(4, offsets.length, 4);
-    *
-    * // Add each string to the newly created vector
-    * // The strings are added in reverse order since the buffer
-    * // is filled in back to front
-    * for (int i = offsets.length - 1; i >= 0; i--) {
-    *   builder.addOffset(offsets[i]);
-    * }
-    *
-    * // Finish off the vector
-    * int offsetOfTheVector = fbb.endVector();
-    * }
- * - * @param elem_size The size of each element in the array. - * @param num_elems The number of elements in the array. - * @param alignment The alignment of the array. - */ - public void startVector(int elem_size, int num_elems, int alignment) { - notNested(); - vector_num_elems = num_elems; - prep(SIZEOF_INT, elem_size * num_elems); - prep(alignment, elem_size * num_elems); // Just in case alignment > int. - nested = true; - } - - /** - * Finish off the creation of an array and all its elements. The array - * must be created with {@link #startVector(int, int, int)}. - * - * @return The offset at which the newly created array starts. - * @see #startVector(int, int, int) - */ - public int endVector() { - if (!nested) - throw new AssertionError("FlatBuffers: endVector called without startVector"); - nested = false; - putInt(vector_num_elems); - return offset(); - } - /// @endcond - - /** - * Create a new array/vector and return a ByteBuffer to be filled later. - * Call {@link #endVector} after this method to get an offset to the beginning - * of vector. - * - * @param elem_size the size of each element in bytes. - * @param num_elems number of elements in the vector. - * @param alignment byte alignment. - * @return ByteBuffer with position and limit set to the space allocated for the array. - */ - public ByteBuffer createUnintializedVector(int elem_size, int num_elems, int alignment) { - int length = elem_size * num_elems; - startVector(elem_size, num_elems, alignment); - - bb.position(space -= length); - - // Slice and limit the copy vector to point to the 'array' - ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN); - copy.limit(length); - return copy; - } - - /** - * Create a vector of tables. - * - * @param offsets Offsets of the tables. - * @return Returns offset of the vector. - */ - public int createVectorOfTables(int[] offsets) { - notNested(); - startVector(Constants.SIZEOF_INT, offsets.length, Constants.SIZEOF_INT); - for(int i = offsets.length - 1; i >= 0; i--) addOffset(offsets[i]); - return endVector(); - } - - /** - * Create a vector of sorted by the key tables. - * - * @param obj Instance of the table subclass. - * @param offsets Offsets of the tables. - * @return Returns offset of the sorted vector. - */ - public int createSortedVectorOfTables(T obj, int[] offsets) { - obj.sortTables(offsets, bb); - return createVectorOfTables(offsets); - } - - /** - * Encode the String `s` in the buffer using UTF-8. If a String with - * this exact contents has already been serialized using this method, - * instead simply returns the offset of the existing String. - * - * Usage of the method will incur into additional allocations, - * so it is advisable to use it only when it is known upfront that - * your message will have several repeated strings. - * - * @param s The String to encode. - * @return The offset in the buffer where the encoded String starts. - */ - public int createSharedString(String s) { - - if (string_pool == null) { - string_pool = new HashMap<>(); - int offset = createString(s); - string_pool.put(s, offset); - return offset; - - } - - Integer offset = string_pool.get(s); - - if(offset == null) { - offset = createString(s); - string_pool.put(s, offset); - } - return offset; - } - - /** - * Encode the string `s` in the buffer using UTF-8. If {@code s} is - * already a {@link CharBuffer}, this method is allocation free. - * - * @param s The string to encode. - * @return The offset in the buffer where the encoded string starts. - */ - public int createString(CharSequence s) { - int length = utf8.encodedLength(s); - addByte((byte)0); - startVector(1, length, 1); - bb.position(space -= length); - utf8.encodeUtf8(s, bb); - return endVector(); - } - - /** - * Create a string in the buffer from an already encoded UTF-8 string in a ByteBuffer. - * - * @param s An already encoded UTF-8 string as a `ByteBuffer`. - * @return The offset in the buffer where the encoded string starts. - */ - public int createString(ByteBuffer s) { - int length = s.remaining(); - addByte((byte)0); - startVector(1, length, 1); - bb.position(space -= length); - bb.put(s); - return endVector(); - } - - /** - * Create a byte array in the buffer. - * - * @param arr A source array with data - * @return The offset in the buffer where the encoded array starts. - */ - public int createByteVector(byte[] arr) { - int length = arr.length; - startVector(1, length, 1); - bb.position(space -= length); - bb.put(arr); - return endVector(); - } - - /** - * Create a byte array in the buffer. - * - * @param arr a source array with data. - * @param offset the offset in the source array to start copying from. - * @param length the number of bytes to copy from the source array. - * @return The offset in the buffer where the encoded array starts. - */ - public int createByteVector(byte[] arr, int offset, int length) { - startVector(1, length, 1); - bb.position(space -= length); - bb.put(arr, offset, length); - return endVector(); - } - - /** - * Create a byte array in the buffer. - * - * The source {@link ByteBuffer} position is advanced by {@link ByteBuffer#remaining()} places - * after this call. - * - * @param byteBuffer A source {@link ByteBuffer} with data. - * @return The offset in the buffer where the encoded array starts. - */ - public int createByteVector(ByteBuffer byteBuffer) { - int length = byteBuffer.remaining(); - startVector(1, length, 1); - bb.position(space -= length); - bb.put(byteBuffer); - return endVector(); - } - - /// @cond FLATBUFFERS_INTERNAL - /** - * Should not be accessing the final buffer before it is finished. - */ - public void finished() { - if (!finished) - throw new AssertionError( - "FlatBuffers: you can only access the serialized buffer after it has been" + - " finished by FlatBufferBuilder.finish()."); - } - - /** - * Should not be creating any other object, string or vector - * while an object is being constructed. - */ - public void notNested() { - if (nested) - throw new AssertionError("FlatBuffers: object serialization must not be nested."); - } - - /** - * Structures are always stored inline, they need to be created right - * where they're used. You'll get this assertion failure if you - * created it elsewhere. - * - * @param obj The offset of the created object. - */ - public void Nested(int obj) { - if (obj != offset()) - throw new AssertionError("FlatBuffers: struct must be serialized inline."); - } - - /** - * Start encoding a new object in the buffer. Users will not usually need to - * call this directly. The `FlatBuffers` compiler will generate helper methods - * that call this method internally. - *

- * For example, using the "Monster" code found on the "landing page". An - * object of type `Monster` can be created using the following code: - * - *

{@code
-    * int testArrayOfString = Monster.createTestarrayofstringVector(fbb, new int[] {
-    *   fbb.createString("test1"),
-    *   fbb.createString("test2")
-    * });
-    *
-    * Monster.startMonster(fbb);
-    * Monster.addPos(fbb, Vec3.createVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
-    *   Color.Green, (short)5, (byte)6));
-    * Monster.addHp(fbb, (short)80);
-    * Monster.addName(fbb, str);
-    * Monster.addInventory(fbb, inv);
-    * Monster.addTestType(fbb, (byte)Any.Monster);
-    * Monster.addTest(fbb, mon2);
-    * Monster.addTest4(fbb, test4);
-    * Monster.addTestarrayofstring(fbb, testArrayOfString);
-    * int mon = Monster.endMonster(fbb);
-    * }
- *

- * Here: - *

    - *
  • The call to `Monster#startMonster(FlatBufferBuilder)` will call this - * method with the right number of fields set.
  • - *
  • `Monster#endMonster(FlatBufferBuilder)` will ensure {@link #endObject()} is called.
  • - *
- *

- * It's not recommended to call this method directly. If it's called manually, you must ensure - * to audit all calls to it whenever fields are added or removed from your schema. This is - * automatically done by the code generated by the `FlatBuffers` compiler. - * - * @param numfields The number of fields found in this object. - */ - public void startTable(int numfields) { - notNested(); - if (vtable == null || vtable.length < numfields) vtable = new int[numfields]; - vtable_in_use = numfields; - Arrays.fill(vtable, 0, vtable_in_use, 0); - nested = true; - object_start = offset(); - } - - /** - * Add a `boolean` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x A `boolean` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d A `boolean` default value to compare against when `force_defaults` is `false`. - */ - public void addBoolean(int o, boolean x, boolean d) { if(force_defaults || x != d) { addBoolean(x); slot(o); } } - - /** - * Add a `byte` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x A `byte` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d A `byte` default value to compare against when `force_defaults` is `false`. - */ - public void addByte (int o, byte x, int d) { if(force_defaults || x != d) { addByte (x); slot(o); } } - - /** - * Add a `short` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x A `short` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d A `short` default value to compare against when `force_defaults` is `false`. - */ - public void addShort (int o, short x, int d) { if(force_defaults || x != d) { addShort (x); slot(o); } } - - /** - * Add an `int` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x An `int` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d An `int` default value to compare against when `force_defaults` is `false`. - */ - public void addInt (int o, int x, int d) { if(force_defaults || x != d) { addInt (x); slot(o); } } - - /** - * Add a `long` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x A `long` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d A `long` default value to compare against when `force_defaults` is `false`. - */ - public void addLong (int o, long x, long d) { if(force_defaults || x != d) { addLong (x); slot(o); } } - - /** - * Add a `float` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x A `float` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d A `float` default value to compare against when `force_defaults` is `false`. - */ - public void addFloat (int o, float x, double d) { if(force_defaults || x != d) { addFloat (x); slot(o); } } - - /** - * Add a `double` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x A `double` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d A `double` default value to compare against when `force_defaults` is `false`. - */ - public void addDouble (int o, double x, double d) { if(force_defaults || x != d) { addDouble (x); slot(o); } } - - /** - * Add an `offset` to a table at `o` into its vtable, with value `x` and default `d`. - * - * @param o The index into the vtable. - * @param x An `offset` to put into the buffer, depending on how defaults are handled. If - * `force_defaults` is `false`, compare `x` against the default value `d`. If `x` contains the - * default value, it can be skipped. - * @param d An `offset` default value to compare against when `force_defaults` is `false`. - */ - public void addOffset (int o, int x, int d) { if(force_defaults || x != d) { addOffset (x); slot(o); } } - - /** - * Add a struct to the table. Structs are stored inline, so nothing additional is being added. - * - * @param voffset The index into the vtable. - * @param x The offset of the created struct. - * @param d The default value is always `0`. - */ - public void addStruct(int voffset, int x, int d) { - if(x != d) { - Nested(x); - slot(voffset); - } - } - - /** - * Set the current vtable at `voffset` to the current location in the buffer. - * - * @param voffset The index into the vtable to store the offset relative to the end of the - * buffer. - */ - public void slot(int voffset) { - vtable[voffset] = offset(); - } - - /** - * Finish off writing the object that is under construction. - * - * @return The offset to the object inside {@link #dataBuffer()}. - * @see #startTable(int) - */ - public int endTable() { - if (vtable == null || !nested) - throw new AssertionError("FlatBuffers: endTable called without startTable"); - addInt(0); - int vtableloc = offset(); - // Write out the current vtable. - int i = vtable_in_use - 1; - // Trim trailing zeroes. - for (; i >= 0 && vtable[i] == 0; i--) {} - int trimmed_size = i + 1; - for (; i >= 0 ; i--) { - // Offset relative to the start of the table. - short off = (short)(vtable[i] != 0 ? vtableloc - vtable[i] : 0); - addShort(off); - } - - final int standard_fields = 2; // The fields below: - addShort((short)(vtableloc - object_start)); - addShort((short)((trimmed_size + standard_fields) * SIZEOF_SHORT)); - - // Search for an existing vtable that matches the current one. - int existing_vtable = 0; - outer_loop: - for (i = 0; i < num_vtables; i++) { - int vt1 = bb.capacity() - vtables[i]; - int vt2 = space; - short len = bb.getShort(vt1); - if (len == bb.getShort(vt2)) { - for (int j = SIZEOF_SHORT; j < len; j += SIZEOF_SHORT) { - if (bb.getShort(vt1 + j) != bb.getShort(vt2 + j)) { - continue outer_loop; - } - } - existing_vtable = vtables[i]; - break outer_loop; - } - } - - if (existing_vtable != 0) { - // Found a match: - // Remove the current vtable. - space = bb.capacity() - vtableloc; - // Point table to existing vtable. - bb.putInt(space, existing_vtable - vtableloc); - } else { - // No match: - // Add the location of the current vtable to the list of vtables. - if (num_vtables == vtables.length) vtables = Arrays.copyOf(vtables, num_vtables * 2); - vtables[num_vtables++] = offset(); - // Point table to current vtable. - bb.putInt(bb.capacity() - vtableloc, offset() - vtableloc); - } - - nested = false; - return vtableloc; - } - - /** - * Checks that a required field has been set in a given table that has - * just been constructed. - * - * @param table The offset to the start of the table from the `ByteBuffer` capacity. - * @param field The offset to the field in the vtable. - */ - public void required(int table, int field) { - int table_start = bb.capacity() - table; - int vtable_start = table_start - bb.getInt(table_start); - boolean ok = bb.getShort(vtable_start + field) != 0; - // If this fails, the caller will show what field needs to be set. - if (!ok) - throw new AssertionError("FlatBuffers: field " + field + " must be set"); - } - /// @endcond - - /** - * Finalize a buffer, pointing to the given `root_table`. - * - * @param root_table An offset to be added to the buffer. - * @param size_prefix Whether to prefix the size to the buffer. - */ - protected void finish(int root_table, boolean size_prefix) { - prep(minalign, SIZEOF_INT + (size_prefix ? SIZEOF_INT : 0)); - addOffset(root_table); - if (size_prefix) { - addInt(bb.capacity() - space); - } - bb.position(space); - finished = true; - } - - /** - * Finalize a buffer, pointing to the given `root_table`. - * - * @param root_table An offset to be added to the buffer. - */ - public void finish(int root_table) { - finish(root_table, false); - } - - /** - * Finalize a buffer, pointing to the given `root_table`, with the size prefixed. - * - * @param root_table An offset to be added to the buffer. - */ - public void finishSizePrefixed(int root_table) { - finish(root_table, true); - } - - /** - * Finalize a buffer, pointing to the given `root_table`. - * - * @param root_table An offset to be added to the buffer. - * @param file_identifier A FlatBuffer file identifier to be added to the buffer before - * `root_table`. - * @param size_prefix Whether to prefix the size to the buffer. - */ - protected void finish(int root_table, String file_identifier, boolean size_prefix) { - prep(minalign, SIZEOF_INT + FILE_IDENTIFIER_LENGTH + (size_prefix ? SIZEOF_INT : 0)); - if (file_identifier.length() != FILE_IDENTIFIER_LENGTH) - throw new AssertionError("FlatBuffers: file identifier must be length " + - FILE_IDENTIFIER_LENGTH); - for (int i = FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) { - addByte((byte)file_identifier.charAt(i)); - } - finish(root_table, size_prefix); - } - - /** - * Finalize a buffer, pointing to the given `root_table`. - * - * @param root_table An offset to be added to the buffer. - * @param file_identifier A FlatBuffer file identifier to be added to the buffer before - * `root_table`. - */ - public void finish(int root_table, String file_identifier) { - finish(root_table, file_identifier, false); - } - - /** - * Finalize a buffer, pointing to the given `root_table`, with the size prefixed. - * - * @param root_table An offset to be added to the buffer. - * @param file_identifier A FlatBuffer file identifier to be added to the buffer before - * `root_table`. - */ - public void finishSizePrefixed(int root_table, String file_identifier) { - finish(root_table, file_identifier, true); - } - - /** - * In order to save space, fields that are set to their default value - * don't get serialized into the buffer. Forcing defaults provides a - * way to manually disable this optimization. - * - * @param forceDefaults When set to `true`, always serializes default values. - * @return Returns `this`. - */ - public FlatBufferBuilder forceDefaults(boolean forceDefaults){ - this.force_defaults = forceDefaults; - return this; - } - - /** - * Get the ByteBuffer representing the FlatBuffer. Only call this after you've - * called `finish()`. The actual data starts at the ByteBuffer's current position, - * not necessarily at `0`. - * - * @return The {@link ByteBuffer} representing the FlatBuffer - */ - public ByteBuffer dataBuffer() { - finished(); - return bb; - } - - /** - * The FlatBuffer data doesn't start at offset 0 in the {@link ByteBuffer}, but - * now the {@code ByteBuffer}'s position is set to that location upon {@link #finish(int)}. - * - * @return The {@link ByteBuffer#position() position} the data starts in {@link #dataBuffer()} - * @deprecated This method should not be needed anymore, but is left - * here for the moment to document this API change. It will be removed in the future. - */ - @Deprecated - private int dataStart() { - finished(); - return space; - } - - /** - * A utility function to copy and return the ByteBuffer data from `start` to - * `start` + `length` as a `byte[]`. - * - * @param start Start copying at this offset. - * @param length How many bytes to copy. - * @return A range copy of the {@link #dataBuffer() data buffer}. - * @throws IndexOutOfBoundsException If the range of bytes is ouf of bound. - */ - public byte[] sizedByteArray(int start, int length){ - finished(); - byte[] array = new byte[length]; - bb.position(start); - bb.get(array); - return array; - } - - /** - * A utility function to copy and return the ByteBuffer data as a `byte[]`. - * - * @return A full copy of the {@link #dataBuffer() data buffer}. - */ - public byte[] sizedByteArray() { - return sizedByteArray(space, bb.capacity() - space); - } - - /** - * A utility function to return an InputStream to the ByteBuffer data - * - * @return An InputStream that starts at the beginning of the ByteBuffer data - * and can read to the end of it. - */ - public InputStream sizedInputStream() { - finished(); - ByteBuffer duplicate = bb.duplicate(); - duplicate.position(space); - duplicate.limit(bb.capacity()); - return new ByteBufferBackedInputStream(duplicate); - } - - /** - * A class that allows a user to create an InputStream from a ByteBuffer. - */ - static class ByteBufferBackedInputStream extends InputStream { - - ByteBuffer buf; - - public ByteBufferBackedInputStream(ByteBuffer buf) { - this.buf = buf; - } - - public int read() throws IOException { - try { - return buf.get() & 0xFF; - } catch(BufferUnderflowException e) { - return -1; - } - } - } - -} - -/// @} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffers.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffers.java deleted file mode 100644 index 75a0595f6..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffers.java +++ /dev/null @@ -1,1221 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - - -import static com.google.flatbuffers.FlexBuffers.Unsigned.byteToUnsignedInt; -import static com.google.flatbuffers.FlexBuffers.Unsigned.intToUnsignedLong; -import static com.google.flatbuffers.FlexBuffers.Unsigned.shortToUnsignedInt; - -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; - -/// @file -/// @addtogroup flatbuffers_java_api -/// @{ - -/** - * This class can be used to parse FlexBuffer messages. - *

- * For generating FlexBuffer messages, use {@link FlexBuffersBuilder}. - *

- * Example of usage: - *

- * ReadBuf bb = ... // load message from file or network
- * FlexBuffers.Reference r = FlexBuffers.getRoot(bb); // Reads the root element
- * FlexBuffers.Map map = r.asMap(); // We assumed root object is a map
- * System.out.println(map.get("name").asString()); // prints element with key "name"
- * 
- */ -public class FlexBuffers { - - // These are used as the upper 6 bits of a type field to indicate the actual - // type. - /** Represent a null type */ - public static final int FBT_NULL = 0; - /** Represent a signed integer type */ - public static final int FBT_INT = 1; - /** Represent a unsigned type */ - public static final int FBT_UINT = 2; - /** Represent a float type */ - public static final int FBT_FLOAT = 3; // Types above stored inline, types below store an offset. - /** Represent a key to a map type */ - public static final int FBT_KEY = 4; - /** Represent a string type */ - public static final int FBT_STRING = 5; - /** Represent a indirect signed integer type */ - public static final int FBT_INDIRECT_INT = 6; - /** Represent a indirect unsigned integer type */ - public static final int FBT_INDIRECT_UINT = 7; - /** Represent a indirect float type */ - public static final int FBT_INDIRECT_FLOAT = 8; - /** Represent a map type */ - public static final int FBT_MAP = 9; - /** Represent a vector type */ - public static final int FBT_VECTOR = 10; // Untyped. - /** Represent a vector of signed integers type */ - public static final int FBT_VECTOR_INT = 11; // Typed any size = stores no type table). - /** Represent a vector of unsigned integers type */ - public static final int FBT_VECTOR_UINT = 12; - /** Represent a vector of floats type */ - public static final int FBT_VECTOR_FLOAT = 13; - /** Represent a vector of keys type */ - public static final int FBT_VECTOR_KEY = 14; - /** Represent a vector of strings type */ - // DEPRECATED, use FBT_VECTOR or FBT_VECTOR_KEY instead. - // more info on thttps://github.com/google/flatbuffers/issues/5627. - public static final int FBT_VECTOR_STRING_DEPRECATED = 15; - - /// @cond FLATBUFFERS_INTERNAL - public static final int FBT_VECTOR_INT2 = 16; // Typed tuple = no type table; no size field). - public static final int FBT_VECTOR_UINT2 = 17; - public static final int FBT_VECTOR_FLOAT2 = 18; - public static final int FBT_VECTOR_INT3 = 19; // Typed triple = no type table; no size field). - public static final int FBT_VECTOR_UINT3 = 20; - public static final int FBT_VECTOR_FLOAT3 = 21; - public static final int FBT_VECTOR_INT4 = 22; // Typed quad = no type table; no size field). - public static final int FBT_VECTOR_UINT4 = 23; - public static final int FBT_VECTOR_FLOAT4 = 24; - /// @endcond FLATBUFFERS_INTERNAL - - /** Represent a blob type */ - public static final int FBT_BLOB = 25; - /** Represent a boolean type */ - public static final int FBT_BOOL = 26; - /** Represent a vector of booleans type */ - public static final int FBT_VECTOR_BOOL = 36; // To Allow the same type of conversion of type to vector type - - private static final ReadBuf EMPTY_BB = new ArrayReadWriteBuf(new byte[] {0}, 1); - - /** - * Checks where a type is a typed vector - * - * @param type type to be checked - * @return true if typed vector - */ - static boolean isTypedVector(int type) { - return (type >= FBT_VECTOR_INT && type <= FBT_VECTOR_STRING_DEPRECATED) || type == FBT_VECTOR_BOOL; - } - - /** - * Check whether you can access type directly (no indirection) or not. - * - * @param type type to be checked - * @return true if inline type - */ - static boolean isTypeInline(int type) { - return type <= FBT_FLOAT || type == FBT_BOOL; - } - - static int toTypedVectorElementType(int original_type) { - return original_type - FBT_VECTOR_INT + FBT_INT; - } - - /** - * Return a vector type our of a original element type - * - * @param type element type - * @param fixedLength size of element - * @return typed vector type - */ - static int toTypedVector(int type, int fixedLength) { - assert (isTypedVectorElementType(type)); - switch (fixedLength) { - case 0: return type - FBT_INT + FBT_VECTOR_INT; - case 2: return type - FBT_INT + FBT_VECTOR_INT2; - case 3: return type - FBT_INT + FBT_VECTOR_INT3; - case 4: return type - FBT_INT + FBT_VECTOR_INT4; - default: - assert (false); - return FBT_NULL; - } - } - - static boolean isTypedVectorElementType(int type) { - return (type >= FBT_INT && type <= FBT_KEY) || type == FBT_BOOL; - } - - // return position of the element that the offset is pointing to - private static int indirect(ReadBuf bb, int offset, int byteWidth) { - // we assume all offset fits on a int, since ReadBuf operates with that assumption - return (int) (offset - readUInt(bb, offset, byteWidth)); - } - - // read unsigned int with size byteWidth and return as a 64-bit integer - private static long readUInt(ReadBuf buff, int end, int byteWidth) { - switch (byteWidth) { - case 1: return byteToUnsignedInt(buff.get(end)); - case 2: return shortToUnsignedInt(buff.getShort(end)); - case 4: return intToUnsignedLong(buff.getInt(end)); - case 8: return buff.getLong(end); // We are passing signed long here. Losing information (user should know) - default: return -1; // we should never reach here - } - } - - // read signed int of size byteWidth and return as 32-bit int - private static int readInt(ReadBuf buff, int end, int byteWidth) { - return (int) readLong(buff, end, byteWidth); - } - - // read signed int of size byteWidth and return as 64-bit int - private static long readLong(ReadBuf buff, int end, int byteWidth) { - switch (byteWidth) { - case 1: return buff.get(end); - case 2: return buff.getShort(end); - case 4: return buff.getInt(end); - case 8: return buff.getLong(end); - default: return -1; // we should never reach here - } - } - - private static double readDouble(ReadBuf buff, int end, int byteWidth) { - switch (byteWidth) { - case 4: return buff.getFloat(end); - case 8: return buff.getDouble(end); - default: return -1; // we should never reach here - } - } - - /** - * Reads a FlexBuffer message in ReadBuf and returns {@link Reference} to - * the root element. - * @param buffer ReadBuf containing FlexBuffer message - * @return {@link Reference} to the root object - */ - @Deprecated - public static Reference getRoot(ByteBuffer buffer) { - return getRoot( buffer.hasArray() ? new ArrayReadWriteBuf(buffer.array(), buffer.limit()) : new ByteBufferReadWriteBuf(buffer)); - } - - /** - * Reads a FlexBuffer message in ReadBuf and returns {@link Reference} to - * the root element. - * @param buffer ReadBuf containing FlexBuffer message - * @return {@link Reference} to the root object - */ - public static Reference getRoot(ReadBuf buffer) { - // See Finish() below for the serialization counterpart of this. - // The root ends at the end of the buffer, so we parse backwards from there. - int end = buffer.limit(); - int byteWidth = buffer.get(--end); - int packetType = byteToUnsignedInt(buffer.get(--end)); - end -= byteWidth; // The root data item. - return new Reference(buffer, end, byteWidth, packetType); - } - - /** - * Represents an generic element in the buffer. - */ - public static class Reference { - - private static final Reference NULL_REFERENCE = new Reference(EMPTY_BB, 0, 1, 0); - private ReadBuf bb; - private int end; - private int parentWidth; - private int byteWidth; - private int type; - - Reference(ReadBuf bb, int end, int parentWidth, int packedType) { - this(bb, end, parentWidth, (1 << (packedType & 3)), packedType >> 2); - } - - Reference(ReadBuf bb, int end, int parentWidth, int byteWidth, int type) { - this.bb = bb; - this.end = end; - this.parentWidth = parentWidth; - this.byteWidth = byteWidth; - this.type = type; - } - - /** - * Return element type - * @return element type as integer - */ - public int getType() { - return type; - } - - /** - * Checks whether the element is null type - * @return true if null type - */ - public boolean isNull() { - return type == FBT_NULL; - } - - /** - * Checks whether the element is boolean type - * @return true if boolean type - */ - public boolean isBoolean() { - return type == FBT_BOOL; - } - - /** - * Checks whether the element type is numeric (signed/unsigned integers and floats) - * @return true if numeric type - */ - public boolean isNumeric() { - return isIntOrUInt() || isFloat(); - } - - /** - * Checks whether the element type is signed or unsigned integers - * @return true if an integer type - */ - public boolean isIntOrUInt() { - return isInt() || isUInt(); - } - - /** - * Checks whether the element type is float - * @return true if a float type - */ - public boolean isFloat() { - return type == FBT_FLOAT || type == FBT_INDIRECT_FLOAT; - } - - /** - * Checks whether the element type is signed integer - * @return true if a signed integer type - */ - public boolean isInt() { - return type == FBT_INT || type == FBT_INDIRECT_INT; - } - - /** - * Checks whether the element type is signed integer - * @return true if a signed integer type - */ - public boolean isUInt() { - return type == FBT_UINT || type == FBT_INDIRECT_UINT; - } - - /** - * Checks whether the element type is string - * @return true if a string type - */ - public boolean isString() { - return type == FBT_STRING; - } - - /** - * Checks whether the element type is key - * @return true if a key type - */ - public boolean isKey() { - return type == FBT_KEY; - } - - /** - * Checks whether the element type is vector - * @return true if a vector type - */ - public boolean isVector() { - return type == FBT_VECTOR || type == FBT_MAP; - } - - /** - * Checks whether the element type is typed vector - * @return true if a typed vector type - */ - public boolean isTypedVector() { - return FlexBuffers.isTypedVector(type); - } - - /** - * Checks whether the element type is a map - * @return true if a map type - */ - public boolean isMap() { - return type == FBT_MAP; - } - - /** - * Checks whether the element type is a blob - * @return true if a blob type - */ - public boolean isBlob() { - return type == FBT_BLOB; - } - - /** - * Returns element as 32-bit integer. - *

For vector element, it will return size of the vector

- *

For String element, it will type to be parsed as integer

- *

Unsigned elements will become negative

- *

Float elements will be casted to integer

- * @return 32-bit integer or 0 if fail to convert element to integer. - */ - public int asInt() { - if (type == FBT_INT) { - // A fast path for the common case. - return readInt(bb, end, parentWidth); - } else - switch (type) { - case FBT_INDIRECT_INT: return readInt(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_UINT: return (int) readUInt(bb, end, parentWidth); - case FBT_INDIRECT_UINT: return (int) readUInt(bb, indirect(bb, end, parentWidth), parentWidth); - case FBT_FLOAT: return (int) readDouble(bb, end, parentWidth); - case FBT_INDIRECT_FLOAT: return (int) readDouble(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_NULL: return 0; - case FBT_STRING: return Integer.parseInt(asString()); - case FBT_VECTOR: return asVector().size(); - case FBT_BOOL: return readInt(bb, end, parentWidth); - default: - // Convert other things to int. - return 0; - } - } - - /** - * Returns element as unsigned 64-bit integer. - *

For vector element, it will return size of the vector

- *

For String element, it will type to be parsed as integer

- *

Negative signed elements will become unsigned counterpart

- *

Float elements will be casted to integer

- * @return 64-bit integer or 0 if fail to convert element to integer. - */ - public long asUInt() { - if (type == FBT_UINT) { - // A fast path for the common case. - return readUInt(bb, end, parentWidth); - } else - switch (type) { - case FBT_INDIRECT_UINT: return readUInt(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_INT: return readLong(bb, end, parentWidth); - case FBT_INDIRECT_INT: return readLong(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_FLOAT: return (long) readDouble(bb, end, parentWidth); - case FBT_INDIRECT_FLOAT: return (long) readDouble(bb, indirect(bb, end, parentWidth), parentWidth); - case FBT_NULL: return 0; - case FBT_STRING: return Long.parseLong(asString()); - case FBT_VECTOR: return asVector().size(); - case FBT_BOOL: return readInt(bb, end, parentWidth); - default: - // Convert other things to uint. - return 0; - } - } - - /** - * Returns element as 64-bit integer. - *

For vector element, it will return size of the vector

- *

For String element, it will type to be parsed as integer

- *

Unsigned elements will become negative

- *

Float elements will be casted to integer

- * @return 64-bit integer or 0 if fail to convert element to long. - */ - public long asLong() { - if (type == FBT_INT) { - // A fast path for the common case. - return readLong(bb, end, parentWidth); - } else - switch (type) { - case FBT_INDIRECT_INT: return readLong(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_UINT: return readUInt(bb, end, parentWidth); - case FBT_INDIRECT_UINT: return readUInt(bb, indirect(bb, end, parentWidth), parentWidth); - case FBT_FLOAT: return (long) readDouble(bb, end, parentWidth); - case FBT_INDIRECT_FLOAT: return (long) readDouble(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_NULL: return 0; - case FBT_STRING: { - try { - return Long.parseLong(asString()); - } catch (NumberFormatException nfe) { - return 0; //same as C++ implementation - } - } - case FBT_VECTOR: return asVector().size(); - case FBT_BOOL: return readInt(bb, end, parentWidth); - default: - // Convert other things to int. - return 0; - } - } - - /** - * Returns element as 64-bit integer. - *

For vector element, it will return size of the vector

- *

For String element, it will type to be parsed as integer

- * @return 64-bit integer or 0 if fail to convert element to long. - */ - public double asFloat() { - if (type == FBT_FLOAT) { - // A fast path for the common case. - return readDouble(bb, end, parentWidth); - } else - switch (type) { - case FBT_INDIRECT_FLOAT: return readDouble(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_INT: return readInt(bb, end, parentWidth); - case FBT_UINT: - case FBT_BOOL: - return readUInt(bb, end, parentWidth); - case FBT_INDIRECT_INT: return readInt(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_INDIRECT_UINT: return readUInt(bb, indirect(bb, end, parentWidth), byteWidth); - case FBT_NULL: return 0.0; - case FBT_STRING: return Double.parseDouble(asString()); - case FBT_VECTOR: return asVector().size(); - default: - // Convert strings and other things to float. - return 0; - } - } - - /** - * Returns element as a {@link Key} - * @return key or {@link Key#empty()} if element is not a key - */ - public Key asKey() { - if (isKey()) { - return new Key(bb, indirect(bb, end, parentWidth), byteWidth); - } else { - return Key.empty(); - } - } - - /** - * Returns element as a `String` - * @return element as `String` or empty `String` if fail - */ - public String asString() { - if (isString()) { - int start = indirect(bb, end, parentWidth); - int size = (int) readUInt(bb, start - byteWidth, byteWidth); - return bb.getString(start, size); - } - else if (isKey()){ - int start = indirect(bb, end, byteWidth); - for (int i = start; ; i++) { - if (bb.get(i) == 0) { - return bb.getString(start, i - start); - } - } - } else { - return ""; - } - } - - /** - * Returns element as a {@link Map} - * @return element as {@link Map} or empty {@link Map} if fail - */ - public Map asMap() { - if (isMap()) { - return new Map(bb, indirect(bb, end, parentWidth), byteWidth); - } else { - return Map.empty(); - } - } - - /** - * Returns element as a {@link Vector} - * @return element as {@link Vector} or empty {@link Vector} if fail - */ - public Vector asVector() { - if (isVector()) { - return new Vector(bb, indirect(bb, end, parentWidth), byteWidth); - } else if(type == FlexBuffers.FBT_VECTOR_STRING_DEPRECATED) { - // deprecated. Should be treated as key vector - return new TypedVector(bb, indirect(bb, end, parentWidth), byteWidth, FlexBuffers.FBT_KEY); - } else if (FlexBuffers.isTypedVector(type)) { - return new TypedVector(bb, indirect(bb, end, parentWidth), byteWidth, FlexBuffers.toTypedVectorElementType(type)); - } else { - return Vector.empty(); - } - } - - /** - * Returns element as a {@link Blob} - * @return element as {@link Blob} or empty {@link Blob} if fail - */ - public Blob asBlob() { - if (isBlob() || isString()) { - return new Blob(bb, indirect(bb, end, parentWidth), byteWidth); - } else { - return Blob.empty(); - } - } - - /** - * Returns element as a boolean - *

If element type is not boolean, it will be casted to integer and compared against 0

- * @return element as boolean - */ - public boolean asBoolean() { - if (isBoolean()) { - return bb.get(end) != 0; - } - return asUInt() != 0; - } - - /** - * Returns text representation of the element (JSON) - * @return String containing text representation of the element - */ - @Override - public String toString() { - return toString(new StringBuilder(128)).toString(); - } - - /** - * Appends a text(JSON) representation to a `StringBuilder` - */ - StringBuilder toString(StringBuilder sb) { - //TODO: Original C++ implementation escape strings. - // probably we should do it as well. - switch (type) { - case FBT_NULL: - return sb.append("null"); - case FBT_INT: - case FBT_INDIRECT_INT: - return sb.append(asLong()); - case FBT_UINT: - case FBT_INDIRECT_UINT: - return sb.append(asUInt()); - case FBT_INDIRECT_FLOAT: - case FBT_FLOAT: - return sb.append(asFloat()); - case FBT_KEY: - return asKey().toString(sb.append('"')).append('"'); - case FBT_STRING: - return sb.append('"').append(asString()).append('"'); - case FBT_MAP: - return asMap().toString(sb); - case FBT_VECTOR: - return asVector().toString(sb); - case FBT_BLOB: - return asBlob().toString(sb); - case FBT_BOOL: - return sb.append(asBoolean()); - case FBT_VECTOR_INT: - case FBT_VECTOR_UINT: - case FBT_VECTOR_FLOAT: - case FBT_VECTOR_KEY: - case FBT_VECTOR_STRING_DEPRECATED: - case FBT_VECTOR_BOOL: - return sb.append(asVector()); - case FBT_VECTOR_INT2: - case FBT_VECTOR_UINT2: - case FBT_VECTOR_FLOAT2: - case FBT_VECTOR_INT3: - case FBT_VECTOR_UINT3: - case FBT_VECTOR_FLOAT3: - case FBT_VECTOR_INT4: - case FBT_VECTOR_UINT4: - case FBT_VECTOR_FLOAT4: - - throw new FlexBufferException("not_implemented:" + type); - default: - return sb; - } - } - } - - /** - * Base class of all types below. - * Points into the data buffer and allows access to one type. - */ - private static abstract class Object { - ReadBuf bb; - int end; - int byteWidth; - - Object(ReadBuf buff, int end, int byteWidth) { - this.bb = buff; - this.end = end; - this.byteWidth = byteWidth; - } - - @Override - public String toString() { - return toString(new StringBuilder(128)).toString(); - } - - public abstract StringBuilder toString(StringBuilder sb); - } - - // Stores size in `byte_width_` bytes before end position. - private static abstract class Sized extends Object { - - protected final int size; - - Sized(ReadBuf buff, int end, int byteWidth) { - super(buff, end, byteWidth); - size = (int) readUInt(bb, end - byteWidth, byteWidth); - } - - public int size() { - return size; - } - } - - /** - * Represents a array of bytes element in the buffer - * - *

It can be converted to `ReadBuf` using {@link data()}, - * copied into a byte[] using {@link getBytes()} or - * have individual bytes accessed individually using {@link get(int)}

- */ - public static class Blob extends Sized { - static final Blob EMPTY = new Blob(EMPTY_BB, 1, 1); - - Blob(ReadBuf buff, int end, int byteWidth) { - super(buff, end, byteWidth); - } - - /** Return an empty {@link Blob} */ - public static Blob empty() { - return EMPTY; - } - - /** - * Return {@link Blob} as `ReadBuf` - * @return blob as `ReadBuf` - */ - public ByteBuffer data() { - ByteBuffer dup = ByteBuffer.wrap(bb.data()); - dup.position(end); - dup.limit(end + size()); - return dup.asReadOnlyBuffer().slice(); - } - - /** - * Copy blob into a byte[] - * @return blob as a byte[] - */ - public byte[] getBytes() { - int size = size(); - byte[] result = new byte[size]; - for (int i = 0; i < size; i++) { - result[i] = bb.get(end + i); - } - return result; - } - - /** - * Return individual byte at a given position - * @param pos position of the byte to be read - */ - public byte get(int pos) { - assert pos >=0 && pos <= size(); - return bb.get(end + pos); - } - - /** - * Returns a text(JSON) representation of the {@link Blob} - */ - @Override - public String toString() { - return bb.getString(end, size()); - } - - /** - * Append a text(JSON) representation of the {@link Blob} into a `StringBuilder` - */ - @Override - public StringBuilder toString(StringBuilder sb) { - sb.append('"'); - sb.append(bb.getString(end, size())); - return sb.append('"'); - } - } - - /** - * Represents a key element in the buffer. Keys are - * used to reference objects in a {@link Map} - */ - public static class Key extends Object { - - private static final Key EMPTY = new Key(EMPTY_BB, 0, 0); - - Key(ReadBuf buff, int end, int byteWidth) { - super(buff, end, byteWidth); - } - - /** - * Return an empty {@link Key} - * @return empty {@link Key} - * */ - public static Key empty() { - return Key.EMPTY; - } - - /** - * Appends a text(JSON) representation to a `StringBuilder` - */ - @Override - public StringBuilder toString(StringBuilder sb) { - return sb.append(toString()); - } - - @Override - public String toString() { - int size; - for (int i = end; ; i++) { - if (bb.get(i) == 0) { - size = i - end; - break; - } - } - return bb.getString(end, size); - } - - int compareTo(byte[] other) { - int ia = end; - int io = 0; - byte c1, c2; - do { - c1 = bb.get(ia); - c2 = other[io]; - if (c1 == '\0') - return c1 - c2; - ia++; - io++; - if (io == other.length) { - // in our buffer we have an additional \0 byte - // but this does not exist in regular Java strings, so we return now - int cmp = c1 - c2; - if (cmp != 0 || bb.get(ia) == '\0') { - return cmp; - } else { - return 1; - } - } - } - while (c1 == c2); - return c1 - c2; - } - - /** - * Compare keys - * @param obj other key to compare - * @return true if keys are the same - */ - @Override - public boolean equals(java.lang.Object obj) { - if (!(obj instanceof Key)) - return false; - - return ((Key) obj).end == end && ((Key) obj).byteWidth == byteWidth; - } - - public int hashCode() { - return end ^ byteWidth; - } - } - - /** - * Map object representing a set of key-value pairs. - */ - public static class Map extends Vector { - private static final Map EMPTY_MAP = new Map(EMPTY_BB, 1, 1); - // cache for converting UTF-8 codepoints into - // Java chars. Used to speed up String comparison - private final byte[] comparisonBuffer = new byte[4]; - - Map(ReadBuf bb, int end, int byteWidth) { - super(bb, end, byteWidth); - } - - /** - * Returns an empty {@link Map} - * @return an empty {@link Map} - */ - public static Map empty() { - return EMPTY_MAP; - } - - /** - * @param key access key to element on map - * @return reference to value in map - */ - public Reference get(String key) { - int index = binarySearch(key); - if (index >= 0 && index < size) { - return get(index); - } - return Reference.NULL_REFERENCE; - } - - /** - * @param key access key to element on map. Keys are assumed to be encoded in UTF-8 - * @return reference to value in map - */ - public Reference get(byte[] key) { - int index = binarySearch(key); - if (index >= 0 && index < size) { - return get(index); - } - return Reference.NULL_REFERENCE; - } - - /** - * Get a vector or keys in the map - * - * @return vector of keys - */ - public KeyVector keys() { - final int num_prefixed_fields = 3; - int keysOffset = end - (byteWidth * num_prefixed_fields); - return new KeyVector(new TypedVector(bb, - indirect(bb, keysOffset, byteWidth), - readInt(bb, keysOffset + byteWidth, byteWidth), - FBT_KEY)); - } - - /** - * @return {@code Vector} of values from map - */ - public Vector values() { - return new Vector(bb, end, byteWidth); - } - - /** - * Writes text (json) representation of map in a {@code StringBuilder}. - * - * @param builder {@code StringBuilder} to be appended to - * @return Same {@code StringBuilder} with appended text - */ - public StringBuilder toString(StringBuilder builder) { - builder.append("{ "); - KeyVector keys = keys(); - int size = size(); - Vector vals = values(); - for (int i = 0; i < size; i++) { - builder.append('"') - .append(keys.get(i).toString()) - .append("\" : "); - builder.append(vals.get(i).toString()); - if (i != size - 1) - builder.append(", "); - } - builder.append(" }"); - return builder; - } - - // Performs a binary search on a key vector and return index of the key in key vector - private int binarySearch(CharSequence searchedKey) { - int low = 0; - int high = size - 1; - final int num_prefixed_fields = 3; - int keysOffset = end - (byteWidth * num_prefixed_fields); - int keysStart = indirect(bb, keysOffset, byteWidth); - int keyByteWidth = readInt(bb, keysOffset + byteWidth, byteWidth); - while (low <= high) { - int mid = (low + high) >>> 1; - int keyPos = indirect(bb, keysStart + mid * keyByteWidth, keyByteWidth); - int cmp = compareCharSequence(keyPos, searchedKey); - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid - 1; - else - return mid; // key found - } - return -(low + 1); // key not found - } - - private int binarySearch(byte[] searchedKey) { - int low = 0; - int high = size - 1; - final int num_prefixed_fields = 3; - int keysOffset = end - (byteWidth * num_prefixed_fields); - int keysStart = indirect(bb, keysOffset, byteWidth); - int keyByteWidth = readInt(bb, keysOffset + byteWidth, byteWidth); - - while (low <= high) { - int mid = (low + high) >>> 1; - int keyPos = indirect(bb, keysStart + mid * keyByteWidth, keyByteWidth); - int cmp = compareBytes(bb, keyPos, searchedKey); - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid - 1; - else - return mid; // key found - } - return -(low + 1); // key not found - } - - // compares a byte[] against a FBT_KEY - private int compareBytes(ReadBuf bb, int start, byte[] other) { - int l1 = start; - int l2 = 0; - byte c1, c2; - do { - c1 = bb.get(l1); - c2 = other[l2]; - if (c1 == '\0') - return c1 - c2; - l1++; - l2++; - if (l2 == other.length) { - // in our buffer we have an additional \0 byte - // but this does not exist in regular Java strings, so we return now - int cmp = c1 - c2; - if (cmp != 0 || bb.get(l1) == '\0') { - return cmp; - } else { - return 1; - } - } - } - while (c1 == c2); - return c1 - c2; - } - - // compares a CharSequence against a FBT_KEY - private int compareCharSequence(int start, CharSequence other) { - int bufferPos = start; - int otherPos = 0; - int limit = bb.limit(); - int otherLimit = other.length(); - - // special loop for ASCII characters. Most of keys should be ASCII only, so this - // loop should be optimized for that. - // breaks if a multi-byte character is found - while (otherPos < otherLimit) { - char c2 = other.charAt(otherPos); - - if (c2 >= 0x80) { - // not a single byte codepoint - break; - } - - byte b = bb.get(bufferPos); - - if (b == 0) { - return -c2; - } else if (b < 0) { - break; - } else if ((char) b != c2) { - return b - c2; - } - ++bufferPos; - ++otherPos; - } - - while (bufferPos < limit) { - - int sizeInBuff = Utf8.encodeUtf8CodePoint(other, otherPos, comparisonBuffer); - - if (sizeInBuff == 0) { - // That means we finish with other and there are not more chars to - // compare. String in the buffer is bigger. - return bb.get(bufferPos); - } - - for (int i = 0; i < sizeInBuff; i++) { - byte bufferByte = bb.get(bufferPos++); - byte otherByte = comparisonBuffer[i]; - if (bufferByte == 0) { - // Our key is finished, so other is bigger - return -otherByte; - } else if (bufferByte != otherByte) { - return bufferByte - otherByte; - } - } - - otherPos += sizeInBuff == 4 ? 2 : 1; - } - return 0; - } - } - - /** - * Object that represents a set of elements in the buffer - */ - public static class Vector extends Sized { - - private static final Vector EMPTY_VECTOR = new Vector(EMPTY_BB, 1, 1); - - Vector(ReadBuf bb, int end, int byteWidth) { - super(bb, end, byteWidth); - } - - /** - * Returns an empty {@link Map} - * @return an empty {@link Map} - */ - public static Vector empty() { - return EMPTY_VECTOR; - } - - /** - * Checks if the vector is empty - * @return true if vector is empty - */ - public boolean isEmpty() { - return this == EMPTY_VECTOR; - } - - /** - * Appends a text(JSON) representation to a `StringBuilder` - */ - @Override - public StringBuilder toString(StringBuilder sb) { - sb.append("[ "); - int size = size(); - for (int i = 0; i < size; i++) { - get(i).toString(sb); - if (i != size - 1) { - sb.append(", "); - } - } - sb.append(" ]"); - return sb; - } - - /** - * Get a element in a vector by index - * - * @param index position of the element - * @return {@code Reference} to the element - */ - public Reference get(int index) { - long len = size(); - if (index >= len) { - return Reference.NULL_REFERENCE; - } - int packedType = byteToUnsignedInt(bb.get((int) (end + (len * byteWidth) + index))); - int obj_end = end + index * byteWidth; - return new Reference(bb, obj_end, byteWidth, packedType); - } - } - - /** - * Object that represents a set of elements with the same type - */ - public static class TypedVector extends Vector { - - private static final TypedVector EMPTY_VECTOR = new TypedVector(EMPTY_BB, 1, 1, FBT_INT); - - private final int elemType; - - TypedVector(ReadBuf bb, int end, int byteWidth, int elemType) { - super(bb, end, byteWidth); - this.elemType = elemType; - } - - public static TypedVector empty() { - return EMPTY_VECTOR; - } - - /** - * Returns whether the vector is empty - * - * @return true if empty - */ - public boolean isEmptyVector() { - return this == EMPTY_VECTOR; - } - - /** - * Return element type for all elements in the vector - * - * @return element type - */ - public int getElemType() { - return elemType; - } - - /** - * Get reference to an object in the {@code Vector} - * - * @param pos position of the object in {@code Vector} - * @return reference to element - */ - @Override - public Reference get(int pos) { - int len = size(); - if (pos >= len) return Reference.NULL_REFERENCE; - int childPos = end + pos * byteWidth; - return new Reference(bb, childPos, byteWidth, 1, elemType); - } - } - - /** - * Represent a vector of keys in a map - */ - public static class KeyVector { - - private final TypedVector vec; - - KeyVector(TypedVector vec) { - this.vec = vec; - } - - /** - * Return key - * - * @param pos position of the key in key vector - * @return key - */ - public Key get(int pos) { - int len = size(); - if (pos >= len) return Key.EMPTY; - int childPos = vec.end + pos * vec.byteWidth; - return new Key(vec.bb, indirect(vec.bb, childPos, vec.byteWidth), 1); - } - - /** - * Returns size of key vector - * - * @return size - */ - public int size() { - return vec.size(); - } - - /** - * Returns a text(JSON) representation - */ - public String toString() { - StringBuilder b = new StringBuilder(); - b.append('['); - for (int i = 0; i < vec.size(); i++) { - vec.get(i).toString(b); - if (i != vec.size() - 1) { - b.append(", "); - } - } - return b.append("]").toString(); - } - } - - public static class FlexBufferException extends RuntimeException { - FlexBufferException(String msg) { - super(msg); - } - } - - static class Unsigned { - - static int byteToUnsignedInt(byte x) { - return ((int) x) & 0xff; - } - - static int shortToUnsignedInt(short x) { - return ((int) x) & 0xffff; - } - - static long intToUnsignedLong(int x) { - return ((long) x) & 0xffffffffL; - } - } -} -/// @} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffersBuilder.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffersBuilder.java deleted file mode 100644 index 60ab5355a..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FlexBuffersBuilder.java +++ /dev/null @@ -1,802 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; - -import static com.google.flatbuffers.FlexBuffers.*; -import static com.google.flatbuffers.FlexBuffers.Unsigned.byteToUnsignedInt; -import static com.google.flatbuffers.FlexBuffers.Unsigned.intToUnsignedLong; -import static com.google.flatbuffers.FlexBuffers.Unsigned.shortToUnsignedInt; - -/// @file -/// @addtogroup flatbuffers_java_api -/// @{ - -/** - * Helper class that builds FlexBuffers - *

This class presents all necessary APIs to create FlexBuffers. A `ByteBuffer` will be used to store the - * data. It can be created internally, or passed down in the constructor.

- * - *

There are some limitations when compared to original implementation in C++. Most notably: - *

    - *
  • No support for mutations (might change in the future).

  • - *
  • Buffer size limited to {@link Integer#MAX_VALUE}

  • - *
  • Since Java does not support unsigned type, all unsigned operations accepts an immediate higher representation - * of similar type.

  • - *
- *

- */ -public class FlexBuffersBuilder { - - /** - * No keys or strings will be shared - */ - public static final int BUILDER_FLAG_NONE = 0; - /** - * Keys will be shared between elements. Identical keys will only be serialized once, thus possibly saving space. - * But serialization performance might be slower and consumes more memory. - */ - public static final int BUILDER_FLAG_SHARE_KEYS = 1; - /** - * Strings will be shared between elements. Identical strings will only be serialized once, thus possibly saving space. - * But serialization performance might be slower and consumes more memory. This is ideal if you expect many repeated - * strings on the message. - */ - public static final int BUILDER_FLAG_SHARE_STRINGS = 2; - /** - * Strings and keys will be shared between elements. - */ - public static final int BUILDER_FLAG_SHARE_KEYS_AND_STRINGS = 3; - /** - * Reserved for the future. - */ - public static final int BUILDER_FLAG_SHARE_KEY_VECTORS = 4; - /** - * Reserved for the future. - */ - public static final int BUILDER_FLAG_SHARE_ALL = 7; - - /// @cond FLATBUFFERS_INTERNAL - private static final int WIDTH_8 = 0; - private static final int WIDTH_16 = 1; - private static final int WIDTH_32 = 2; - private static final int WIDTH_64 = 3; - private final ReadWriteBuf bb; - private final ArrayList stack = new ArrayList<>(); - private final HashMap keyPool = new HashMap<>(); - private final HashMap stringPool = new HashMap<>(); - private final int flags; - private boolean finished = false; - - // A lambda to sort map keys - private Comparator keyComparator = new Comparator() { - @Override - public int compare(Value o1, Value o2) { - int ia = o1.key; - int io = o2.key; - byte c1, c2; - do { - c1 = bb.get(ia); - c2 = bb.get(io); - if (c1 == 0) - return c1 - c2; - ia++; - io++; - } - while (c1 == c2); - return c1 - c2; - } - }; - /// @endcond - - /** - * Constructs a newly allocated {@code FlexBuffersBuilder} with {@link #BUILDER_FLAG_SHARE_KEYS} set. - * @param bufSize size of buffer in bytes. - */ - public FlexBuffersBuilder(int bufSize) { - this(new ArrayReadWriteBuf(bufSize), BUILDER_FLAG_SHARE_KEYS); - } - - /** - * Constructs a newly allocated {@code FlexBuffersBuilder} with {@link #BUILDER_FLAG_SHARE_KEYS} set. - */ - public FlexBuffersBuilder() { - this(256); - } - - /** - * Constructs a newly allocated {@code FlexBuffersBuilder}. - * - * @param bb `ByteBuffer` that will hold the message - * @param flags Share flags - */ - @Deprecated - public FlexBuffersBuilder(ByteBuffer bb, int flags) { - this(new ArrayReadWriteBuf(bb.array()), flags); - } - - public FlexBuffersBuilder(ReadWriteBuf bb, int flags) { - this.bb = bb; - this.flags = flags; - } - - /** - * Constructs a newly allocated {@code FlexBuffersBuilder}. - * By default same keys will be serialized only once - * @param bb `ByteBuffer` that will hold the message - */ - public FlexBuffersBuilder(ByteBuffer bb) { - this(bb, BUILDER_FLAG_SHARE_KEYS); - } - - /** - * Reset the FlexBuffersBuilder by purging all data that it holds. - */ - public void clear(){ - bb.clear(); - stack.clear(); - keyPool.clear(); - stringPool.clear(); - finished = false; - } - - /** - * Return `ByteBuffer` containing FlexBuffer message. {@code #finish()} must be called before calling this - * function otherwise an assert will trigger. - * - * @return `ByteBuffer` with finished message - */ - public ReadWriteBuf getBuffer() { - assert (finished); - return bb; - } - - /** - * Insert a null value into the buffer - */ - public void putNull() { - putNull(null); - } - - /** - * Insert a null value into the buffer - * @param key key used to store element in map - */ - public void putNull(String key) { - stack.add(Value.nullValue(putKey(key))); - } - - /** - * Insert a single boolean into the buffer - * @param val true or false - */ - public void putBoolean(boolean val) { - putBoolean(null, val); - } - - /** - * Insert a single boolean into the buffer - * @param key key used to store element in map - * @param val true or false - */ - public void putBoolean(String key, boolean val) { - stack.add(Value.bool(putKey(key), val)); - } - - private int putKey(String key) { - if (key == null) { - return -1; - } - int pos = bb.writePosition(); - if ((flags & BUILDER_FLAG_SHARE_KEYS) != 0) { - Integer keyFromPool = keyPool.get(key); - if (keyFromPool == null) { - byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); - bb.put(keyBytes, 0, keyBytes.length); - bb.put((byte) 0); - keyPool.put(key, pos); - } else { - pos = keyFromPool; - } - } else { - byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); - bb.put(keyBytes, 0, keyBytes.length); - bb.put((byte) 0); - keyPool.put(key, pos); - } - return pos; - } - - /** - * Adds a integer into the buff - * @param val integer - */ - public void putInt(int val) { - putInt(null, val); - } - - /** - * Adds a integer into the buff - * @param key key used to store element in map - * @param val integer - */ - public void putInt(String key, int val) { - putInt(key, (long) val); - } - - /** - * Adds a integer into the buff - * @param key key used to store element in map - * @param val 64-bit integer - */ - public void putInt(String key, long val) { - int iKey = putKey(key); - if (Byte.MIN_VALUE <= val && val <= Byte.MAX_VALUE) { - stack.add(Value.int8(iKey, (int) val)); - } else if (Short.MIN_VALUE <= val && val <= Short.MAX_VALUE) { - stack.add(Value.int16(iKey, (int) val)); - } else if (Integer.MIN_VALUE <= val && val <= Integer.MAX_VALUE) { - stack.add(Value.int32(iKey, (int) val)); - } else { - stack.add(Value.int64(iKey, val)); - } - } - - /** - * Adds a 64-bit integer into the buff - * @param value integer - */ - public void putInt(long value) { - putInt(null, value); - } - - /** - * Adds a unsigned integer into the buff. - * @param value integer representing unsigned value - */ - public void putUInt(int value) { - putUInt(null, (long) value); - } - - /** - * Adds a unsigned integer (stored in a signed 64-bit integer) into the buff. - * @param value integer representing unsigned value - */ - public void putUInt(long value) { - putUInt(null, value); - } - - /** - * Adds a 64-bit unsigned integer (stored as {@link BigInteger}) into the buff. - * Warning: This operation might be very slow. - * @param value integer representing unsigned value - */ - public void putUInt64(BigInteger value) { - putUInt64(null, value.longValue()); - } - - private void putUInt64(String key, long value) { - stack.add(Value.uInt64(putKey(key), value)); - } - - private void putUInt(String key, long value) { - int iKey = putKey(key); - Value vVal; - - int width = widthUInBits(value); - - if (width == WIDTH_8) { - vVal = Value.uInt8(iKey, (int)value); - } else if (width == WIDTH_16) { - vVal = Value.uInt16(iKey, (int)value); - } else if (width == WIDTH_32) { - vVal = Value.uInt32(iKey, (int)value); - } else { - vVal = Value.uInt64(iKey, value); - } - stack.add(vVal); - } - - /** - * Adds a 32-bit float into the buff. - * @param value float representing value - */ - public void putFloat(float value) { - putFloat(null, value); - } - - /** - * Adds a 32-bit float into the buff. - * @param key key used to store element in map - * @param value float representing value - */ - public void putFloat(String key, float val) { - stack.add(Value.float32(putKey(key), val)); - } - - /** - * Adds a 64-bit float into the buff. - * @param value float representing value - */ - public void putFloat(double value) { - putFloat(null, value); - } - - /** - * Adds a 64-bit float into the buff. - * @param key key used to store element in map - * @param value float representing value - */ - public void putFloat(String key, double val) { - stack.add(Value.float64(putKey(key), val)); - } - - /** - * Adds a String into the buffer - * @param value string - * @return start position of string in the buffer - */ - public int putString(String value) { - return putString(null, value); - } - - /** - * Adds a String into the buffer - * @param key key used to store element in map - * @param value string - * @return start position of string in the buffer - */ - public int putString(String key, String val) { - int iKey = putKey(key); - if ((flags & FlexBuffersBuilder.BUILDER_FLAG_SHARE_STRINGS) != 0) { - Integer i = stringPool.get(val); - if (i == null) { - Value value = writeString(iKey, val); - stringPool.put(val, (int) value.iValue); - stack.add(value); - return (int) value.iValue; - } else { - int bitWidth = widthUInBits(val.length()); - stack.add(Value.blob(iKey, i, FBT_STRING, bitWidth)); - return i; - } - } else { - Value value = writeString(iKey, val); - stack.add(value); - return (int) value.iValue; - } - } - - private Value writeString(int key, String s) { - return writeBlob(key, s.getBytes(StandardCharsets.UTF_8), FBT_STRING, true); - } - - // in bits to fit a unsigned int - static int widthUInBits(long len) { - if (len <= byteToUnsignedInt((byte)0xff)) return WIDTH_8; - if (len <= shortToUnsignedInt((short)0xffff)) return WIDTH_16; - if (len <= intToUnsignedLong(0xffff_ffff)) return WIDTH_32; - return WIDTH_64; - } - - private Value writeBlob(int key, byte[] blob, int type, boolean trailing) { - int bitWidth = widthUInBits(blob.length); - int byteWidth = align(bitWidth); - writeInt(blob.length, byteWidth); - int sloc = bb.writePosition(); - bb.put(blob, 0, blob.length); - if (trailing) { - bb.put((byte) 0); - } - return Value.blob(key, sloc, type, bitWidth); - } - - // Align to prepare for writing a scalar with a certain size. - private int align(int alignment) { - int byteWidth = 1 << alignment; - int padBytes = Value.paddingBytes(bb.writePosition(), byteWidth); - while (padBytes-- != 0) { - bb.put((byte) 0); - } - return byteWidth; - } - - private void writeInt(long value, int byteWidth) { - switch (byteWidth) { - case 1: bb.put((byte) value); break; - case 2: bb.putShort((short) value); break; - case 4: bb.putInt((int) value); break; - case 8: bb.putLong(value); break; - } - } - - /** - * Adds a byte array into the message - * @param value byte array - * @return position in buffer as the start of byte array - */ - public int putBlob(byte[] value) { - return putBlob(null, value); - } - - /** - * Adds a byte array into the message - * @param key key used to store element in map - * @param value byte array - * @return position in buffer as the start of byte array - */ - public int putBlob(String key, byte[] val) { - int iKey = putKey(key); - Value value = writeBlob(iKey, val, FBT_BLOB, false); - stack.add(value); - return (int) value.iValue; - } - - /** - * Start a new vector in the buffer. - * @return a reference indicating position of the vector in buffer. This - * reference must be passed along when the vector is finished using endVector() - */ - public int startVector() { - return stack.size(); - } - - /** - * Finishes a vector, but writing the information in the buffer - * @param key key used to store element in map - * @param start reference for beginning of the vector. Returned by {@link startVector()} - * @param typed boolean indicating whether vector is typed - * @param fixed boolean indicating whether vector is fixed - * @return Reference to the vector - */ - public int endVector(String key, int start, boolean typed, boolean fixed) { - int iKey = putKey(key); - Value vec = createVector(iKey, start, stack.size() - start, typed, fixed, null); - // Remove temp elements and return vector. - while (stack.size() > start) { - stack.remove(stack.size() - 1); - } - stack.add(vec); - return (int) vec.iValue; - } - - /** - * Finish writing the message into the buffer. After that no other element must - * be inserted into the buffer. Also, you must call this function before start using the - * FlexBuffer message - * @return `ByteBuffer` containing the FlexBuffer message - */ - public ByteBuffer finish() { - // If you hit this assert, you likely have objects that were never included - // in a parent. You need to have exactly one root to finish a buffer. - // Check your Start/End calls are matched, and all objects are inside - // some other object. - assert (stack.size() == 1); - // Write root value. - int byteWidth = align(stack.get(0).elemWidth(bb.writePosition(), 0)); - writeAny(stack.get(0), byteWidth); - // Write root type. - bb.put(stack.get(0).storedPackedType()); - // Write root size. Normally determined by parent, but root has no parent :) - bb.put((byte) byteWidth); - this.finished = true; - return ByteBuffer.wrap(bb.data(), 0, bb.writePosition()); - } - - /* - * Create a vector based on the elements stored in the stack - * - * @param key reference to its key - * @param start element in the stack - * @param length size of the vector - * @param typed whether is TypedVector or not - * @param fixed whether is Fixed vector or not - * @param keys Value representing key vector - * @return Value representing the created vector - */ - private Value createVector(int key, int start, int length, boolean typed, boolean fixed, Value keys) { - if (fixed & !typed) - throw new UnsupportedOperationException("Untyped fixed vector is not supported"); - - // Figure out smallest bit width we can store this vector with. - int bitWidth = Math.max(WIDTH_8, widthUInBits(length)); - int prefixElems = 1; - if (keys != null) { - // If this vector is part of a map, we will pre-fix an offset to the keys - // to this vector. - bitWidth = Math.max(bitWidth, keys.elemWidth(bb.writePosition(), 0)); - prefixElems += 2; - } - int vectorType = FBT_KEY; - // Check bit widths and types for all elements. - for (int i = start; i < stack.size(); i++) { - int elemWidth = stack.get(i).elemWidth(bb.writePosition(), i + prefixElems); - bitWidth = Math.max(bitWidth, elemWidth); - if (typed) { - if (i == start) { - vectorType = stack.get(i).type; - if (!FlexBuffers.isTypedVectorElementType(vectorType)) { - throw new FlexBufferException("TypedVector does not support this element type"); - } - } else { - // If you get this assert, you are writing a typed vector with - // elements that are not all the same type. - assert (vectorType == stack.get(i).type); - } - } - } - // If you get this assert, your fixed types are not one of: - // Int / UInt / Float / Key. - assert (!fixed || FlexBuffers.isTypedVectorElementType(vectorType)); - - int byteWidth = align(bitWidth); - // Write vector. First the keys width/offset if available, and size. - if (keys != null) { - writeOffset(keys.iValue, byteWidth); - writeInt(1L << keys.minBitWidth, byteWidth); - } - if (!fixed) { - writeInt(length, byteWidth); - } - // Then the actual data. - int vloc = bb.writePosition(); - for (int i = start; i < stack.size(); i++) { - writeAny(stack.get(i), byteWidth); - } - // Then the types. - if (!typed) { - for (int i = start; i < stack.size(); i++) { - bb.put(stack.get(i).storedPackedType(bitWidth)); - } - } - return new Value(key, keys != null ? FBT_MAP - : (typed ? FlexBuffers.toTypedVector(vectorType, fixed ? length : 0) - : FBT_VECTOR), bitWidth, vloc); - } - - private void writeOffset(long val, int byteWidth) { - int reloff = (int) (bb.writePosition() - val); - assert (byteWidth == 8 || reloff < 1L << (byteWidth * 8)); - writeInt(reloff, byteWidth); - } - - private void writeAny(final Value val, int byteWidth) { - switch (val.type) { - case FBT_NULL: - case FBT_BOOL: - case FBT_INT: - case FBT_UINT: - writeInt(val.iValue, byteWidth); - break; - case FBT_FLOAT: - writeDouble(val.dValue, byteWidth); - break; - default: - writeOffset(val.iValue, byteWidth); - break; - } - } - - private void writeDouble(double val, int byteWidth) { - if (byteWidth == 4) { - bb.putFloat((float) val); - } else if (byteWidth == 8) { - bb.putDouble(val); - } - } - - /** - * Start a new map in the buffer. - * @return a reference indicating position of the map in buffer. This - * reference must be passed along when the map is finished using endMap() - */ - public int startMap() { - return stack.size(); - } - - /** - * Finishes a map, but writing the information in the buffer - * @param key key used to store element in map - * @param start reference for beginning of the map. Returned by {@link startMap()} - * @return Reference to the map - */ - public int endMap(String key, int start) { - int iKey = putKey(key); - - Collections.sort(stack.subList(start, stack.size()), keyComparator); - - Value keys = createKeyVector(start, stack.size() - start); - Value vec = createVector(iKey, start, stack.size() - start, false, false, keys); - // Remove temp elements and return map. - while (stack.size() > start) { - stack.remove(stack.size() - 1); - } - stack.add(vec); - return (int) vec.iValue; - } - - private Value createKeyVector(int start, int length) { - // Figure out smallest bit width we can store this vector with. - int bitWidth = Math.max(WIDTH_8, widthUInBits(length)); - int prefixElems = 1; - // Check bit widths and types for all elements. - for (int i = start; i < stack.size(); i++) { - int elemWidth = Value.elemWidth(FBT_KEY, WIDTH_8, stack.get(i).key, bb.writePosition(), i + prefixElems); - bitWidth = Math.max(bitWidth, elemWidth); - } - - int byteWidth = align(bitWidth); - // Write vector. First the keys width/offset if available, and size. - writeInt(length, byteWidth); - // Then the actual data. - int vloc = bb.writePosition(); - for (int i = start; i < stack.size(); i++) { - int pos = stack.get(i).key; - assert(pos != -1); - writeOffset(stack.get(i).key, byteWidth); - } - // Then the types. - return new Value(-1, FlexBuffers.toTypedVector(FBT_KEY,0), bitWidth, vloc); - } - - private static class Value { - final int type; - // for scalars, represents scalar size in bytes - // for vectors, represents the size - // for string, length - final int minBitWidth; - // float value - final double dValue; - // integer value - long iValue; - // position of the key associated with this value in buffer - int key; - - Value(int key, int type, int bitWidth, long iValue) { - this.key = key; - this.type = type; - this.minBitWidth = bitWidth; - this.iValue = iValue; - this.dValue = Double.MIN_VALUE; - } - - Value(int key, int type, int bitWidth, double dValue) { - this.key = key; - this.type = type; - this.minBitWidth = bitWidth; - this.dValue = dValue; - this.iValue = Long.MIN_VALUE; - } - - static Value nullValue(int key) { - return new Value(key, FBT_NULL, WIDTH_8, 0); - } - - static Value bool(int key, boolean b) { - return new Value(key, FBT_BOOL, WIDTH_8, b ? 1 : 0); - } - - static Value blob(int key, int position, int type, int bitWidth) { - return new Value(key, type, bitWidth, position); - } - - static Value int8(int key, int value) { - return new Value(key, FBT_INT, WIDTH_8, value); - } - - static Value int16(int key, int value) { - return new Value(key, FBT_INT, WIDTH_16, value); - } - - static Value int32(int key, int value) { - return new Value(key, FBT_INT, WIDTH_32, value); - } - - static Value int64(int key, long value) { - return new Value(key, FBT_INT, WIDTH_64, value); - } - - static Value uInt8(int key, int value) { - return new Value(key, FBT_UINT, WIDTH_8, value); - } - - static Value uInt16(int key, int value) { - return new Value(key, FBT_UINT, WIDTH_16, value); - } - - static Value uInt32(int key, int value) { - return new Value(key, FBT_UINT, WIDTH_32, value); - } - - static Value uInt64(int key, long value) { - return new Value(key, FBT_UINT, WIDTH_64, value); - } - - static Value float32(int key, float value) { - return new Value(key, FBT_FLOAT, WIDTH_32, value); - } - - static Value float64(int key, double value) { - return new Value(key, FBT_FLOAT, WIDTH_64, value); - } - - private byte storedPackedType() { - return storedPackedType(WIDTH_8); - } - - private byte storedPackedType(int parentBitWidth) { - return packedType(storedWidth(parentBitWidth), type); - } - - private static byte packedType(int bitWidth, int type) { - return (byte) (bitWidth | (type << 2)); - } - - private int storedWidth(int parentBitWidth) { - if (FlexBuffers.isTypeInline(type)) { - return Math.max(minBitWidth, parentBitWidth); - } else { - return minBitWidth; - } - } - - private int elemWidth(int bufSize, int elemIndex) { - return elemWidth(type, minBitWidth, iValue, bufSize, elemIndex); - } - - private static int elemWidth(int type, int minBitWidth, long iValue, int bufSize, int elemIndex) { - if (FlexBuffers.isTypeInline(type)) { - return minBitWidth; - } else { - // We have an absolute offset, but want to store a relative offset - // elem_index elements beyond the current buffer end. Since whether - // the relative offset fits in a certain byte_width depends on - // the size of the elements before it (and their alignment), we have - // to test for each size in turn. - - // Original implementation checks for largest scalar - // which is long unsigned int - for (int byteWidth = 1; byteWidth <= 32; byteWidth *= 2) { - // Where are we going to write this offset? - int offsetLoc = bufSize + paddingBytes(bufSize, byteWidth) + (elemIndex * byteWidth); - // Compute relative offset. - long offset = offsetLoc - iValue; - // Does it fit? - int bitWidth = widthUInBits(offset); - if (((1L) << bitWidth) == byteWidth) - return bitWidth; - } - assert (false); // Must match one of the sizes above. - return WIDTH_64; - } - } - - private static int paddingBytes(int bufSize, int scalarSize) { - return ((~bufSize) + 1) & (scalarSize - 1); - } - } -} - -/// @} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FloatVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FloatVector.java deleted file mode 100644 index 5c505ba82..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/FloatVector.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of float values. - */ -public final class FloatVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public FloatVector __assign(int _vector, ByteBuffer _bb) { - __reset(_vector, Constants.SIZEOF_FLOAT, _bb); return this; - } - - /** - * Reads the float value at the given index. - * - * @param j The index from which the float value will be read. - * @return the float value at the given index. - */ - public float get(int j) { - return bb.getFloat(__element(j)); - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/IntVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/IntVector.java deleted file mode 100644 index 85549f417..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/IntVector.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of signed or unsigned 32-bit values. - */ -public final class IntVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public IntVector __assign(int _vector, ByteBuffer _bb) { - __reset(_vector, Constants.SIZEOF_INT, _bb); return this; - } - - /** - * Reads the integer at the given index. - * - * @param j The index from which the integer will be read. - * @return the 32-bit value at the given index. - */ - public int get(int j) { - return bb.getInt(__element(j)); - } - - /** - * Reads the integer at the given index, zero-extends it to type long, and returns the result, - * which is therefore in the range 0 through 4294967295. - * - * @param j The index from which the integer will be read. - * @return the unsigned 32-bit at the given index. - */ - public long getAsUnsigned(int j) { - return (long) get(j) & 0xFFFFFFFFL; - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/LongVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/LongVector.java deleted file mode 100644 index 0ca5ab82e..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/LongVector.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of long values. - */ -public final class LongVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public LongVector __assign(int _vector, ByteBuffer _bb) { - __reset(_vector, Constants.SIZEOF_LONG, _bb); return this; - } - - /** - * Reads the long value at the given index. - * - * @param j The index from which the long value will be read. - * @return the signed 64-bit value at the given index. - */ - public long get(int j) { - return bb.getLong(__element(j)); - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadBuf.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadBuf.java deleted file mode 100644 index 751361fa2..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadBuf.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.google.flatbuffers; - -/** - * Represent a chunk of data, where FlexBuffers will read from. - */ -public 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(); - -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadWriteBuf.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadWriteBuf.java deleted file mode 100644 index 6eb43bd5d..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ReadWriteBuf.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.google.flatbuffers; - -/** - * Interface to represent a read-write buffer. This interface will be used to access and write - * FlexBuffers message. - */ -public interface ReadWriteBuf extends ReadBuf { - - /** - * Clears (resets) the buffer so that it can be reused. Write position will be set to the - * start. - */ - void clear(); - - /** - * Put a boolean into the buffer at {@code writePosition()} . Booleans as stored as single - * byte. Write position will be incremented. - * @return boolean element - */ - void putBoolean(boolean value); - - /** - * Put an array of bytes into the buffer at {@code writePosition()}. Write position will be - * incremented. - * @param value the data to be copied - * @param start initial position on value to be copied - * @param length amount of bytes to be copied - */ - void put (byte[] value, int start, int length); - - /** - * Write a byte into the buffer at {@code writePosition()}. Write position will be - * incremented. - */ - void put(byte value); - - /** - * Write a 16-bit into in the buffer at {@code writePosition()}. Write position will be - * incremented. - */ - void putShort(short value); - - /** - * Write a 32-bit into in the buffer at {@code writePosition()}. Write position will be - * incremented. - */ - void putInt(int value); - - /** - * Write a 64-bit into in the buffer at {@code writePosition()}. Write position will be - * incremented. - */ - void putLong(long value); - - /** - * Write a 32-bit float into the buffer at {@code writePosition()}. Write position will be - * incremented. - */ - void putFloat(float value); - - /** - * Write a 64-bit float into the buffer at {@code writePosition()}. Write position will be - * incremented. - */ - void putDouble(double value); - - /** - * Write boolean into a given position on the buffer. Booleans as stored as single byte. - * @param index position of the element in buffer - */ - void setBoolean(int index, boolean value); - - /** - * Read a byte from data. - * @param index position of the element in the buffer - * @return a byte - */ - void set(int index, byte value); - - /** - * Write an array of bytes into the buffer. - * @param index initial position of the buffer to be written - * @param value the data to be copied - * @param start initial position on value to be copied - * @param length amount of bytes to be copied - */ - void set(int index, byte[] value, int start, int length); - - /** - * Read a short from data. - * @param index position of the element in ReadBuf - * @return a short - */ - void setShort(int index, short value); - - /** - * Read a 32-bit int from data. - * @param index position of the element in ReadBuf - * @return an int - */ - void setInt(int index, int value); - - /** - * Read a 64-bit long from data. - * @param index position of the element in ReadBuf - * @return a long - */ - void setLong(int index, long value); - - /** - * Read a 32-bit float from data. - * @param index position of the element in ReadBuf - * @return a float - */ - void setFloat(int index, float value); - - /** - * Read a 64-bit float from data. - * @param index position of the element in ReadBuf - * @return a double - */ - void setDouble(int index, double value); - - - int writePosition(); - /** - * 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 position {@code limit() -1}. - * @return indicate last position - */ - int limit(); - - /** - * 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. - * - * @return true if buffer is able to offer - * the requested capacity - */ - boolean requestCapacity(int capacity); -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ShortVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ShortVector.java deleted file mode 100644 index b02ac3e49..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/ShortVector.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of signed or unsigned 16-bit values. - */ -public final class ShortVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public ShortVector __assign(int _vector, ByteBuffer _bb) { - __reset(_vector, Constants.SIZEOF_SHORT, _bb); return this; - } - - /** - * Reads the short value at the given index. - * - * @param j The index from which the short value will be read. - * @return the 16-bit value at the given index. - */ - public short get(int j) { - return bb.getShort(__element(j)); - } - - /** - * Reads the short at the given index, zero-extends it to type int, and returns the result, - * which is therefore in the range 0 through 65535. - * - * @param j The index from which the short value will be read. - * @return the unsigned 16-bit at the given index. - */ - public int getAsUnsigned(int j) { - return (int) get(j) & 0xFFFF; - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/StringVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/StringVector.java deleted file mode 100644 index 6c20775c3..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/StringVector.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of String. - */ -public final class StringVector extends BaseVector { - private Utf8 utf8 = Utf8.getDefault(); - - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _element_size Size of a vector element. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public StringVector __assign(int _vector, int _element_size, ByteBuffer _bb) { - __reset(_vector, _element_size, _bb); return this; - } - - /** - * Reads the String at the given index. - * - * @param j The index from which the String value will be read. - * @return the String at the given index. - */ - public String get(int j) { - return Table.__string(__element(j), bb, utf8); - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Struct.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Struct.java deleted file mode 100644 index c92164ff8..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Struct.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import java.nio.ByteBuffer; - -/// @cond FLATBUFFERS_INTERNAL - -/** - * All structs in the generated code derive from this class, and add their own accessors. - */ -public class Struct { - /** Used to hold the position of the `bb` buffer. */ - protected int bb_pos; - /** The underlying ByteBuffer to hold the data of the Struct. */ - protected ByteBuffer bb; - - /** - * Re-init the internal state with an external buffer {@code ByteBuffer} and an offset within. - * - * This method exists primarily to allow recycling Table instances without risking memory leaks - * due to {@code ByteBuffer} references. - */ - protected void __reset(int _i, ByteBuffer _bb) { - bb = _bb; - if (bb != null) { - bb_pos = _i; - } else { - bb_pos = 0; - } - } - - /** - * Resets internal state with a null {@code ByteBuffer} and a zero position. - * - * This method exists primarily to allow recycling Struct instances without risking memory leaks - * due to {@code ByteBuffer} references. The instance will be unusable until it is assigned - * again to a {@code ByteBuffer}. - * - * @param struct the instance to reset to initial state - */ - public void __reset() { - __reset(0, null); - } -} - -/// @endcond diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Table.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Table.java deleted file mode 100644 index 7f416396e..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Table.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -/// @cond FLATBUFFERS_INTERNAL - -/** - * All tables in the generated code derive from this class, and add their own accessors. - */ -public class Table { - /** Used to hold the position of the `bb` buffer. */ - protected int bb_pos; - /** The underlying ByteBuffer to hold the data of the Table. */ - protected ByteBuffer bb; - /** Used to hold the vtable position. */ - private int vtable_start; - /** Used to hold the vtable size. */ - private int vtable_size; - Utf8 utf8 = Utf8.getDefault(); - - /** - * Get the underlying ByteBuffer. - * - * @return Returns the Table's ByteBuffer. - */ - public ByteBuffer getByteBuffer() { return bb; } - - /** - * Look up a field in the vtable. - * - * @param vtable_offset An `int` offset to the vtable in the Table's ByteBuffer. - * @return Returns an offset into the object, or `0` if the field is not present. - */ - protected int __offset(int vtable_offset) { - return vtable_offset < vtable_size ? bb.getShort(vtable_start + vtable_offset) : 0; - } - - protected static int __offset(int vtable_offset, int offset, ByteBuffer bb) { - int vtable = bb.capacity() - offset; - return bb.getShort(vtable + vtable_offset - bb.getInt(vtable)) + vtable; - } - - /** - * Retrieve a relative offset. - * - * @param offset An `int` index into the Table's ByteBuffer containing the relative offset. - * @return Returns the relative offset stored at `offset`. - */ - protected int __indirect(int offset) { - return offset + bb.getInt(offset); - } - - /** - * Retrieve a relative offset. - * - * @param offset An `int` index into a ByteBuffer containing the relative offset. - * @param bb from which the relative offset will be retrieved. - * @return Returns the relative offset stored at `offset`. - */ - protected static int __indirect(int offset, ByteBuffer bb) { - return offset + bb.getInt(offset); - } - - /** - * Create a Java `String` from UTF-8 data stored inside the FlatBuffer. - * - * This allocates a new string and converts to wide chars upon each access, - * which is not very efficient. Instead, each FlatBuffer string also comes with an - * accessor based on __vector_as_bytebuffer below, which is much more efficient, - * assuming your Java program can handle UTF-8 data directly. - * - * @param offset An `int` index into the Table's ByteBuffer. - * @return Returns a `String` from the data stored inside the FlatBuffer at `offset`. - */ - protected String __string(int offset) { - return __string(offset, bb, utf8); - } - - /** - * Create a Java `String` from UTF-8 data stored inside the FlatBuffer. - * - * This allocates a new string and converts to wide chars upon each access, - * which is not very efficient. Instead, each FlatBuffer string also comes with an - * accessor based on __vector_as_bytebuffer below, which is much more efficient, - * assuming your Java program can handle UTF-8 data directly. - * - * @param offset An `int` index into the Table's ByteBuffer. - * @param bb Table ByteBuffer used to read a string at given offset. - * @param utf8 decoder that creates a Java `String` from UTF-8 characters. - * @return Returns a `String` from the data stored inside the FlatBuffer at `offset`. - */ - protected static String __string(int offset, ByteBuffer bb, Utf8 utf8) { - offset += bb.getInt(offset); - int length = bb.getInt(offset); - return utf8.decodeUtf8(bb, offset + SIZEOF_INT, length); - } - - /** - * Get the length of a vector. - * - * @param offset An `int` index into the Table's ByteBuffer. - * @return Returns the length of the vector whose offset is stored at `offset`. - */ - protected int __vector_len(int offset) { - offset += bb_pos; - offset += bb.getInt(offset); - return bb.getInt(offset); - } - - /** - * Get the start data of a vector. - * - * @param offset An `int` index into the Table's ByteBuffer. - * @return Returns the start of the vector data whose offset is stored at `offset`. - */ - protected int __vector(int offset) { - offset += bb_pos; - return offset + bb.getInt(offset) + SIZEOF_INT; // data starts after the length - } - - /** - * Get a whole vector as a ByteBuffer. - * - * This is efficient, since it only allocates a new {@link ByteBuffer} object, - * but does not actually copy the data, it still refers to the same bytes - * as the original ByteBuffer. Also useful with nested FlatBuffers, etc. - * - * @param vector_offset The position of the vector in the byte buffer - * @param elem_size The size of each element in the array - * @return The {@link ByteBuffer} for the array - */ - protected ByteBuffer __vector_as_bytebuffer(int vector_offset, int elem_size) { - int o = __offset(vector_offset); - if (o == 0) return null; - ByteBuffer bb = this.bb.duplicate().order(ByteOrder.LITTLE_ENDIAN); - int vectorstart = __vector(o); - bb.position(vectorstart); - bb.limit(vectorstart + __vector_len(o) * elem_size); - return bb; - } - - /** - * Initialize vector as a ByteBuffer. - * - * This is more efficient than using duplicate, since it doesn't copy the data - * nor allocattes a new {@link ByteBuffer}, creating no garbage to be collected. - * - * @param bb The {@link ByteBuffer} for the array - * @param vector_offset The position of the vector in the byte buffer - * @param elem_size The size of each element in the array - * @return The {@link ByteBuffer} for the array - */ - protected ByteBuffer __vector_in_bytebuffer(ByteBuffer bb, int vector_offset, int elem_size) { - int o = this.__offset(vector_offset); - if (o == 0) return null; - int vectorstart = __vector(o); - bb.rewind(); - bb.limit(vectorstart + __vector_len(o) * elem_size); - bb.position(vectorstart); - return bb; - } - - /** - * Initialize any Table-derived type to point to the union at the given `offset`. - * - * @param t A `Table`-derived type that should point to the union at `offset`. - * @param offset An `int` index into the Table's ByteBuffer. - * @return Returns the Table that points to the union at `offset`. - */ - protected Table __union(Table t, int offset) { - return __union(t, offset, bb); - } - - /** - * Initialize any Table-derived type to point to the union at the given `offset`. - * - * @param t A `Table`-derived type that should point to the union at `offset`. - * @param offset An `int` index into the Table's ByteBuffer. - * @param bb Table ByteBuffer used to initialize the object Table-derived type. - * @return Returns the Table that points to the union at `offset`. - */ - protected static Table __union(Table t, int offset, ByteBuffer bb) { - t.__reset(__indirect(offset, bb), bb); - return t; - } - - /** - * Check if a {@link ByteBuffer} contains a file identifier. - * - * @param bb A {@code ByteBuffer} to check if it contains the identifier - * `ident`. - * @param ident A `String` identifier of the FlatBuffer file. - * @return True if the buffer contains the file identifier - */ - protected static boolean __has_identifier(ByteBuffer bb, String ident) { - if (ident.length() != FILE_IDENTIFIER_LENGTH) - throw new AssertionError("FlatBuffers: file identifier must be length " + - FILE_IDENTIFIER_LENGTH); - for (int i = 0; i < FILE_IDENTIFIER_LENGTH; i++) { - if (ident.charAt(i) != (char)bb.get(bb.position() + SIZEOF_INT + i)) return false; - } - return true; - } - - /** - * Sort tables by the key. - * - * @param offsets An 'int' indexes of the tables into the bb. - * @param bb A {@code ByteBuffer} to get the tables. - */ - protected void sortTables(int[] offsets, final ByteBuffer bb) { - Integer[] off = new Integer[offsets.length]; - for (int i = 0; i < offsets.length; i++) off[i] = offsets[i]; - java.util.Arrays.sort(off, new java.util.Comparator() { - public int compare(Integer o1, Integer o2) { - return keysCompare(o1, o2, bb); - } - }); - for (int i = 0; i < offsets.length; i++) offsets[i] = off[i]; - } - - /** - * Compare two tables by the key. - * - * @param o1 An 'Integer' index of the first key into the bb. - * @param o2 An 'Integer' index of the second key into the bb. - * @param bb A {@code ByteBuffer} to get the keys. - */ - protected int keysCompare(Integer o1, Integer o2, ByteBuffer bb) { return 0; } - - /** - * Compare two strings in the buffer. - * - * @param offset_1 An 'int' index of the first string into the bb. - * @param offset_2 An 'int' index of the second string into the bb. - * @param bb A {@code ByteBuffer} to get the strings. - */ - protected static int compareStrings(int offset_1, int offset_2, ByteBuffer bb) { - offset_1 += bb.getInt(offset_1); - offset_2 += bb.getInt(offset_2); - int len_1 = bb.getInt(offset_1); - int len_2 = bb.getInt(offset_2); - int startPos_1 = offset_1 + SIZEOF_INT; - int startPos_2 = offset_2 + SIZEOF_INT; - int len = Math.min(len_1, len_2); - for(int i = 0; i < len; i++) { - if (bb.get(i + startPos_1) != bb.get(i + startPos_2)) - return bb.get(i + startPos_1) - bb.get(i + startPos_2); - } - return len_1 - len_2; - } - - /** - * Compare string from the buffer with the 'String' object. - * - * @param offset_1 An 'int' index of the first string into the bb. - * @param key Second string as a byte array. - * @param bb A {@code ByteBuffer} to get the first string. - */ - protected static int compareStrings(int offset_1, byte[] key, ByteBuffer bb) { - offset_1 += bb.getInt(offset_1); - int len_1 = bb.getInt(offset_1); - int len_2 = key.length; - int startPos_1 = offset_1 + Constants.SIZEOF_INT; - int len = Math.min(len_1, len_2); - for (int i = 0; i < len; i++) { - if (bb.get(i + startPos_1) != key[i]) - return bb.get(i + startPos_1) - key[i]; - } - return len_1 - len_2; - } - - /** - * Re-init the internal state with an external buffer {@code ByteBuffer} and an offset within. - * - * This method exists primarily to allow recycling Table instances without risking memory leaks - * due to {@code ByteBuffer} references. - */ - protected void __reset(int _i, ByteBuffer _bb) { - bb = _bb; - if (bb != null) { - bb_pos = _i; - vtable_start = bb_pos - bb.getInt(bb_pos); - vtable_size = bb.getShort(vtable_start); - } else { - bb_pos = 0; - vtable_start = 0; - vtable_size = 0; - } - } - - /** - * Resets the internal state with a null {@code ByteBuffer} and a zero position. - * - * This method exists primarily to allow recycling Table instances without risking memory leaks - * due to {@code ByteBuffer} references. The instance will be unusable until it is assigned - * again to a {@code ByteBuffer}. - */ - public void __reset() { - __reset(0, null); - } -} - -/// @endcond diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/UnionVector.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/UnionVector.java deleted file mode 100644 index 986cfea40..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/UnionVector.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2019 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import static com.google.flatbuffers.Constants.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; - -/** - * Helper type for accessing vector of unions. - */ -public final class UnionVector extends BaseVector { - /** - * Assigns vector access object to vector data. - * - * @param _vector Start data of a vector. - * @param _element_size Size of a vector element. - * @param _bb Table's ByteBuffer. - * @return Returns current vector access object assigned to vector data whose offset is stored at - * `vector`. - */ - public UnionVector __assign(int _vector, int _element_size, ByteBuffer _bb) { - __reset(_vector, _element_size, _bb); return this; - } - - - /** - * Initialize any Table-derived type to point to the union at the given `index`. - * - * @param obj A `Table`-derived type that should point to the union at `index`. - * @param j An `int` index into the union vector. - * @return Returns the Table that points to the union at `index`. - */ - public Table get(Table obj, int j) { - return Table.__union(obj, __element(j), bb); - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8.java deleted file mode 100644 index e8af8ad6c..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import java.nio.ByteBuffer; - -import static java.lang.Character.MAX_SURROGATE; -import static java.lang.Character.MIN_SURROGATE; -import static java.lang.Character.MIN_HIGH_SURROGATE; -import static java.lang.Character.MIN_LOW_SURROGATE; -import static java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT; -import static java.lang.Character.isSurrogatePair; -import static java.lang.Character.toCodePoint; - -public abstract class Utf8 { - - /** - * Returns the number of bytes in the UTF-8-encoded form of {@code sequence}. For a string, - * this method is equivalent to {@code string.getBytes(UTF_8).length}, but is more efficient in - * both time and space. - * - * @throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired - * surrogates) - */ - public abstract int encodedLength(CharSequence sequence); - - /** - * Encodes the given characters to the target {@link ByteBuffer} using UTF-8 encoding. - * - *

Selects an optimal algorithm based on the type of {@link ByteBuffer} (i.e. heap or direct) - * and the capabilities of the platform. - * - * @param in the source string to be encoded - * @param out the target buffer to receive the encoded string. - */ - public abstract void encodeUtf8(CharSequence in, ByteBuffer out); - - /** - * Decodes the given UTF-8 portion of the {@link ByteBuffer} into a {@link String}. - * - * @throws IllegalArgumentException if the input is not valid UTF-8. - */ - public abstract String decodeUtf8(ByteBuffer buffer, int offset, int length); - - private static Utf8 DEFAULT; - - /** - * Get the default UTF-8 processor. - * @return the default processor - */ - public static Utf8 getDefault() { - if (DEFAULT == null) { - DEFAULT = new Utf8Safe(); - } - return DEFAULT; - } - - /** - * Set the default instance of the UTF-8 processor. - * @param instance the new instance to use - */ - public static void setDefault(Utf8 instance) { - DEFAULT = instance; - } - - /** - * Encode a Java's CharSequence UTF8 codepoint into a byte array. - * @param in CharSequence to be encoded - * @param start start position of the first char in the codepoint - * @param out byte array of 4 bytes to be filled - * @return return the amount of bytes occupied by the codepoint - */ - public static int encodeUtf8CodePoint(CharSequence in, int start, byte[] out) { - // utf8 codepoint needs at least 4 bytes - assert out.length >= 4; - - final int inLength = in.length(); - if (start >= inLength) { - return 0; - } - - char c = in.charAt(start); - if (c < 0x80) { - // One byte (0xxx xxxx) - out[0] = (byte) c; - return 1; - } else if (c < 0x800) { - // Two bytes (110x xxxx 10xx xxxx) - out[0] = (byte) (0xC0 | (c >>> 6)); - out[1] = (byte) (0x80 | (0x3F & c)); - return 2; - } else if (c < MIN_SURROGATE || MAX_SURROGATE < c) { - // Three bytes (1110 xxxx 10xx xxxx 10xx xxxx) - // Maximum single-char code point is 0xFFFF, 16 bits. - out[0] = (byte) (0xE0 | (c >>> 12)); - out[1] =(byte) (0x80 | (0x3F & (c >>> 6))); - out[2] = (byte) (0x80 | (0x3F & c)); - return 3; - } else { - // Four bytes (1111 xxxx 10xx xxxx 10xx xxxx 10xx xxxx) - // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, four UTF-8 - // bytes - final char low; - if (start + 1 == inLength || !isSurrogatePair(c, (low = in.charAt(start+1)))) { - throw new UnpairedSurrogateException(start, inLength); - } - int codePoint = toCodePoint(c, low); - out[0] = (byte) ((0xF << 4) | (codePoint >>> 18)); - out[1] = (byte) (0x80 | (0x3F & (codePoint >>> 12))); - out[2] = (byte) (0x80 | (0x3F & (codePoint >>> 6))); - out[3] = (byte) (0x80 | (0x3F & codePoint)); - return 4; - } - } - - /** - * Utility methods for decoding bytes into {@link String}. Callers are responsible for extracting - * bytes (possibly using Unsafe methods), and checking remaining bytes. All other UTF-8 validity - * checks and codepoint conversion happen in this class. - */ - static class DecodeUtil { - - /** - * Returns whether this is a single-byte codepoint (i.e., ASCII) with the form '0XXXXXXX'. - */ - static boolean isOneByte(byte b) { - return b >= 0; - } - - /** - * Returns whether this is a two-byte codepoint with the form '10XXXXXX'. - */ - static boolean isTwoBytes(byte b) { - return b < (byte) 0xE0; - } - - /** - * Returns whether this is a three-byte codepoint with the form '110XXXXX'. - */ - static boolean isThreeBytes(byte b) { - return b < (byte) 0xF0; - } - - static void handleOneByte(byte byte1, char[] resultArr, int resultPos) { - resultArr[resultPos] = (char) byte1; - } - - static void handleTwoBytes( - byte byte1, byte byte2, char[] resultArr, int resultPos) - throws IllegalArgumentException { - // Simultaneously checks for illegal trailing-byte in leading position (<= '11000000') and - // overlong 2-byte, '11000001'. - if (byte1 < (byte) 0xC2) { - throw new IllegalArgumentException("Invalid UTF-8: Illegal leading byte in 2 bytes utf"); - } - if (isNotTrailingByte(byte2)) { - throw new IllegalArgumentException("Invalid UTF-8: Illegal trailing byte in 2 bytes utf"); - } - resultArr[resultPos] = (char) (((byte1 & 0x1F) << 6) | trailingByteValue(byte2)); - } - - static void handleThreeBytes( - byte byte1, byte byte2, byte byte3, char[] resultArr, int resultPos) - throws IllegalArgumentException { - if (isNotTrailingByte(byte2) - // overlong? 5 most significant bits must not all be zero - || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0) - // check for illegal surrogate codepoints - || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0) - || isNotTrailingByte(byte3)) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - resultArr[resultPos] = (char) - (((byte1 & 0x0F) << 12) | (trailingByteValue(byte2) << 6) | trailingByteValue(byte3)); - } - - static void handleFourBytes( - byte byte1, byte byte2, byte byte3, byte byte4, char[] resultArr, int resultPos) - throws IllegalArgumentException{ - if (isNotTrailingByte(byte2) - // Check that 1 <= plane <= 16. Tricky optimized form of: - // valid 4-byte leading byte? - // if (byte1 > (byte) 0xF4 || - // overlong? 4 most significant bits must not all be zero - // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 || - // codepoint larger than the highest code point (U+10FFFF)? - // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F) - || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0 - || isNotTrailingByte(byte3) - || isNotTrailingByte(byte4)) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - int codepoint = ((byte1 & 0x07) << 18) - | (trailingByteValue(byte2) << 12) - | (trailingByteValue(byte3) << 6) - | trailingByteValue(byte4); - resultArr[resultPos] = DecodeUtil.highSurrogate(codepoint); - resultArr[resultPos + 1] = DecodeUtil.lowSurrogate(codepoint); - } - - /** - * Returns whether the byte is not a valid continuation of the form '10XXXXXX'. - */ - private static boolean isNotTrailingByte(byte b) { - return b > (byte) 0xBF; - } - - /** - * Returns the actual value of the trailing byte (removes the prefix '10') for composition. - */ - private static int trailingByteValue(byte b) { - return b & 0x3F; - } - - private static char highSurrogate(int codePoint) { - return (char) ((MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)) - + (codePoint >>> 10)); - } - - private static char lowSurrogate(int codePoint) { - return (char) (MIN_LOW_SURROGATE + (codePoint & 0x3ff)); - } - } - - // These UTF-8 handling methods are copied from Guava's Utf8Unsafe class with a modification to throw - // a protocol buffer local exception. This exception is then caught in CodedOutputStream so it can - // fallback to more lenient behavior. - static class UnpairedSurrogateException extends IllegalArgumentException { - UnpairedSurrogateException(int index, int length) { - super("Unpaired surrogate at index " + index + " of " + length); - } - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Old.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Old.java deleted file mode 100644 index c568105a0..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Old.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.flatbuffers; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.CoderResult; -import java.nio.charset.StandardCharsets; - -/** - * This class implements the Utf8 API using the Java Utf8 encoder. Use - * Utf8.setDefault(new Utf8Old()); to use it. - */ -public class Utf8Old extends Utf8 { - - private static class Cache { - final CharsetEncoder encoder; - final CharsetDecoder decoder; - CharSequence lastInput = null; - ByteBuffer lastOutput = null; - - Cache() { - encoder = StandardCharsets.UTF_8.newEncoder(); - decoder = StandardCharsets.UTF_8.newDecoder(); - } - } - - // ThreadLocal.withInitial() is not used to make the following code compatible with Android API - // level 23. - private static final ThreadLocal CACHE = - new ThreadLocal() { - @Override - protected Cache initialValue() { - return new Cache(); - } - }; - - // Play some games so that the old encoder doesn't pay twice for computing - // the length of the encoded string. - - @Override - public int encodedLength(CharSequence in) { - final Cache cache = CACHE.get(); - int estimated = (int) (in.length() * cache.encoder.maxBytesPerChar()); - if (cache.lastOutput == null || cache.lastOutput.capacity() < estimated) { - cache.lastOutput = ByteBuffer.allocate(Math.max(128, estimated)); - } - cache.lastOutput.clear(); - cache.lastInput = in; - CharBuffer wrap = (in instanceof CharBuffer) ? - (CharBuffer) in : CharBuffer.wrap(in); - CoderResult result = cache.encoder.encode(wrap, cache.lastOutput, true); - if (result.isError()) { - try { - result.throwException(); - } catch (CharacterCodingException e) { - throw new IllegalArgumentException("bad character encoding", e); - } - } - cache.lastOutput.flip(); - return cache.lastOutput.remaining(); - } - - @Override - public void encodeUtf8(CharSequence in, ByteBuffer out) { - final Cache cache = CACHE.get(); - if (cache.lastInput != in) { - // Update the lastOutput to match our input, although flatbuffer should - // never take this branch. - encodedLength(in); - } - out.put(cache.lastOutput); - } - - @Override - public String decodeUtf8(ByteBuffer buffer, int offset, int length) { - CharsetDecoder decoder = CACHE.get().decoder; - decoder.reset(); - buffer = buffer.duplicate(); - buffer.position(offset); - buffer.limit(offset + length); - try { - CharBuffer result = decoder.decode(buffer); - return result.toString(); - } catch (CharacterCodingException e) { - throw new IllegalArgumentException("Bad encoding", e); - } - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Safe.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Safe.java deleted file mode 100644 index 060379fd0..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/Utf8Safe.java +++ /dev/null @@ -1,421 +0,0 @@ -package com.google.flatbuffers; - -import java.nio.ByteBuffer; -import static java.lang.Character.MAX_SURROGATE; -import static java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT; -import static java.lang.Character.MIN_SURROGATE; -import static java.lang.Character.isSurrogatePair; -import static java.lang.Character.toCodePoint; - -/** - * A set of low-level, high-performance static utility methods related - * to the UTF-8 character encoding. This class has no dependencies - * outside of the core JDK libraries. - * - *

There are several variants of UTF-8. The one implemented by - * this class is the restricted definition of UTF-8 introduced in - * Unicode 3.1, which mandates the rejection of "overlong" byte - * sequences as well as rejection of 3-byte surrogate codepoint byte - * sequences. Note that the UTF-8 decoder included in Oracle's JDK - * has been modified to also reject "overlong" byte sequences, but (as - * of 2011) still accepts 3-byte surrogate codepoint byte sequences. - * - *

The byte sequences considered valid by this class are exactly - * those that can be roundtrip converted to Strings and back to bytes - * using the UTF-8 charset, without loss:

 {@code
- * Arrays.equals(bytes, new String(bytes, Internal.UTF_8).getBytes(Internal.UTF_8))
- * }
- * - *

See the Unicode Standard,
- * Table 3-6. UTF-8 Bit Distribution,
- * Table 3-7. Well Formed UTF-8 Byte Sequences. - */ -final public class Utf8Safe extends Utf8 { - - /** - * Returns the number of bytes in the UTF-8-encoded form of {@code sequence}. For a string, - * this method is equivalent to {@code string.getBytes(UTF_8).length}, but is more efficient in - * both time and space. - * - * @throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired - * surrogates) - */ - private static int computeEncodedLength(CharSequence sequence) { - // Warning to maintainers: this implementation is highly optimized. - int utf16Length = sequence.length(); - int utf8Length = utf16Length; - int i = 0; - - // This loop optimizes for pure ASCII. - while (i < utf16Length && sequence.charAt(i) < 0x80) { - i++; - } - - // This loop optimizes for chars less than 0x800. - for (; i < utf16Length; i++) { - char c = sequence.charAt(i); - if (c < 0x800) { - utf8Length += ((0x7f - c) >>> 31); // branch free! - } else { - utf8Length += encodedLengthGeneral(sequence, i); - break; - } - } - - if (utf8Length < utf16Length) { - // Necessary and sufficient condition for overflow because of maximum 3x expansion - throw new IllegalArgumentException("UTF-8 length does not fit in int: " - + (utf8Length + (1L << 32))); - } - return utf8Length; - } - - private static int encodedLengthGeneral(CharSequence sequence, int start) { - int utf16Length = sequence.length(); - int utf8Length = 0; - for (int i = start; i < utf16Length; i++) { - char c = sequence.charAt(i); - if (c < 0x800) { - utf8Length += (0x7f - c) >>> 31; // branch free! - } else { - utf8Length += 2; - // jdk7+: if (Character.isSurrogate(c)) { - if (Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE) { - // Check that we have a well-formed surrogate pair. - int cp = Character.codePointAt(sequence, i); - if (cp < MIN_SUPPLEMENTARY_CODE_POINT) { - throw new Utf8Safe.UnpairedSurrogateException(i, utf16Length); - } - i++; - } - } - } - return utf8Length; - } - - 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( - String.format("buffer length=%d, index=%d, size=%d", bytes.length, index, size)); - } - - int offset = index; - final int limit = offset + size; - - // The longest possible resulting String is the same as the number of input bytes, when it is - // all ASCII. For other cases, this over-allocates and we will truncate in the end. - char[] resultArr = new char[size]; - int resultPos = 0; - - // Optimize for 100% ASCII (Hotspot loves small simple top-level loops like this). - // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII). - while (offset < limit) { - byte b = bytes[offset]; - if (!DecodeUtil.isOneByte(b)) { - break; - } - offset++; - DecodeUtil.handleOneByte(b, resultArr, resultPos++); - } - - while (offset < limit) { - byte byte1 = bytes[offset++]; - if (DecodeUtil.isOneByte(byte1)) { - DecodeUtil.handleOneByte(byte1, resultArr, resultPos++); - // It's common for there to be multiple ASCII characters in a run mixed in, so add an - // extra optimized loop to take care of these runs. - while (offset < limit) { - byte b = bytes[offset]; - if (!DecodeUtil.isOneByte(b)) { - break; - } - offset++; - DecodeUtil.handleOneByte(b, resultArr, resultPos++); - } - } else if (DecodeUtil.isTwoBytes(byte1)) { - if (offset >= limit) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - DecodeUtil.handleTwoBytes(byte1, /* byte2 */ bytes[offset++], resultArr, resultPos++); - } else if (DecodeUtil.isThreeBytes(byte1)) { - if (offset >= limit - 1) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - DecodeUtil.handleThreeBytes( - byte1, - /* byte2 */ bytes[offset++], - /* byte3 */ bytes[offset++], - resultArr, - resultPos++); - } else { - if (offset >= limit - 2) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - DecodeUtil.handleFourBytes( - byte1, - /* byte2 */ bytes[offset++], - /* byte3 */ bytes[offset++], - /* byte4 */ bytes[offset++], - resultArr, - resultPos++); - // 4-byte case requires two chars. - resultPos++; - } - } - - return new String(resultArr, 0, resultPos); - } - - 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) { - throw new ArrayIndexOutOfBoundsException( - String.format("buffer limit=%d, index=%d, limit=%d", buffer.limit(), - offset, length)); - } - - final int limit = offset + length; - - // The longest possible resulting String is the same as the number of input bytes, when it is - // all ASCII. For other cases, this over-allocates and we will truncate in the end. - char[] resultArr = new char[length]; - int resultPos = 0; - - // Optimize for 100% ASCII (Hotspot loves small simple top-level loops like this). - // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII). - while (offset < limit) { - byte b = buffer.get(offset); - if (!DecodeUtil.isOneByte(b)) { - break; - } - offset++; - DecodeUtil.handleOneByte(b, resultArr, resultPos++); - } - - while (offset < limit) { - byte byte1 = buffer.get(offset++); - if (DecodeUtil.isOneByte(byte1)) { - DecodeUtil.handleOneByte(byte1, resultArr, resultPos++); - // It's common for there to be multiple ASCII characters in a run mixed in, so add an - // extra optimized loop to take care of these runs. - while (offset < limit) { - byte b = buffer.get(offset); - if (!DecodeUtil.isOneByte(b)) { - break; - } - offset++; - DecodeUtil.handleOneByte(b, resultArr, resultPos++); - } - } else if (DecodeUtil.isTwoBytes(byte1)) { - if (offset >= limit) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - DecodeUtil.handleTwoBytes( - byte1, /* byte2 */ buffer.get(offset++), resultArr, resultPos++); - } else if (DecodeUtil.isThreeBytes(byte1)) { - if (offset >= limit - 1) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - DecodeUtil.handleThreeBytes( - byte1, - /* byte2 */ buffer.get(offset++), - /* byte3 */ buffer.get(offset++), - resultArr, - resultPos++); - } else { - if (offset >= limit - 2) { - throw new IllegalArgumentException("Invalid UTF-8"); - } - DecodeUtil.handleFourBytes( - byte1, - /* byte2 */ buffer.get(offset++), - /* byte3 */ buffer.get(offset++), - /* byte4 */ buffer.get(offset++), - resultArr, - resultPos++); - // 4-byte case requires two chars. - resultPos++; - } - } - - return new String(resultArr, 0, resultPos); - } - - @Override - public int encodedLength(CharSequence in) { - return computeEncodedLength(in); - } - - /** - * Decodes the given UTF-8 portion of the {@link ByteBuffer} into a {@link String}. - * - * @throws IllegalArgumentException if the input is not valid UTF-8. - */ - @Override - public String decodeUtf8(ByteBuffer buffer, int offset, int length) - throws IllegalArgumentException { - if (buffer.hasArray()) { - return decodeUtf8Array(buffer.array(), buffer.arrayOffset() + offset, length); - } else { - return decodeUtf8Buffer(buffer, offset, length); - } - } - - - private static void encodeUtf8Buffer(CharSequence in, ByteBuffer out) { - final int inLength = in.length(); - int outIx = out.position(); - int inIx = 0; - - // Since ByteBuffer.putXXX() already checks boundaries for us, no need to explicitly check - // access. Assume the buffer is big enough and let it handle the out of bounds exception - // if it occurs. - try { - // Designed to take advantage of - // https://wikis.oracle.com/display/HotSpotInternals/RangeCheckElimination - for (char c; inIx < inLength && (c = in.charAt(inIx)) < 0x80; ++inIx) { - out.put(outIx + inIx, (byte) c); - } - if (inIx == inLength) { - // Successfully encoded the entire string. - out.position(outIx + inIx); - return; - } - - outIx += inIx; - for (char c; inIx < inLength; ++inIx, ++outIx) { - c = in.charAt(inIx); - if (c < 0x80) { - // One byte (0xxx xxxx) - out.put(outIx, (byte) c); - } else if (c < 0x800) { - // Two bytes (110x xxxx 10xx xxxx) - - // Benchmarks show put performs better than putShort here (for HotSpot). - out.put(outIx++, (byte) (0xC0 | (c >>> 6))); - out.put(outIx, (byte) (0x80 | (0x3F & c))); - } else if (c < MIN_SURROGATE || MAX_SURROGATE < c) { - // Three bytes (1110 xxxx 10xx xxxx 10xx xxxx) - // Maximum single-char code point is 0xFFFF, 16 bits. - - // Benchmarks show put performs better than putShort here (for HotSpot). - out.put(outIx++, (byte) (0xE0 | (c >>> 12))); - out.put(outIx++, (byte) (0x80 | (0x3F & (c >>> 6)))); - out.put(outIx, (byte) (0x80 | (0x3F & c))); - } else { - // Four bytes (1111 xxxx 10xx xxxx 10xx xxxx 10xx xxxx) - - // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, four UTF-8 - // bytes - final char low; - if (inIx + 1 == inLength || !isSurrogatePair(c, (low = in.charAt(++inIx)))) { - throw new UnpairedSurrogateException(inIx, inLength); - } - // TODO(nathanmittler): Consider using putInt() to improve performance. - int codePoint = toCodePoint(c, low); - out.put(outIx++, (byte) ((0xF << 4) | (codePoint >>> 18))); - out.put(outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 12)))); - out.put(outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 6)))); - out.put(outIx, (byte) (0x80 | (0x3F & codePoint))); - } - } - - // Successfully encoded the entire string. - out.position(outIx); - } catch (IndexOutOfBoundsException e) { - // TODO(nathanmittler): Consider making the API throw IndexOutOfBoundsException instead. - - // If we failed in the outer ASCII loop, outIx will not have been updated. In this case, - // use inIx to determine the bad write index. - int badWriteIndex = out.position() + Math.max(inIx, outIx - out.position() + 1); - throw new ArrayIndexOutOfBoundsException( - "Failed writing " + in.charAt(inIx) + " at index " + badWriteIndex); - } - } - - private static int encodeUtf8Array(CharSequence in, byte[] out, - int offset, int length) { - int utf16Length = in.length(); - int j = offset; - int i = 0; - int limit = offset + length; - // Designed to take advantage of - // https://wikis.oracle.com/display/HotSpotInternals/RangeCheckElimination - for (char c; i < utf16Length && i + j < limit && (c = in.charAt(i)) < 0x80; i++) { - out[j + i] = (byte) c; - } - if (i == utf16Length) { - return j + utf16Length; - } - j += i; - for (char c; i < utf16Length; i++) { - c = in.charAt(i); - if (c < 0x80 && j < limit) { - out[j++] = (byte) c; - } else if (c < 0x800 && j <= limit - 2) { // 11 bits, two UTF-8 bytes - out[j++] = (byte) ((0xF << 6) | (c >>> 6)); - out[j++] = (byte) (0x80 | (0x3F & c)); - } else if ((c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) && j <= limit - 3) { - // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes - out[j++] = (byte) ((0xF << 5) | (c >>> 12)); - out[j++] = (byte) (0x80 | (0x3F & (c >>> 6))); - out[j++] = (byte) (0x80 | (0x3F & c)); - } else if (j <= limit - 4) { - // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, - // four UTF-8 bytes - final char low; - if (i + 1 == in.length() - || !Character.isSurrogatePair(c, (low = in.charAt(++i)))) { - throw new UnpairedSurrogateException((i - 1), utf16Length); - } - int codePoint = Character.toCodePoint(c, low); - out[j++] = (byte) ((0xF << 4) | (codePoint >>> 18)); - out[j++] = (byte) (0x80 | (0x3F & (codePoint >>> 12))); - out[j++] = (byte) (0x80 | (0x3F & (codePoint >>> 6))); - out[j++] = (byte) (0x80 | (0x3F & codePoint)); - } else { - // If we are surrogates and we're not a surrogate pair, always throw an - // UnpairedSurrogateException instead of an ArrayOutOfBoundsException. - if ((Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE) - && (i + 1 == in.length() - || !Character.isSurrogatePair(c, in.charAt(i + 1)))) { - throw new UnpairedSurrogateException(i, utf16Length); - } - throw new ArrayIndexOutOfBoundsException("Failed writing " + c + " at index " + j); - } - } - return j; - } - - /** - * Encodes the given characters to the target {@link ByteBuffer} using UTF-8 encoding. - * - *

Selects an optimal algorithm based on the type of {@link ByteBuffer} (i.e. heap or direct) - * and the capabilities of the platform. - * - * @param in the source string to be encoded - * @param out the target buffer to receive the encoded string. - */ - @Override - public void encodeUtf8(CharSequence in, ByteBuffer out) { - if (out.hasArray()) { - int start = out.arrayOffset(); - int end = encodeUtf8Array(in, out.array(), start + out.position(), - out.remaining()); - out.position(end - start); - } else { - encodeUtf8Buffer(in, out); - } - } - - // These UTF-8 handling methods are copied from Guava's Utf8Unsafe class with - // a modification to throw a local exception. This exception can be caught - // to fallback to more lenient behavior. - static class UnpairedSurrogateException extends IllegalArgumentException { - UnpairedSurrogateException(int index, int length) { - super("Unpaired surrogate at index " + index + " of " + length); - } - } -} diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/AdvancedFeatures.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/AdvancedFeatures.java deleted file mode 100644 index cf49086cd..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/AdvancedFeatures.java +++ /dev/null @@ -1,16 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -/** - * New schema language features that are not supported by old code generators. - */ -@SuppressWarnings("unused") -public final class AdvancedFeatures { - private AdvancedFeatures() { } - public static final long AdvancedArrayFeatures = 1L; - public static final long AdvancedUnionFeatures = 2L; - public static final long OptionalScalars = 4L; - public static final long DefaultVectorsAndStrings = 8L; -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/BaseType.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/BaseType.java deleted file mode 100644 index ef6ba2d40..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/BaseType.java +++ /dev/null @@ -1,33 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -@SuppressWarnings("unused") -public final class BaseType { - private BaseType() { } - public static final byte None = 0; - public static final byte UType = 1; - public static final byte Bool = 2; - public static final byte Byte = 3; - public static final byte UByte = 4; - public static final byte Short = 5; - public static final byte UShort = 6; - public static final byte Int = 7; - public static final byte UInt = 8; - public static final byte Long = 9; - public static final byte ULong = 10; - public static final byte Float = 11; - public static final byte Double = 12; - public static final byte String = 13; - public static final byte Vector = 14; - public static final byte Obj = 15; - public static final byte Union = 16; - public static final byte Array = 17; - public static final byte Vector64 = 18; - public static final byte MaxBaseType = 19; - - public static final String[] names = { "None", "UType", "Bool", "Byte", "UByte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "String", "Vector", "Obj", "Union", "Array", "Vector64", "MaxBaseType", }; - - public static String name(int e) { return names[e]; } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Enum.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Enum.java deleted file mode 100644 index 6c8a41866..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Enum.java +++ /dev/null @@ -1,135 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class Enum extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static Enum getRootAsEnum(ByteBuffer _bb) { return getRootAsEnum(_bb, new Enum()); } - public static Enum getRootAsEnum(ByteBuffer _bb, Enum obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public Enum __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - public com.google.flatbuffers.reflection.EnumVal values(int j) { return values(new com.google.flatbuffers.reflection.EnumVal(), j); } - public com.google.flatbuffers.reflection.EnumVal values(com.google.flatbuffers.reflection.EnumVal obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int valuesLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.EnumVal valuesByKey(long key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.EnumVal.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.EnumVal valuesByKey(com.google.flatbuffers.reflection.EnumVal obj, long key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.EnumVal.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.EnumVal.Vector valuesVector() { return valuesVector(new com.google.flatbuffers.reflection.EnumVal.Vector()); } - public com.google.flatbuffers.reflection.EnumVal.Vector valuesVector(com.google.flatbuffers.reflection.EnumVal.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public boolean isUnion() { int o = __offset(8); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } - public com.google.flatbuffers.reflection.Type underlyingType() { return underlyingType(new com.google.flatbuffers.reflection.Type()); } - public com.google.flatbuffers.reflection.Type underlyingType(com.google.flatbuffers.reflection.Type obj) { int o = __offset(10); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); } - public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(12); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int attributesLength() { int o = __offset(12); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(12); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(12); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(12); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public String documentation(int j) { int o = __offset(14); return o != 0 ? __string(__vector(o) + j * 4) : null; } - public int documentationLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } - public StringVector documentationVector() { return documentationVector(new StringVector()); } - public StringVector documentationVector(StringVector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - /** - * File that this Enum is declared in. - */ - public String declarationFile() { int o = __offset(16); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer declarationFileAsByteBuffer() { return __vector_as_bytebuffer(16, 1); } - public ByteBuffer declarationFileInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 16, 1); } - - public static int createEnum(FlatBufferBuilder builder, - int nameOffset, - int valuesOffset, - boolean isUnion, - int underlyingTypeOffset, - int attributesOffset, - int documentationOffset, - int declarationFileOffset) { - builder.startTable(7); - Enum.addDeclarationFile(builder, declarationFileOffset); - Enum.addDocumentation(builder, documentationOffset); - Enum.addAttributes(builder, attributesOffset); - Enum.addUnderlyingType(builder, underlyingTypeOffset); - Enum.addValues(builder, valuesOffset); - Enum.addName(builder, nameOffset); - Enum.addIsUnion(builder, isUnion); - return Enum.endEnum(builder); - } - - public static void startEnum(FlatBufferBuilder builder) { builder.startTable(7); } - public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); } - public static void addValues(FlatBufferBuilder builder, int valuesOffset) { builder.addOffset(1, valuesOffset, 0); } - public static int createValuesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startValuesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addIsUnion(FlatBufferBuilder builder, boolean isUnion) { builder.addBoolean(2, isUnion, false); } - public static void addUnderlyingType(FlatBufferBuilder builder, int underlyingTypeOffset) { builder.addOffset(3, underlyingTypeOffset, 0); } - public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(4, attributesOffset, 0); } - public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(5, documentationOffset, 0); } - public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDeclarationFile(FlatBufferBuilder builder, int declarationFileOffset) { builder.addOffset(6, declarationFileOffset, 0); } - public static int endEnum(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // name - builder.required(o, 6); // values - builder.required(o, 10); // underlying_type - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); } - - public static Enum __lookup_by_key(Enum obj, int vectorLocation, String key, ByteBuffer bb) { - byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8); - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb); - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new Enum() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public Enum get(int j) { return get(new Enum(), j); } - public Enum get(Enum obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public Enum getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); } - public Enum getByKey(Enum obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/EnumVal.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/EnumVal.java deleted file mode 100644 index 732371714..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/EnumVal.java +++ /dev/null @@ -1,116 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class EnumVal extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static EnumVal getRootAsEnumVal(ByteBuffer _bb) { return getRootAsEnumVal(_bb, new EnumVal()); } - public static EnumVal getRootAsEnumVal(ByteBuffer _bb, EnumVal obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public EnumVal __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - public long value() { int o = __offset(6); return o != 0 ? bb.getLong(o + bb_pos) : 0L; } - public com.google.flatbuffers.reflection.Type unionType() { return unionType(new com.google.flatbuffers.reflection.Type()); } - public com.google.flatbuffers.reflection.Type unionType(com.google.flatbuffers.reflection.Type obj) { int o = __offset(10); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } - public String documentation(int j) { int o = __offset(12); return o != 0 ? __string(__vector(o) + j * 4) : null; } - public int documentationLength() { int o = __offset(12); return o != 0 ? __vector_len(o) : 0; } - public StringVector documentationVector() { return documentationVector(new StringVector()); } - public StringVector documentationVector(StringVector obj) { int o = __offset(12); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); } - public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(14); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int attributesLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - - public static int createEnumVal(FlatBufferBuilder builder, - int nameOffset, - long value, - int unionTypeOffset, - int documentationOffset, - int attributesOffset) { - builder.startTable(6); - EnumVal.addValue(builder, value); - EnumVal.addAttributes(builder, attributesOffset); - EnumVal.addDocumentation(builder, documentationOffset); - EnumVal.addUnionType(builder, unionTypeOffset); - EnumVal.addName(builder, nameOffset); - return EnumVal.endEnumVal(builder); - } - - public static void startEnumVal(FlatBufferBuilder builder) { builder.startTable(6); } - public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(0, nameOffset, 0); } - public static void addValue(FlatBufferBuilder builder, long value) { builder.addLong(value); builder.slot(1); } - public static void addUnionType(FlatBufferBuilder builder, int unionTypeOffset) { builder.addOffset(3, unionTypeOffset, 0); } - public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(4, documentationOffset, 0); } - public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(5, attributesOffset, 0); } - public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static int endEnumVal(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // name - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { - long val_1 = _bb.getLong(__offset(6, o1, _bb)); - long val_2 = _bb.getLong(__offset(6, o2, _bb)); - return val_1 > val_2 ? 1 : val_1 < val_2 ? -1 : 0; - } - - public static EnumVal __lookup_by_key(EnumVal obj, int vectorLocation, long key, ByteBuffer bb) { - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - long val = bb.getLong(__offset(6, bb.capacity() - tableOffset, bb)); - int comp = val > key ? 1 : val < key ? -1 : 0; - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new EnumVal() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public EnumVal get(int j) { return get(new EnumVal(), j); } - public EnumVal get(EnumVal obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public EnumVal getByKey(long key) { return __lookup_by_key(null, __vector(), key, bb); } - public EnumVal getByKey(EnumVal obj, long key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Field.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Field.java deleted file mode 100644 index d5c1c13a5..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Field.java +++ /dev/null @@ -1,155 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class Field extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static Field getRootAsField(ByteBuffer _bb) { return getRootAsField(_bb, new Field()); } - public static Field getRootAsField(ByteBuffer _bb, Field obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public Field __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - public com.google.flatbuffers.reflection.Type type() { return type(new com.google.flatbuffers.reflection.Type()); } - public com.google.flatbuffers.reflection.Type type(com.google.flatbuffers.reflection.Type obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } - public int id() { int o = __offset(8); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; } - public int offset() { int o = __offset(10); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; } - public long defaultInteger() { int o = __offset(12); return o != 0 ? bb.getLong(o + bb_pos) : 0L; } - public double defaultReal() { int o = __offset(14); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; } - public boolean deprecated() { int o = __offset(16); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } - public boolean required() { int o = __offset(18); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } - public boolean key() { int o = __offset(20); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } - public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); } - public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(22); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int attributesLength() { int o = __offset(22); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(22); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(22); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(22); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public String documentation(int j) { int o = __offset(24); return o != 0 ? __string(__vector(o) + j * 4) : null; } - public int documentationLength() { int o = __offset(24); return o != 0 ? __vector_len(o) : 0; } - public StringVector documentationVector() { return documentationVector(new StringVector()); } - public StringVector documentationVector(StringVector obj) { int o = __offset(24); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public boolean optional() { int o = __offset(26); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } - /** - * Number of padding octets to always add after this field. Structs only. - */ - public int padding() { int o = __offset(28); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; } - /** - * If the field uses 64-bit offsets. - */ - public boolean offset64() { int o = __offset(30); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } - - public static int createField(FlatBufferBuilder builder, - int nameOffset, - int typeOffset, - int id, - int offset, - long defaultInteger, - double defaultReal, - boolean deprecated, - boolean required, - boolean key, - int attributesOffset, - int documentationOffset, - boolean optional, - int padding, - boolean offset64) { - builder.startTable(14); - Field.addDefaultReal(builder, defaultReal); - Field.addDefaultInteger(builder, defaultInteger); - Field.addDocumentation(builder, documentationOffset); - Field.addAttributes(builder, attributesOffset); - Field.addType(builder, typeOffset); - Field.addName(builder, nameOffset); - Field.addPadding(builder, padding); - Field.addOffset(builder, offset); - Field.addId(builder, id); - Field.addOffset64(builder, offset64); - Field.addOptional(builder, optional); - Field.addKey(builder, key); - Field.addRequired(builder, required); - Field.addDeprecated(builder, deprecated); - return Field.endField(builder); - } - - public static void startField(FlatBufferBuilder builder) { builder.startTable(14); } - public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); } - public static void addType(FlatBufferBuilder builder, int typeOffset) { builder.addOffset(1, typeOffset, 0); } - public static void addId(FlatBufferBuilder builder, int id) { builder.addShort(2, (short) id, (short) 0); } - public static void addOffset(FlatBufferBuilder builder, int offset) { builder.addShort(3, (short) offset, (short) 0); } - public static void addDefaultInteger(FlatBufferBuilder builder, long defaultInteger) { builder.addLong(4, defaultInteger, 0L); } - public static void addDefaultReal(FlatBufferBuilder builder, double defaultReal) { builder.addDouble(5, defaultReal, 0.0); } - public static void addDeprecated(FlatBufferBuilder builder, boolean deprecated) { builder.addBoolean(6, deprecated, false); } - public static void addRequired(FlatBufferBuilder builder, boolean required) { builder.addBoolean(7, required, false); } - public static void addKey(FlatBufferBuilder builder, boolean key) { builder.addBoolean(8, key, false); } - public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(9, attributesOffset, 0); } - public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(10, documentationOffset, 0); } - public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addOptional(FlatBufferBuilder builder, boolean optional) { builder.addBoolean(11, optional, false); } - public static void addPadding(FlatBufferBuilder builder, int padding) { builder.addShort(12, (short) padding, (short) 0); } - public static void addOffset64(FlatBufferBuilder builder, boolean offset64) { builder.addBoolean(13, offset64, false); } - public static int endField(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // name - builder.required(o, 6); // type - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); } - - public static Field __lookup_by_key(Field obj, int vectorLocation, String key, ByteBuffer bb) { - byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8); - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb); - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new Field() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public Field get(int j) { return get(new Field(), j); } - public Field get(Field obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public Field getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); } - public Field getByKey(Field obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/KeyValue.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/KeyValue.java deleted file mode 100644 index 546404bc2..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/KeyValue.java +++ /dev/null @@ -1,88 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class KeyValue extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static KeyValue getRootAsKeyValue(ByteBuffer _bb) { return getRootAsKeyValue(_bb, new KeyValue()); } - public static KeyValue getRootAsKeyValue(ByteBuffer _bb, KeyValue obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public KeyValue __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public String key() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer keyAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer keyInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - public String value() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer valueAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } - public ByteBuffer valueInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 6, 1); } - - public static int createKeyValue(FlatBufferBuilder builder, - int keyOffset, - int valueOffset) { - builder.startTable(2); - KeyValue.addValue(builder, valueOffset); - KeyValue.addKey(builder, keyOffset); - return KeyValue.endKeyValue(builder); - } - - public static void startKeyValue(FlatBufferBuilder builder) { builder.startTable(2); } - public static void addKey(FlatBufferBuilder builder, int keyOffset) { builder.addOffset(keyOffset); builder.slot(0); } - public static void addValue(FlatBufferBuilder builder, int valueOffset) { builder.addOffset(1, valueOffset, 0); } - public static int endKeyValue(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // key - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); } - - public static KeyValue __lookup_by_key(KeyValue obj, int vectorLocation, String key, ByteBuffer bb) { - byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8); - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb); - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new KeyValue() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public KeyValue get(int j) { return get(new KeyValue(), j); } - public KeyValue get(KeyValue obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public KeyValue getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); } - public KeyValue getByKey(KeyValue obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Object.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Object.java deleted file mode 100644 index 70d73263a..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Object.java +++ /dev/null @@ -1,137 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class Object extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static Object getRootAsObject(ByteBuffer _bb) { return getRootAsObject(_bb, new Object()); } - public static Object getRootAsObject(ByteBuffer _bb, Object obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public Object __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - public com.google.flatbuffers.reflection.Field fields(int j) { return fields(new com.google.flatbuffers.reflection.Field(), j); } - public com.google.flatbuffers.reflection.Field fields(com.google.flatbuffers.reflection.Field obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int fieldsLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.Field fieldsByKey(String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Field.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Field fieldsByKey(com.google.flatbuffers.reflection.Field obj, String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Field.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Field.Vector fieldsVector() { return fieldsVector(new com.google.flatbuffers.reflection.Field.Vector()); } - public com.google.flatbuffers.reflection.Field.Vector fieldsVector(com.google.flatbuffers.reflection.Field.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public boolean isStruct() { int o = __offset(8); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } - public int minalign() { int o = __offset(10); return o != 0 ? bb.getInt(o + bb_pos) : 0; } - public int bytesize() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; } - public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); } - public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(14); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int attributesLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public String documentation(int j) { int o = __offset(16); return o != 0 ? __string(__vector(o) + j * 4) : null; } - public int documentationLength() { int o = __offset(16); return o != 0 ? __vector_len(o) : 0; } - public StringVector documentationVector() { return documentationVector(new StringVector()); } - public StringVector documentationVector(StringVector obj) { int o = __offset(16); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - /** - * File that this Object is declared in. - */ - public String declarationFile() { int o = __offset(18); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer declarationFileAsByteBuffer() { return __vector_as_bytebuffer(18, 1); } - public ByteBuffer declarationFileInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 18, 1); } - - public static int createObject(FlatBufferBuilder builder, - int nameOffset, - int fieldsOffset, - boolean isStruct, - int minalign, - int bytesize, - int attributesOffset, - int documentationOffset, - int declarationFileOffset) { - builder.startTable(8); - Object.addDeclarationFile(builder, declarationFileOffset); - Object.addDocumentation(builder, documentationOffset); - Object.addAttributes(builder, attributesOffset); - Object.addBytesize(builder, bytesize); - Object.addMinalign(builder, minalign); - Object.addFields(builder, fieldsOffset); - Object.addName(builder, nameOffset); - Object.addIsStruct(builder, isStruct); - return Object.endObject(builder); - } - - public static void startObject(FlatBufferBuilder builder) { builder.startTable(8); } - public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); } - public static void addFields(FlatBufferBuilder builder, int fieldsOffset) { builder.addOffset(1, fieldsOffset, 0); } - public static int createFieldsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startFieldsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addIsStruct(FlatBufferBuilder builder, boolean isStruct) { builder.addBoolean(2, isStruct, false); } - public static void addMinalign(FlatBufferBuilder builder, int minalign) { builder.addInt(3, minalign, 0); } - public static void addBytesize(FlatBufferBuilder builder, int bytesize) { builder.addInt(4, bytesize, 0); } - public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(5, attributesOffset, 0); } - public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(6, documentationOffset, 0); } - public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDeclarationFile(FlatBufferBuilder builder, int declarationFileOffset) { builder.addOffset(7, declarationFileOffset, 0); } - public static int endObject(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // name - builder.required(o, 6); // fields - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); } - - public static Object __lookup_by_key(Object obj, int vectorLocation, String key, ByteBuffer bb) { - byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8); - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb); - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new Object() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public Object get(int j) { return get(new Object(), j); } - public Object get(Object obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public Object getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); } - public Object getByKey(Object obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/RPCCall.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/RPCCall.java deleted file mode 100644 index f970d6ecb..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/RPCCall.java +++ /dev/null @@ -1,115 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class RPCCall extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static RPCCall getRootAsRPCCall(ByteBuffer _bb) { return getRootAsRPCCall(_bb, new RPCCall()); } - public static RPCCall getRootAsRPCCall(ByteBuffer _bb, RPCCall obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public RPCCall __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - public com.google.flatbuffers.reflection.Object request() { return request(new com.google.flatbuffers.reflection.Object()); } - public com.google.flatbuffers.reflection.Object request(com.google.flatbuffers.reflection.Object obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } - public com.google.flatbuffers.reflection.Object response() { return response(new com.google.flatbuffers.reflection.Object()); } - public com.google.flatbuffers.reflection.Object response(com.google.flatbuffers.reflection.Object obj) { int o = __offset(8); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); } - public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(10); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int attributesLength() { int o = __offset(10); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(10); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(10); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(10); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public String documentation(int j) { int o = __offset(12); return o != 0 ? __string(__vector(o) + j * 4) : null; } - public int documentationLength() { int o = __offset(12); return o != 0 ? __vector_len(o) : 0; } - public StringVector documentationVector() { return documentationVector(new StringVector()); } - public StringVector documentationVector(StringVector obj) { int o = __offset(12); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - - public static int createRPCCall(FlatBufferBuilder builder, - int nameOffset, - int requestOffset, - int responseOffset, - int attributesOffset, - int documentationOffset) { - builder.startTable(5); - RPCCall.addDocumentation(builder, documentationOffset); - RPCCall.addAttributes(builder, attributesOffset); - RPCCall.addResponse(builder, responseOffset); - RPCCall.addRequest(builder, requestOffset); - RPCCall.addName(builder, nameOffset); - return RPCCall.endRPCCall(builder); - } - - public static void startRPCCall(FlatBufferBuilder builder) { builder.startTable(5); } - public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); } - public static void addRequest(FlatBufferBuilder builder, int requestOffset) { builder.addOffset(1, requestOffset, 0); } - public static void addResponse(FlatBufferBuilder builder, int responseOffset) { builder.addOffset(2, responseOffset, 0); } - public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(3, attributesOffset, 0); } - public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(4, documentationOffset, 0); } - public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static int endRPCCall(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // name - builder.required(o, 6); // request - builder.required(o, 8); // response - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); } - - public static RPCCall __lookup_by_key(RPCCall obj, int vectorLocation, String key, ByteBuffer bb) { - byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8); - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb); - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new RPCCall() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public RPCCall get(int j) { return get(new RPCCall(), j); } - public RPCCall get(RPCCall obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public RPCCall getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); } - public RPCCall getByKey(RPCCall obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Schema.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Schema.java deleted file mode 100644 index 1cbe7b3b6..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Schema.java +++ /dev/null @@ -1,127 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class Schema extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static Schema getRootAsSchema(ByteBuffer _bb) { return getRootAsSchema(_bb, new Schema()); } - public static Schema getRootAsSchema(ByteBuffer _bb, Schema obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public static boolean SchemaBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "BFBS"); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public Schema __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public com.google.flatbuffers.reflection.Object objects(int j) { return objects(new com.google.flatbuffers.reflection.Object(), j); } - public com.google.flatbuffers.reflection.Object objects(com.google.flatbuffers.reflection.Object obj, int j) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int objectsLength() { int o = __offset(4); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.Object objectsByKey(String key) { int o = __offset(4); return o != 0 ? com.google.flatbuffers.reflection.Object.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Object objectsByKey(com.google.flatbuffers.reflection.Object obj, String key) { int o = __offset(4); return o != 0 ? com.google.flatbuffers.reflection.Object.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Object.Vector objectsVector() { return objectsVector(new com.google.flatbuffers.reflection.Object.Vector()); } - public com.google.flatbuffers.reflection.Object.Vector objectsVector(com.google.flatbuffers.reflection.Object.Vector obj) { int o = __offset(4); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public com.google.flatbuffers.reflection.Enum enums(int j) { return enums(new com.google.flatbuffers.reflection.Enum(), j); } - public com.google.flatbuffers.reflection.Enum enums(com.google.flatbuffers.reflection.Enum obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int enumsLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.Enum enumsByKey(String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Enum.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Enum enumsByKey(com.google.flatbuffers.reflection.Enum obj, String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Enum.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Enum.Vector enumsVector() { return enumsVector(new com.google.flatbuffers.reflection.Enum.Vector()); } - public com.google.flatbuffers.reflection.Enum.Vector enumsVector(com.google.flatbuffers.reflection.Enum.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public String fileIdent() { int o = __offset(8); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer fileIdentAsByteBuffer() { return __vector_as_bytebuffer(8, 1); } - public ByteBuffer fileIdentInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 8, 1); } - public String fileExt() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer fileExtAsByteBuffer() { return __vector_as_bytebuffer(10, 1); } - public ByteBuffer fileExtInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 10, 1); } - public com.google.flatbuffers.reflection.Object rootTable() { return rootTable(new com.google.flatbuffers.reflection.Object()); } - public com.google.flatbuffers.reflection.Object rootTable(com.google.flatbuffers.reflection.Object obj) { int o = __offset(12); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } - public com.google.flatbuffers.reflection.Service services(int j) { return services(new com.google.flatbuffers.reflection.Service(), j); } - public com.google.flatbuffers.reflection.Service services(com.google.flatbuffers.reflection.Service obj, int j) { int o = __offset(14); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int servicesLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.Service servicesByKey(String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.Service.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Service servicesByKey(com.google.flatbuffers.reflection.Service obj, String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.Service.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.Service.Vector servicesVector() { return servicesVector(new com.google.flatbuffers.reflection.Service.Vector()); } - public com.google.flatbuffers.reflection.Service.Vector servicesVector(com.google.flatbuffers.reflection.Service.Vector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public long advancedFeatures() { int o = __offset(16); return o != 0 ? bb.getLong(o + bb_pos) : 0L; } - /** - * All the files used in this compilation. Files are relative to where - * flatc was invoked. - */ - public com.google.flatbuffers.reflection.SchemaFile fbsFiles(int j) { return fbsFiles(new com.google.flatbuffers.reflection.SchemaFile(), j); } - public com.google.flatbuffers.reflection.SchemaFile fbsFiles(com.google.flatbuffers.reflection.SchemaFile obj, int j) { int o = __offset(18); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int fbsFilesLength() { int o = __offset(18); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.SchemaFile fbsFilesByKey(String key) { int o = __offset(18); return o != 0 ? com.google.flatbuffers.reflection.SchemaFile.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.SchemaFile fbsFilesByKey(com.google.flatbuffers.reflection.SchemaFile obj, String key) { int o = __offset(18); return o != 0 ? com.google.flatbuffers.reflection.SchemaFile.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.SchemaFile.Vector fbsFilesVector() { return fbsFilesVector(new com.google.flatbuffers.reflection.SchemaFile.Vector()); } - public com.google.flatbuffers.reflection.SchemaFile.Vector fbsFilesVector(com.google.flatbuffers.reflection.SchemaFile.Vector obj) { int o = __offset(18); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - - public static int createSchema(FlatBufferBuilder builder, - int objectsOffset, - int enumsOffset, - int fileIdentOffset, - int fileExtOffset, - int rootTableOffset, - int servicesOffset, - long advancedFeatures, - int fbsFilesOffset) { - builder.startTable(8); - Schema.addAdvancedFeatures(builder, advancedFeatures); - Schema.addFbsFiles(builder, fbsFilesOffset); - Schema.addServices(builder, servicesOffset); - Schema.addRootTable(builder, rootTableOffset); - Schema.addFileExt(builder, fileExtOffset); - Schema.addFileIdent(builder, fileIdentOffset); - Schema.addEnums(builder, enumsOffset); - Schema.addObjects(builder, objectsOffset); - return Schema.endSchema(builder); - } - - public static void startSchema(FlatBufferBuilder builder) { builder.startTable(8); } - public static void addObjects(FlatBufferBuilder builder, int objectsOffset) { builder.addOffset(0, objectsOffset, 0); } - public static int createObjectsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startObjectsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addEnums(FlatBufferBuilder builder, int enumsOffset) { builder.addOffset(1, enumsOffset, 0); } - public static int createEnumsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startEnumsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addFileIdent(FlatBufferBuilder builder, int fileIdentOffset) { builder.addOffset(2, fileIdentOffset, 0); } - public static void addFileExt(FlatBufferBuilder builder, int fileExtOffset) { builder.addOffset(3, fileExtOffset, 0); } - public static void addRootTable(FlatBufferBuilder builder, int rootTableOffset) { builder.addOffset(4, rootTableOffset, 0); } - public static void addServices(FlatBufferBuilder builder, int servicesOffset) { builder.addOffset(5, servicesOffset, 0); } - public static int createServicesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startServicesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addAdvancedFeatures(FlatBufferBuilder builder, long advancedFeatures) { builder.addLong(6, advancedFeatures, 0L); } - public static void addFbsFiles(FlatBufferBuilder builder, int fbsFilesOffset) { builder.addOffset(7, fbsFilesOffset, 0); } - public static int createFbsFilesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startFbsFilesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static int endSchema(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // objects - builder.required(o, 6); // enums - return o; - } - public static void finishSchemaBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset, "BFBS"); } - public static void finishSizePrefixedSchemaBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset, "BFBS"); } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public Schema get(int j) { return get(new Schema(), j); } - public Schema get(Schema obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/SchemaFile.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/SchemaFile.java deleted file mode 100644 index a9a7630c7..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/SchemaFile.java +++ /dev/null @@ -1,102 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -/** - * File specific information. - * Symbols declared within a file may be recovered by iterating over all - * symbols and examining the `declaration_file` field. - */ -@SuppressWarnings("unused") -public final class SchemaFile extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb) { return getRootAsSchemaFile(_bb, new SchemaFile()); } - public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb, SchemaFile obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public SchemaFile __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - /** - * Filename, relative to project root. - */ - public String filename() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer filenameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer filenameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - /** - * Names of included files, relative to project root. - */ - public String includedFilenames(int j) { int o = __offset(6); return o != 0 ? __string(__vector(o) + j * 4) : null; } - public int includedFilenamesLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; } - public StringVector includedFilenamesVector() { return includedFilenamesVector(new StringVector()); } - public StringVector includedFilenamesVector(StringVector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - - public static int createSchemaFile(FlatBufferBuilder builder, - int filenameOffset, - int includedFilenamesOffset) { - builder.startTable(2); - SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset); - SchemaFile.addFilename(builder, filenameOffset); - return SchemaFile.endSchemaFile(builder); - } - - public static void startSchemaFile(FlatBufferBuilder builder) { builder.startTable(2); } - public static void addFilename(FlatBufferBuilder builder, int filenameOffset) { builder.addOffset(filenameOffset); builder.slot(0); } - public static void addIncludedFilenames(FlatBufferBuilder builder, int includedFilenamesOffset) { builder.addOffset(1, includedFilenamesOffset, 0); } - public static int createIncludedFilenamesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startIncludedFilenamesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static int endSchemaFile(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // filename - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); } - - public static SchemaFile __lookup_by_key(SchemaFile obj, int vectorLocation, String key, ByteBuffer bb) { - byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8); - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb); - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new SchemaFile() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public SchemaFile get(int j) { return get(new SchemaFile(), j); } - public SchemaFile get(SchemaFile obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public SchemaFile getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); } - public SchemaFile getByKey(SchemaFile obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Service.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Service.java deleted file mode 100644 index d33a6e955..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Service.java +++ /dev/null @@ -1,124 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class Service extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static Service getRootAsService(ByteBuffer _bb) { return getRootAsService(_bb, new Service()); } - public static Service getRootAsService(ByteBuffer _bb, Service obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public Service __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } - public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); } - public com.google.flatbuffers.reflection.RPCCall calls(int j) { return calls(new com.google.flatbuffers.reflection.RPCCall(), j); } - public com.google.flatbuffers.reflection.RPCCall calls(com.google.flatbuffers.reflection.RPCCall obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int callsLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.RPCCall callsByKey(String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.RPCCall.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.RPCCall callsByKey(com.google.flatbuffers.reflection.RPCCall obj, String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.RPCCall.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.RPCCall.Vector callsVector() { return callsVector(new com.google.flatbuffers.reflection.RPCCall.Vector()); } - public com.google.flatbuffers.reflection.RPCCall.Vector callsVector(com.google.flatbuffers.reflection.RPCCall.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); } - public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(8); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; } - public int attributesLength() { int o = __offset(8); return o != 0 ? __vector_len(o) : 0; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(8); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(8); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); } - public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(8); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public String documentation(int j) { int o = __offset(10); return o != 0 ? __string(__vector(o) + j * 4) : null; } - public int documentationLength() { int o = __offset(10); return o != 0 ? __vector_len(o) : 0; } - public StringVector documentationVector() { return documentationVector(new StringVector()); } - public StringVector documentationVector(StringVector obj) { int o = __offset(10); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - /** - * File that this Service is declared in. - */ - public String declarationFile() { int o = __offset(12); return o != 0 ? __string(o + bb_pos) : null; } - public ByteBuffer declarationFileAsByteBuffer() { return __vector_as_bytebuffer(12, 1); } - public ByteBuffer declarationFileInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 12, 1); } - - public static int createService(FlatBufferBuilder builder, - int nameOffset, - int callsOffset, - int attributesOffset, - int documentationOffset, - int declarationFileOffset) { - builder.startTable(5); - Service.addDeclarationFile(builder, declarationFileOffset); - Service.addDocumentation(builder, documentationOffset); - Service.addAttributes(builder, attributesOffset); - Service.addCalls(builder, callsOffset); - Service.addName(builder, nameOffset); - return Service.endService(builder); - } - - public static void startService(FlatBufferBuilder builder) { builder.startTable(5); } - public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); } - public static void addCalls(FlatBufferBuilder builder, int callsOffset) { builder.addOffset(1, callsOffset, 0); } - public static int createCallsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startCallsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(2, attributesOffset, 0); } - public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(3, documentationOffset, 0); } - public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } - public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } - public static void addDeclarationFile(FlatBufferBuilder builder, int declarationFileOffset) { builder.addOffset(4, declarationFileOffset, 0); } - public static int endService(FlatBufferBuilder builder) { - int o = builder.endTable(); - builder.required(o, 4); // name - return o; - } - - @Override - protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); } - - public static Service __lookup_by_key(Service obj, int vectorLocation, String key, ByteBuffer bb) { - byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8); - int span = bb.getInt(vectorLocation - 4); - int start = 0; - while (span != 0) { - int middle = span / 2; - int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb); - int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb); - if (comp > 0) { - span = middle; - } else if (comp < 0) { - middle++; - start += middle; - span -= middle; - } else { - return (obj == null ? new Service() : obj).__assign(tableOffset, bb); - } - } - return null; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public Service get(int j) { return get(new Service(), j); } - public Service get(Service obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - public Service getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); } - public Service getByKey(Service obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Type.java b/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Type.java deleted file mode 100644 index ca0e18ac6..000000000 --- a/third_party/flatbuffers/java/src/main/java/com/google/flatbuffers/reflection/Type.java +++ /dev/null @@ -1,79 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -package com.google.flatbuffers.reflection; - -import com.google.flatbuffers.BaseVector; -import com.google.flatbuffers.BooleanVector; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.Constants; -import com.google.flatbuffers.DoubleVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FloatVector; -import com.google.flatbuffers.IntVector; -import com.google.flatbuffers.LongVector; -import com.google.flatbuffers.ShortVector; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.Struct; -import com.google.flatbuffers.Table; -import com.google.flatbuffers.UnionVector; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -@SuppressWarnings("unused") -public final class Type extends Table { - public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_25(); } - public static Type getRootAsType(ByteBuffer _bb) { return getRootAsType(_bb, new Type()); } - public static Type getRootAsType(ByteBuffer _bb, Type obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } - public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } - public Type __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - - public byte baseType() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) : 0; } - public byte element() { int o = __offset(6); return o != 0 ? bb.get(o + bb_pos) : 0; } - public int index() { int o = __offset(8); return o != 0 ? bb.getInt(o + bb_pos) : -1; } - public int fixedLength() { int o = __offset(10); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; } - /** - * The size (octets) of the `base_type` field. - */ - public long baseSize() { int o = __offset(12); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 4L; } - /** - * The size (octets) of the `element` field, if present. - */ - public long elementSize() { int o = __offset(14); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; } - - public static int createType(FlatBufferBuilder builder, - byte baseType, - byte element, - int index, - int fixedLength, - long baseSize, - long elementSize) { - builder.startTable(6); - Type.addElementSize(builder, elementSize); - Type.addBaseSize(builder, baseSize); - Type.addIndex(builder, index); - Type.addFixedLength(builder, fixedLength); - Type.addElement(builder, element); - Type.addBaseType(builder, baseType); - return Type.endType(builder); - } - - public static void startType(FlatBufferBuilder builder) { builder.startTable(6); } - public static void addBaseType(FlatBufferBuilder builder, byte baseType) { builder.addByte(0, baseType, 0); } - public static void addElement(FlatBufferBuilder builder, byte element) { builder.addByte(1, element, 0); } - public static void addIndex(FlatBufferBuilder builder, int index) { builder.addInt(2, index, -1); } - public static void addFixedLength(FlatBufferBuilder builder, int fixedLength) { builder.addShort(3, (short) fixedLength, (short) 0); } - public static void addBaseSize(FlatBufferBuilder builder, long baseSize) { builder.addInt(4, (int) baseSize, (int) 4L); } - public static void addElementSize(FlatBufferBuilder builder, long elementSize) { builder.addInt(5, (int) elementSize, (int) 0L); } - public static int endType(FlatBufferBuilder builder) { - int o = builder.endTable(); - return o; - } - - public static final class Vector extends BaseVector { - public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } - - public Type get(int j) { return get(new Type(), j); } - public Type get(Type obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } - } -} - diff --git a/third_party/flatbuffers/java/src/test/java/DictionaryLookup b/third_party/flatbuffers/java/src/test/java/DictionaryLookup deleted file mode 120000 index 231bcd800..000000000 --- a/third_party/flatbuffers/java/src/test/java/DictionaryLookup +++ /dev/null @@ -1 +0,0 @@ -../../../../tests/DictionaryLookup \ No newline at end of file diff --git a/third_party/flatbuffers/java/src/test/java/JavaTest.java b/third_party/flatbuffers/java/src/test/java/JavaTest.java deleted file mode 100644 index c392e040e..000000000 --- a/third_party/flatbuffers/java/src/test/java/JavaTest.java +++ /dev/null @@ -1,1533 +0,0 @@ - -import static com.google.flatbuffers.Constants.*; -import static com.google.common.truth.Truth.assertThat; - -import DictionaryLookup.*; -import MyGame.Example.*; -import com.google.common.io.ByteStreams; -import optional_scalars.ScalarStuff; -import optional_scalars.OptionalByte; -import NamespaceA.*; -import NamespaceA.NamespaceB.*; -import com.google.flatbuffers.ByteBufferUtil; -import com.google.flatbuffers.ByteVector; -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.FlexBuffers; -import com.google.flatbuffers.FlexBuffersBuilder; -import com.google.flatbuffers.StringVector; -import com.google.flatbuffers.UnionVector; - -import com.google.flatbuffers.FlexBuffers.FlexBufferException; -import com.google.flatbuffers.FlexBuffers.Reference; -import com.google.flatbuffers.FlexBuffers.Vector; -import com.google.flatbuffers.ArrayReadWriteBuf; -import com.google.flatbuffers.FlexBuffers.KeyVector; - -import java.io.*; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.channels.FileChannel; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - - -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@RunWith(JUnit4.class) -public class JavaTest { - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - - @org.junit.Test - public void mainTest() throws IOException { - // First, let's test reading a FlatBuffer generated by C++ code: - // This file was generated from monsterdata_test.json - byte[] data = ByteStreams.toByteArray( - JavaTest.class.getClassLoader().getResourceAsStream("monsterdata_test.mon")); - - // Now test it: - ByteBuffer bb = ByteBuffer.wrap(data); - TestBuffer(bb); - TestPackUnpack(bb); - } - - @org.junit.Test - public void testFlatBufferBuilder() { - // We use an initial size of 1 to exercise the reallocation algorithm, - // normally a size larger than the typical FlatBuffer you generate would be - // better for performance. - FlatBufferBuilder fbb = new FlatBufferBuilder(1); - TestBuilderBasics(fbb, true); - TestBuilderBasics(fbb, false); - TestExtendedBuffer(fbb.dataBuffer().asReadOnlyBuffer()); - } - - @org.junit.Test - public void TestEnums() { - assertThat(Color.name(Color.Red)).isEqualTo("Red"); - assertThat(Color.name(Color.Blue)).isEqualTo("Blue"); - assertThat(Any.name(Any.NONE)).isEqualTo("NONE"); - assertThat(Any.name(Any.Monster)).isEqualTo("Monster"); - } - - static void TestBuffer(ByteBuffer bb) { - assertThat(Monster.MonsterBufferHasIdentifier(bb)).isEqualTo(true); - - Monster monster = Monster.getRootAsMonster(bb); - - assertThat(monster.hp()).isEqualTo((short) 80); - // default - assertThat(monster.mana()).isEqualTo((short) 150); - - assertThat(monster.name()).isEqualTo("MyMonster"); - // monster.friendly() // can't access, deprecated - - Vec3 pos = monster.pos(); - assertThat(pos.x()).isEqualTo(1.0f); - assertThat(pos.y()).isEqualTo(2.0f); - assertThat(pos.z()).isEqualTo(3.0f); - assertThat(pos.test1()).isEqualTo(3.0); - // issue: int != byte - assertThat(pos.test2()).isEqualTo((int) Color.Green); - Test t = pos.test3(); - assertThat(t.a()).isEqualTo((short) 5); - assertThat(t.b()).isEqualTo((byte) 6); - - assertThat(monster.testType()).isEqualTo((byte) Any.Monster); - Monster monster2 = new Monster(); - assertThat(monster.test(monster2) != null).isTrue(); - assertThat(monster2.name()).isEqualTo("Fred"); - - assertThat(monster.inventoryLength()).isEqualTo(5); - int invsum = 0; - for (int i = 0; i < monster.inventoryLength(); i++) - invsum += monster.inventory(i); - assertThat(invsum).isEqualTo(10); - - // Method using a vector access object: - ByteVector inventoryVector = monster.inventoryVector(); - assertThat(inventoryVector.length()).isEqualTo(5); - invsum = 0; - for (int i = 0; i < inventoryVector.length(); i++) - invsum += inventoryVector.getAsUnsigned(i); - assertThat(invsum).isEqualTo(10); - - // Alternative way of accessing a vector: - ByteBuffer ibb = monster.inventoryAsByteBuffer(); - invsum = 0; - while (ibb.position() < ibb.limit()) - invsum += ibb.get(); - assertThat(invsum).isEqualTo(10); - - Test test_0 = monster.test4(0); - Test test_1 = monster.test4(1); - assertThat(monster.test4Length()).isEqualTo(2); - assertThat(test_0.a() + test_0.b() + test_1.a() + test_1.b()).isEqualTo((Integer) 100); - - Test.Vector test4Vector = monster.test4Vector(); - test_0 = test4Vector.get(0); - test_1 = test4Vector.get(1); - assertThat(test4Vector.length()).isEqualTo(2); - assertThat(test_0.a() + test_0.b() + test_1.a() + test_1.b()).isEqualTo((Integer) 100); - - assertThat(monster.testarrayofstringLength()).isEqualTo(2); - assertThat(monster.testarrayofstring(0)).isEqualTo("test1"); - assertThat(monster.testarrayofstring(1)).isEqualTo("test2"); - - // Method using a vector access object: - StringVector testarrayofstringVector = monster.testarrayofstringVector(); - assertThat(testarrayofstringVector.length()).isEqualTo(2); - assertThat(testarrayofstringVector.get(0)).isEqualTo("test1"); - assertThat(testarrayofstringVector.get(1)).isEqualTo("test2"); - - assertThat(monster.testbool()).isEqualTo(true); - } - - // this method checks additional fields not present in the binary buffer read from file - // these new tests are performed on top of the regular tests - static void TestExtendedBuffer(ByteBuffer bb) { - TestBuffer(bb); - - Monster monster = Monster.getRootAsMonster(bb); - - assertThat(monster.testhashu32Fnv1()).isEqualTo((Integer.MAX_VALUE + 1L)); - } - - - @org.junit.Test public void TestNamespaceNesting() { - // reference / manipulate these to verify compilation - FlatBufferBuilder fbb = new FlatBufferBuilder(1); - - TableInNestedNS.startTableInNestedNS(fbb); - TableInNestedNS.addFoo(fbb, 1234); - int nestedTableOff = TableInNestedNS.endTableInNestedNS(fbb); - - TableInFirstNS.startTableInFirstNS(fbb); - TableInFirstNS.addFooTable(fbb, nestedTableOff); - int off = TableInFirstNS.endTableInFirstNS(fbb); - } - - @org.junit.Test public void TestNestedFlatBuffer() { - final String nestedMonsterName = "NestedMonsterName"; - final short nestedMonsterHp = 600; - final short nestedMonsterMana = 1024; - - FlatBufferBuilder fbb1 = new FlatBufferBuilder(16); - int str1 = fbb1.createString(nestedMonsterName); - Monster.startMonster(fbb1); - Monster.addName(fbb1, str1); - Monster.addHp(fbb1, nestedMonsterHp); - Monster.addMana(fbb1, nestedMonsterMana); - int monster1 = Monster.endMonster(fbb1); - Monster.finishMonsterBuffer(fbb1, monster1); - byte[] fbb1Bytes = fbb1.sizedByteArray(); - fbb1 = null; - - FlatBufferBuilder fbb2 = new FlatBufferBuilder(16); - int str2 = fbb2.createString("My Monster"); - int nestedBuffer = Monster.createTestnestedflatbufferVector(fbb2, fbb1Bytes); - Monster.startMonster(fbb2); - Monster.addName(fbb2, str2); - Monster.addHp(fbb2, (short)50); - Monster.addMana(fbb2, (short)32); - Monster.addTestnestedflatbuffer(fbb2, nestedBuffer); - int monster = Monster.endMonster(fbb2); - Monster.finishMonsterBuffer(fbb2, monster); - - // Now test the data extracted from the nested buffer - Monster mons = Monster.getRootAsMonster(fbb2.dataBuffer()); - Monster nestedMonster = mons.testnestedflatbufferAsMonster(); - - assertThat(nestedMonsterMana).isEqualTo(nestedMonster.mana()); - assertThat(nestedMonsterHp).isEqualTo(nestedMonster.hp()); - assertThat(nestedMonsterName).isEqualTo(nestedMonster.name()); - } - - @org.junit.Test public void TestCreateByteVector() { - FlatBufferBuilder fbb = new FlatBufferBuilder(16); - int str = fbb.createString("MyMonster"); - byte[] inventory = new byte[] { 0, 1, 2, 3, 4 }; - int vec = fbb.createByteVector(inventory); - Monster.startMonster(fbb); - Monster.addInventory(fbb, vec); - Monster.addName(fbb, str); - int monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat((Integer) monsterObject.inventory(1)).isEqualTo((int)inventory[1]); - assertThat(monsterObject.inventoryLength()).isEqualTo(inventory.length); - ByteVector inventoryVector = monsterObject.inventoryVector(); - assertThat(inventoryVector.getAsUnsigned(1)).isEqualTo((int)inventory[1]); - assertThat(inventoryVector.length()).isEqualTo(inventory.length); - - assertThat(ByteBuffer.wrap(inventory)).isEqualTo( - monsterObject.inventoryAsByteBuffer()); - } - - @org.junit.Test public void TestCreateUninitializedVector() { - FlatBufferBuilder fbb = new FlatBufferBuilder(16); - int str = fbb.createString("MyMonster"); - byte[] inventory = new byte[] { 0, 1, 2, 3, 4 }; - ByteBuffer bb = fbb.createUnintializedVector(1, inventory.length, 1); - for (byte i:inventory) { - bb.put(i); - } - int vec = fbb.endVector(); - Monster.startMonster(fbb); - Monster.addInventory(fbb, vec); - Monster.addName(fbb, str); - int monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat((Integer) monsterObject.inventory(1)).isEqualTo((int)inventory[1]); - assertThat(monsterObject.inventoryLength()).isEqualTo(inventory.length); - ByteVector inventoryVector = monsterObject.inventoryVector(); - assertThat(inventoryVector.getAsUnsigned(1)).isEqualTo((int)inventory[1]); - assertThat(inventoryVector.length()).isEqualTo(inventory.length); - assertThat(ByteBuffer.wrap(inventory)).isEqualTo( - monsterObject.inventoryAsByteBuffer()); - } - - @org.junit.Test public void TestByteBufferFactory() throws IOException { - File file = tempFolder.newFile("javatest.bin"); - final class MappedByteBufferFactory extends FlatBufferBuilder.ByteBufferFactory { - @Override - public ByteBuffer newByteBuffer(int capacity) { - ByteBuffer bb; - try { - RandomAccessFile f = new RandomAccessFile(file, "rw"); - bb = f.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, capacity).order(ByteOrder.LITTLE_ENDIAN); - f.close(); - } catch(Throwable e) { - System.out.println("FlatBuffers test: couldn't map ByteBuffer to a file"); - bb = null; - } - return bb; - } - } - - FlatBufferBuilder fbb = new FlatBufferBuilder(1, new MappedByteBufferFactory()); - - TestBuilderBasics(fbb, false); - } - - @org.junit.Test public void TestSizedInputStream() { - // Test on default FlatBufferBuilder that uses HeapByteBuffer - FlatBufferBuilder fbb = new FlatBufferBuilder(1); - - TestBuilderBasics(fbb, false); - - InputStream in = fbb.sizedInputStream(); - byte[] array = fbb.sizedByteArray(); - int count = 0; - int currentVal = 0; - - while (currentVal != -1 && count < array.length) { - try { - currentVal = in.read(); - } catch(java.io.IOException e) { - System.out.println("FlatBuffers test: couldn't read from InputStream"); - return; - } - assertThat((byte)currentVal).isEqualTo(array[count]); - count++; - } - assertThat(count).isEqualTo(array.length); - } - - void TestBuilderBasics(FlatBufferBuilder fbb, boolean sizePrefix) { - int[] names = {fbb.createString("Frodo"), fbb.createString("Barney"), fbb.createString("Wilma")}; - int[] off = new int[3]; - Monster.startMonster(fbb); - Monster.addName(fbb, names[0]); - off[0] = Monster.endMonster(fbb); - Monster.startMonster(fbb); - Monster.addName(fbb, names[1]); - off[1] = Monster.endMonster(fbb); - Monster.startMonster(fbb); - Monster.addName(fbb, names[2]); - off[2] = Monster.endMonster(fbb); - int sortMons = fbb.createSortedVectorOfTables(new Monster(), off); - - // We set up the same values as monsterdata.json: - - int str = fbb.createString("MyMonster"); - - int inv = Monster.createInventoryVector(fbb, new byte[] { 0, 1, 2, 3, 4 }); - - int fred = fbb.createString("Fred"); - Monster.startMonster(fbb); - Monster.addName(fbb, fred); - int mon2 = Monster.endMonster(fbb); - - Monster.startTest4Vector(fbb, 2); - Test.createTest(fbb, (short)10, (byte)20); - Test.createTest(fbb, (short)30, (byte)40); - int test4 = fbb.endVector(); - - int testArrayOfString = Monster.createTestarrayofstringVector(fbb, new int[] { - fbb.createString("test1"), - fbb.createString("test2") - }); - - Monster.startMonster(fbb); - Monster.addPos(fbb, Vec3.createVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0, - Color.Green, (short)5, (byte)6)); - Monster.addHp(fbb, (short)80); - Monster.addName(fbb, str); - Monster.addInventory(fbb, inv); - Monster.addTestType(fbb, (byte)Any.Monster); - Monster.addTest(fbb, mon2); - Monster.addTest4(fbb, test4); - Monster.addTestarrayofstring(fbb, testArrayOfString); - Monster.addTestbool(fbb, true); - Monster.addTesthashu32Fnv1(fbb, Integer.MAX_VALUE + 1L); - Monster.addTestarrayoftables(fbb, sortMons); - int mon = Monster.endMonster(fbb); - - if (sizePrefix) { - Monster.finishSizePrefixedMonsterBuffer(fbb, mon); - } else { - Monster.finishMonsterBuffer(fbb, mon); - } - - // Write the result to a file for debugging purposes: - // Note that the binaries are not necessarily identical, since the JSON - // parser may serialize in a slightly different order than the above - // Java code. They are functionally equivalent though. - - try { - String filename = "monsterdata_java_wire" + (sizePrefix ? "_sp" : "") + ".mon"; - FileChannel fc = new FileOutputStream(tempFolder.newFile(filename)).getChannel(); - fc.write(fbb.dataBuffer().duplicate()); - fc.close(); - } catch(java.io.IOException e) { - System.out.println("FlatBuffers test: couldn't write file"); - return; - } - - // Test it: - ByteBuffer dataBuffer = fbb.dataBuffer(); - if (sizePrefix) { - assertThat(ByteBufferUtil.getSizePrefix(dataBuffer) + SIZE_PREFIX_LENGTH).isEqualTo( - dataBuffer.remaining()); - dataBuffer = ByteBufferUtil.removeSizePrefix(dataBuffer); - } - TestExtendedBuffer(dataBuffer); - - // Make sure it also works with read only ByteBuffers. This is slower, - // since creating strings incurs an additional copy - // (see Table.__string). - TestExtendedBuffer(dataBuffer.asReadOnlyBuffer()); - - //Attempt to mutate Monster fields and check whether the buffer has been mutated properly - // revert to original values after testing - Monster monster = Monster.getRootAsMonster(dataBuffer); - - // mana is optional and does not exist in the buffer so the mutation should fail - // the mana field should retain its default value - assertThat(monster.mutateMana((short)10)).isFalse(); - assertThat(monster.mana()).isEqualTo((short) 150); - - // Accessing a vector of sorted by the key tables - assertThat(monster.testarrayoftables(0).name()).isEqualTo("Barney"); - assertThat(monster.testarrayoftables(1).name()).isEqualTo("Frodo"); - assertThat(monster.testarrayoftables(2).name()).isEqualTo("Wilma"); - Monster.Vector testarrayoftablesVector = monster.testarrayoftablesVector(); - assertThat(testarrayoftablesVector.get(0).name()).isEqualTo("Barney"); - assertThat(testarrayoftablesVector.get(1).name()).isEqualTo("Frodo"); - assertThat(testarrayoftablesVector.get(2).name()).isEqualTo("Wilma"); - - // Example of searching for a table by the key - assertThat(monster.testarrayoftablesByKey("Frodo").name()).isEqualTo("Frodo"); - assertThat(monster.testarrayoftablesByKey("Barney").name()).isEqualTo("Barney"); - assertThat(monster.testarrayoftablesByKey("Wilma").name()).isEqualTo("Wilma"); - assertThat(testarrayoftablesVector.getByKey("Frodo").name()).isEqualTo("Frodo"); - assertThat(testarrayoftablesVector.getByKey("Barney").name()).isEqualTo("Barney"); - assertThat(testarrayoftablesVector.getByKey("Wilma").name()).isEqualTo("Wilma"); - - // testType is an existing field and mutating it should succeed - assertThat(monster.testType()).isEqualTo((byte) Any.Monster); - - //mutate the inventory vector - assertThat(monster.mutateInventory(0, 1)).isTrue(); - assertThat(monster.mutateInventory(1, 2)).isTrue(); - assertThat(monster.mutateInventory(2, 3)).isTrue(); - assertThat(monster.mutateInventory(3, 4)).isTrue(); - assertThat(monster.mutateInventory(4, 5)).isTrue(); - - for (int i = 0; i < monster.inventoryLength(); i++) { - assertThat((Integer) monster.inventory(i)).isEqualTo(i + 1); - } - ByteVector inventoryVector = monster.inventoryVector(); - for (int i = 0; i < inventoryVector.length(); i++) { - assertThat((int)inventoryVector.get(i)).isEqualTo(i + 1); - } - - //reverse mutation - assertThat(monster.mutateInventory(0, 0)).isTrue(); - assertThat(monster.mutateInventory(1, 1)).isTrue(); - assertThat(monster.mutateInventory(2, 2)).isTrue(); - assertThat(monster.mutateInventory(3, 3)).isTrue(); - assertThat(monster.mutateInventory(4, 4)).isTrue(); - - // get a struct field and edit one of its fields - Vec3 pos = monster.pos(); - assertThat(pos.x()).isEqualTo(1.0f); - pos.mutateX(55.0f); - assertThat(pos.x()).isEqualTo(55.0f); - pos.mutateX(1.0f); - assertThat(pos.x()).isEqualTo(1.0f); - } - - @org.junit.Test public void TestVectorOfUnions() { - final FlatBufferBuilder fbb = new FlatBufferBuilder(); - - final int swordAttackDamage = 1; - - final int[] characterVector = new int[] { - Attacker.createAttacker(fbb, swordAttackDamage), - }; - - final byte[] characterTypeVector = new byte[]{ - Character.MuLan, - }; - - Movie.finishMovieBuffer( - fbb, - Movie.createMovie( - fbb, - (byte)0, - (byte)0, - Movie.createCharactersTypeVector(fbb, characterTypeVector), - Movie.createCharactersVector(fbb, characterVector) - ) - ); - - final Movie movie = Movie.getRootAsMovie(fbb.dataBuffer()); - ByteVector charactersTypeByteVector = movie.charactersTypeVector(); - UnionVector charactersVector = movie.charactersVector(); - - assertThat(movie.charactersTypeLength()).isEqualTo(characterTypeVector.length); - assertThat(charactersTypeByteVector.length()).isEqualTo(characterTypeVector.length); - assertThat(movie.charactersLength()).isEqualTo(characterVector.length); - assertThat(charactersVector.length()).isEqualTo(characterVector.length); - - assertThat((Byte) movie.charactersType(0)).isEqualTo(characterTypeVector[0]); - assertThat(charactersTypeByteVector.get(0)).isEqualTo(characterTypeVector[0]); - - assertThat(((Attacker)movie.characters(new Attacker(), 0)).swordAttackDamage()).isEqualTo( - swordAttackDamage); - } - - @org.junit.Test public void TestFixedLengthArrays() { - FlatBufferBuilder builder = new FlatBufferBuilder(0); - - float a; - int[] b = new int[15]; - byte c; - int[][] d_a = new int[2][2]; - byte[] d_b = new byte[2]; - byte[][] d_c = new byte[2][2]; - long[][] d_d = new long[2][2]; - int e; - long[] f = new long[2]; - - a = 0.5f; - for (int i = 0; i < 15; i++) b[i] = i; - c = 1; - d_a[0][0] = 1; - d_a[0][1] = 2; - d_a[1][0] = 3; - d_a[1][1] = 4; - d_b[0] = TestEnum.B; - d_b[1] = TestEnum.C; - d_c[0][0] = TestEnum.A; - d_c[0][1] = TestEnum.B; - d_c[1][0] = TestEnum.C; - d_c[1][1] = TestEnum.B; - d_d[0][0] = -1; - d_d[0][1] = 1; - d_d[1][0] = -2; - d_d[1][1] = 2; - e = 2; - f[0] = -1; - f[1] = 1; - - int arrayOffset = ArrayStruct.createArrayStruct(builder, - a, b, c, d_a, d_b, d_c, d_d, e, f); - - // Create a table with the ArrayStruct. - ArrayTable.startArrayTable(builder); - ArrayTable.addA(builder, arrayOffset); - int tableOffset = ArrayTable.endArrayTable(builder); - - ArrayTable.finishArrayTableBuffer(builder, tableOffset); - - ArrayTable table = ArrayTable.getRootAsArrayTable(builder.dataBuffer()); - NestedStruct nested = new NestedStruct(); - - assertThat(table.a().a()).isEqualTo(0.5f); - for (int i = 0; i < 15; i++) - assertThat(table.a().b(i)).isEqualTo(i); - assertThat(table.a().c()).isEqualTo((byte)1); - assertThat(table.a().d(nested, 0).a(0)).isEqualTo(1); - assertThat(table.a().d(nested, 0).a(1)).isEqualTo(2); - assertThat(table.a().d(nested, 1).a(0)).isEqualTo(3); - assertThat(table.a().d(nested, 1).a(1)).isEqualTo(4); - assertThat(table.a().d(nested, 0).b()).isEqualTo(TestEnum.B); - assertThat(table.a().d(nested, 1).b()).isEqualTo(TestEnum.C); - assertThat(table.a().d(nested, 0).c(0)).isEqualTo(TestEnum.A); - assertThat(table.a().d(nested, 0).c(1)).isEqualTo(TestEnum.B); - assertThat(table.a().d(nested, 1).c(0)).isEqualTo(TestEnum.C); - assertThat(table.a().d(nested, 1).c(1)).isEqualTo(TestEnum.B); - assertThat(table.a().d(nested, 0).d(0)).isEqualTo((long)-1); - assertThat(table.a().d(nested, 0).d(1)).isEqualTo((long)1); - assertThat(table.a().d(nested, 1).d(0)).isEqualTo((long)-2); - assertThat(table.a().d(nested, 1).d(1)).isEqualTo((long)2); - assertThat(table.a().e()).isEqualTo(2); - assertThat(table.a().f(0)).isEqualTo((long)-1); - assertThat(table.a().f(1)).isEqualTo((long)1); - } - - @org.junit.Test public void testFlexBuffersTest() { - FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512), - FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS); - testFlexBuffersTest(builder); - int bufferLimit1 = ((ArrayReadWriteBuf) builder.getBuffer()).limit(); - - // Repeat after clearing the builder to ensure the builder is reusable - builder.clear(); - testFlexBuffersTest(builder); - int bufferLimit2 = ((ArrayReadWriteBuf) builder.getBuffer()).limit(); - assertThat(bufferLimit1).isEqualTo(bufferLimit2); - } - - public static void testFlexBuffersTest(FlexBuffersBuilder builder) { - // Write the equivalent of: - // { vec: [ -100, "Fred", 4.0, false ], bar: [ 1, 2, 3 ], bar3: [ 1, 2, 3 ], - // foo: 100, bool: true, mymap: { foo: "Fred" } } - // It's possible to do this without std::function support as well. - int map1 = builder.startMap(); - - int vec1 = builder.startVector(); - builder.putInt(-100); - builder.putString("Fred"); - builder.putBlob(new byte[]{(byte) 77}); - builder.putBoolean(false); - builder.putInt(Long.MAX_VALUE); - - int map2 = builder.startMap(); - builder.putInt("test", 200); - builder.endMap(null, map2); - - builder.putFloat(150.9); - builder.putFloat(150.9999998); - builder.endVector("vec", vec1, false, false); - - vec1 = builder.startVector(); - builder.putInt(1); - builder.putInt(2); - builder.putInt(3); - builder.endVector("bar", vec1, true, false); - - vec1 = builder.startVector(); - builder.putBoolean(true); - builder.putBoolean(false); - builder.putBoolean(true); - builder.putBoolean(false); - builder.endVector("bools", vec1, true, false); - - builder.putBoolean("bool", true); - builder.putFloat("foo", 100); - - map2 = builder.startMap(); - builder.putString("bar", "Fred"); // Testing key and string reuse. - builder.putInt("int", -120); - builder.putFloat("float", -123.0f); - builder.putBlob("blob", new byte[]{ 65, 67 }); - builder.endMap("mymap", map2); - - builder.endMap(null, map1); - builder.finish(); - - FlexBuffers.Map m = FlexBuffers.getRoot(builder.getBuffer()).asMap(); - - assertThat(m.size()).isEqualTo(6); - - // test empty (an null) - // empty if fail - assertThat(m.get("no_key").asString()).isEqualTo(""); - // empty if fail - assertThat(m.get("no_key").asMap()).isEqualTo(FlexBuffers.Map.empty()); - // empty if fail - assertThat(m.get("no_key").asKey()).isEqualTo(FlexBuffers.Key.empty()); - // empty if fail - assertThat(m.get("no_key").asVector()).isEqualTo(Vector.empty()); - // empty if fail - assertThat(m.get("no_key").asBlob()).isEqualTo(FlexBuffers.Blob.empty()); - assert(m.get("no_key").asVector().isEmpty()); // empty if fail - - // testing "vec" field - FlexBuffers.Vector vec = m.get("vec").asVector(); - assertThat(vec.size()).isEqualTo(8); - assertThat(vec.get(0).asLong()).isEqualTo((long) -100); - assertThat(vec.get(1).asString()).isEqualTo("Fred"); - assertThat(vec.get(2).isBlob()).isTrue(); - assertThat(vec.get(2).asBlob().size()).isEqualTo(1); - assertThat(vec.get(2).asBlob().data().get(0)).isEqualTo((byte) 77); - // Check if type is a bool - assertThat(vec.get(3).isBoolean()).isTrue(); - // Check if value is false - assertThat(vec.get(3).asBoolean()).isFalse(); - assertThat(vec.get(4).asLong()).isEqualTo(Long.MAX_VALUE); - assertThat(vec.get(5).isMap()).isTrue(); - assertThat(vec.get(5).asMap().get("test").asInt()).isEqualTo(200); - assertThat(Float.compare((float)vec.get(6).asFloat(), 150.9f)).isEqualTo(0); - assertThat(Double.compare(vec.get(7).asFloat(), 150.9999998)).isEqualTo(0); - //conversion fail returns 0 as C++ - assertThat((long)0).isEqualTo((long)vec.get(1).asLong()); - - // bar vector - FlexBuffers.Vector tvec = m.get("bar").asVector(); - assertThat(tvec.size()).isEqualTo(3); - assertThat(tvec.get(0).asInt()).isEqualTo(1); - assertThat(tvec.get(1).asInt()).isEqualTo(2); - assertThat(tvec.get(2).asInt()).isEqualTo(3); - assertThat(((FlexBuffers.TypedVector) tvec).getElemType()).isEqualTo(FlexBuffers.FBT_INT); - - // bools vector - FlexBuffers.Vector bvec = m.get("bools").asVector(); - assertThat(bvec.size()).isEqualTo(4); - assertThat(bvec.get(0).asBoolean()).isTrue(); - assertThat(bvec.get(1).asBoolean()).isFalse(); - assertThat(bvec.get(2).asBoolean()).isTrue(); - assertThat(bvec.get(3).asBoolean()).isFalse(); - assertThat(((FlexBuffers.TypedVector) bvec).getElemType()).isEqualTo(FlexBuffers.FBT_BOOL); - - assertThat((float)m.get("foo").asFloat()).isEqualTo((float) 100); - assertThat(m.get("unknown").isNull()).isTrue(); - - // mymap vector - FlexBuffers.Map mymap = m.get("mymap").asMap(); - // These should be equal by pointer equality, since key and value are shared. - assertThat(mymap.keys().get(0)).isEqualTo(m.keys().get(0)); - assertThat(mymap.keys().get(0).toString()).isEqualTo("bar"); - assertThat(mymap.values().get(0).asString()).isEqualTo(vec.get(1).asString()); - assertThat(mymap.get("int").asInt()).isEqualTo(-120); - assertThat((float)mymap.get("float").asFloat()).isEqualTo(-123.0f); - assertThat(Arrays.equals(mymap.get("blob").asBlob().getBytes(), new byte[]{ 65, 67 })).isEqualTo( - true); - assertThat(mymap.get("blob").asBlob().toString()).isEqualTo("AC"); - assertThat(mymap.get("blob").toString()).isEqualTo("\"AC\""); - } - - @org.junit.Test public void testFlexBufferVectorStrings() { - FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(10000000)); - - int size = 3000; - StringBuilder sb = new StringBuilder(); - for (int i=0; i< size; i++) { - sb.append("a"); - } - - String text = sb.toString(); - assertThat(text.length()).isEqualTo(size); - - int pos = builder.startVector(); - - for (int i=0; i source = new HashMap<>(); - for (int i = 0; i < entriesCount; i++) { - source.put("foo_param_" + i, "foo_value_" + i); - } - - FlexBuffersBuilder builder = new FlexBuffersBuilder(1000); - int mapStart = builder.startMap(); - for (Map.Entry entry : source.entrySet()) { - builder.putString(entry.getKey(), entry.getValue()); - } - builder.endMap(null, mapStart); - ByteBuffer bb = builder.finish(); - bb.rewind(); - - FlexBuffers.Reference rootReference = FlexBuffers.getRoot(bb); - - assertThat(rootReference.isMap()).isTrue(); - - FlexBuffers.Map flexMap = rootReference.asMap(); - - FlexBuffers.KeyVector keys = flexMap.keys(); - FlexBuffers.Vector values = flexMap.values(); - - assertThat(entriesCount).isEqualTo(keys.size()); - assertThat(entriesCount).isEqualTo(values.size()); - - HashMap result = new HashMap<>(); - for (int i = 0; i < keys.size(); i++) { - result.put(keys.get(i).toString(), values.get(i).asString()); - } - - assertThat(source).isEqualTo(result); - } - - @org.junit.Test public void testBuilderGrowth() { - FlexBuffersBuilder builder = new FlexBuffersBuilder(); - String someString = "This is a small string"; - builder.putString(someString); - ByteBuffer b = builder.finish(); - assertThat(someString).isEqualTo(FlexBuffers.getRoot(b).asString()); - - FlexBuffersBuilder failBuilder = new FlexBuffersBuilder(ByteBuffer.allocate(1)); - failBuilder.putString(someString); - } - - @org.junit.Test - public void testFlexBuffersUtf8Map() { - FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512), - FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS); - - String key0 = "😨 face1"; - String key1 = "😩 face2"; - String key2 = "😨 face3"; - String key3 = "trademark ®"; - String key4 = "€ euro"; - String utf8keys[] = { "😨 face1", "😩 face2", "😨 face3", "trademark ®", "€ euro"}; - - int map = builder.startMap(); - - for (int i=0; i< utf8keys.length; i++) { - builder.putString(utf8keys[i], utf8keys[i]); // Testing key and string reuse. - } - builder.endMap(null, map); - builder.finish(); - - FlexBuffers.Map m = FlexBuffers.getRoot(builder.getBuffer()).asMap(); - - assertThat(m.size()).isEqualTo(5); - - KeyVector kv = m.keys(); - for (int i=0; i< utf8keys.length; i++) { - assertThat(kv.get(i).toString()).isEqualTo(m.get(i).asString()); - } - - assertThat(m.get(key0).asString()).isEqualTo(utf8keys[0]); - assertThat(m.get(key1).asString()).isEqualTo(utf8keys[1]); - assertThat(m.get(key2).asString()).isEqualTo(utf8keys[2]); - assertThat(m.get(key3).asString()).isEqualTo(utf8keys[3]); - assertThat(m.get(key4).asString()).isEqualTo(utf8keys[4]); - } - - @org.junit.Test public void testFlexBuffersMapLookup() { - FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512), - FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS); - - String key0 = "123"; - String key1 = "1234"; - String key2 = "12345"; - String[] keys = new String[]{key0, key1, key2}; - - int map = builder.startMap(); - - for (int i=0; i< keys.length; i++) { - builder.putString(keys[i], keys[i]); // Testing key and string reuse. - } - builder.endMap(null, map); - builder.finish(); - - FlexBuffers.Map m = FlexBuffers.getRoot(builder.getBuffer()).asMap(); - for (int i=0; i< keys.length; i++) { - assertThat(m.get(keys[i]).asString()).isEqualTo(keys[i]); - assertThat(m.get(keys[i].getBytes(StandardCharsets.UTF_8)).asString()).isEqualTo(keys[i]); - } - } - - @org.junit.Test public void TestDictionaryLookup() { - FlatBufferBuilder fbb = new FlatBufferBuilder(16); - int lfIndex = LongFloatEntry.createLongFloatEntry(fbb, 0, 99); - int vectorEntriesIdx = LongFloatMap.createEntriesVector(fbb, new int[] { lfIndex }); - int rootIdx = LongFloatMap.createLongFloatMap(fbb, vectorEntriesIdx); - - LongFloatMap.finishLongFloatMapBuffer(fbb, rootIdx); - LongFloatMap map = LongFloatMap.getRootAsLongFloatMap(fbb.dataBuffer()); - assertThat(map.entriesLength()).isEqualTo(1); - - LongFloatEntry e = map.entries(0); - assertThat(e.key()).isEqualTo(0L); - assertThat(e.value()).isEqualTo(99.0f); - - LongFloatEntry e2 = map.entriesByKey(0); - assertThat(e2.key()).isEqualTo(0L); - assertThat(e2.value()).isEqualTo(99.0f); - } - - @org.junit.Test public void TestVectorOfBytes() { - FlatBufferBuilder fbb = new FlatBufferBuilder(16); - int str = fbb.createString("ByteMonster"); - byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - int offset = Monster.createInventoryVector(fbb, data); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - int monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject.inventoryLength()).isEqualTo(data.length); - assertThat((Integer) monsterObject.inventory(4)).isEqualTo((int) data[4]); - assertThat(ByteBuffer.wrap(data)).isEqualTo(monsterObject.inventoryAsByteBuffer()); - - fbb.clear(); - ByteBuffer bb = ByteBuffer.wrap(data); - offset = fbb.createByteVector(bb); - str = fbb.createString("ByteMonster"); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject2 = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject2.inventoryLength()).isEqualTo(data.length); - for (int i = 0; i < data.length; i++) { - assertThat((Integer) monsterObject2.inventory(i)).isEqualTo((int) bb.get(i)); - } - - fbb.clear(); - offset = fbb.createByteVector(data, 3, 4); - str = fbb.createString("ByteMonster"); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject3 = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject3.inventoryLength()).isEqualTo(4); - assertThat((Integer) monsterObject3.inventory(0)).isEqualTo((int) data[3]); - - fbb.clear(); - bb = ByteBuffer.wrap(data); - offset = Monster.createInventoryVector(fbb, bb); - str = fbb.createString("ByteMonster"); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject4 = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject4.inventoryLength()).isEqualTo(data.length); - assertThat((Integer) monsterObject4.inventory(8)).isEqualTo((int) 8); - - fbb.clear(); - byte[] largeData = new byte[1024]; - offset = fbb.createByteVector(largeData); - str = fbb.createString("ByteMonster"); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject5 = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject5.inventoryLength()).isEqualTo(largeData.length); - assertThat((Integer) monsterObject5.inventory(25)).isEqualTo((int) largeData[25]); - - fbb.clear(); - bb = ByteBuffer.wrap(largeData); - bb.position(512); - ByteBuffer bb2 = bb.slice(); - assertThat(bb2.arrayOffset()).isEqualTo(512); - offset = fbb.createByteVector(bb2); - str = fbb.createString("ByteMonster"); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject6 = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject6.inventoryLength()).isEqualTo(512); - assertThat((Integer) monsterObject6.inventory(0)).isEqualTo((int) largeData[512]); - - fbb.clear(); - bb = ByteBuffer.wrap(largeData); - bb.limit(256); - offset = fbb.createByteVector(bb); - str = fbb.createString("ByteMonster"); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject7 = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject7.inventoryLength()).isEqualTo(256); - - fbb.clear(); - bb = ByteBuffer.allocateDirect(2048); - offset = fbb.createByteVector(bb); - str = fbb.createString("ByteMonster"); - Monster.startMonster(fbb); - Monster.addName(fbb, str); - Monster.addInventory(fbb, offset); - monster1 = Monster.endMonster(fbb); - Monster.finishMonsterBuffer(fbb, monster1); - Monster monsterObject8 = Monster.getRootAsMonster(fbb.dataBuffer()); - - assertThat(monsterObject8.inventoryLength()).isEqualTo(2048); - } - - @org.junit.Test public void TestSharedStringPool() { - FlatBufferBuilder fb = new FlatBufferBuilder(1); - String testString = "My string"; - int offset = fb.createSharedString(testString); - for (int i=0; i< 10; i++) { - assertThat(offset).isEqualTo(fb.createSharedString(testString)); - } - } - - @org.junit.Test public void TestScalarOptional() { - FlatBufferBuilder fbb = new FlatBufferBuilder(1); - ScalarStuff.startScalarStuff(fbb); - int pos = ScalarStuff.endScalarStuff(fbb); - fbb.finish(pos); - - ScalarStuff scalarStuff = ScalarStuff.getRootAsScalarStuff(fbb.dataBuffer()); - assertThat(scalarStuff.justI8()).isEqualTo((byte)0); - assertThat(scalarStuff.maybeI8()).isEqualTo((byte)0); - assertThat(scalarStuff.defaultI8()).isEqualTo((byte)42); - assertThat(scalarStuff.justU8()).isEqualTo(0); - assertThat(scalarStuff.maybeU8()).isEqualTo(0); - assertThat(scalarStuff.defaultU8()).isEqualTo(42); - assertThat(scalarStuff.justI16()).isEqualTo((short)0); - assertThat(scalarStuff.maybeI16()).isEqualTo((short)0); - assertThat(scalarStuff.defaultI16()).isEqualTo((short)42); - assertThat(scalarStuff.justU16()).isEqualTo(0); - assertThat(scalarStuff.maybeU16()).isEqualTo(0); - assertThat(scalarStuff.defaultU16()).isEqualTo(42); - assertThat(scalarStuff.justI32()).isEqualTo(0); - assertThat(scalarStuff.maybeI32()).isEqualTo(0); - assertThat(scalarStuff.defaultI32()).isEqualTo(42); - assertThat(scalarStuff.justU32()).isEqualTo(0L); - assertThat(scalarStuff.maybeU32()).isEqualTo(0L); - assertThat(scalarStuff.defaultU32()).isEqualTo(42L); - assertThat(scalarStuff.justI64()).isEqualTo(0L); - assertThat(scalarStuff.maybeI64()).isEqualTo(0L); - assertThat(scalarStuff.defaultI64()).isEqualTo(42L); - assertThat(scalarStuff.justU64()).isEqualTo(0L); - assertThat(scalarStuff.maybeU64()).isEqualTo(0L); - assertThat(scalarStuff.defaultU64()).isEqualTo(42L); - assertThat(scalarStuff.justF32()).isEqualTo(0.0f); - assertThat(scalarStuff.maybeF32()).isEqualTo(0f); - assertThat(scalarStuff.defaultF32()).isEqualTo(42.0f); - assertThat(scalarStuff.justF64()).isEqualTo(0.0); - assertThat(scalarStuff.maybeF64()).isEqualTo(0.0); - assertThat(scalarStuff.defaultF64()).isEqualTo(42.0); - assertThat(scalarStuff.justBool()).isFalse(); - assertThat(scalarStuff.maybeBool()).isFalse(); - assertThat(scalarStuff.defaultBool()).isTrue(); - assertThat(scalarStuff.justEnum()).isEqualTo(OptionalByte.None); - assertThat(scalarStuff.maybeEnum()).isEqualTo(OptionalByte.None); - assertThat(scalarStuff.defaultEnum()).isEqualTo(OptionalByte.One); - - assertThat(scalarStuff.hasMaybeI8()).isFalse(); - assertThat(scalarStuff.hasMaybeI16()).isFalse(); - assertThat(scalarStuff.hasMaybeI32()).isFalse(); - assertThat(scalarStuff.hasMaybeI64()).isFalse(); - assertThat(scalarStuff.hasMaybeU8()).isFalse(); - assertThat(scalarStuff.hasMaybeU16()).isFalse(); - assertThat(scalarStuff.hasMaybeU32()).isFalse(); - assertThat(scalarStuff.hasMaybeU64()).isFalse(); - assertThat(scalarStuff.hasMaybeF32()).isFalse(); - assertThat(scalarStuff.hasMaybeF64()).isFalse(); - assertThat(scalarStuff.hasMaybeBool()).isFalse(); - assertThat(scalarStuff.hasMaybeEnum()).isFalse(); - - fbb.clear(); - - ScalarStuff.startScalarStuff(fbb); - ScalarStuff.addJustI8(fbb, (byte)5); - ScalarStuff.addMaybeI8(fbb, (byte)5); - ScalarStuff.addDefaultI8(fbb, (byte)5); - ScalarStuff.addJustU8(fbb, 6); - ScalarStuff.addMaybeU8(fbb, 6); - ScalarStuff.addDefaultU8(fbb, 6); - ScalarStuff.addJustI16(fbb, (short)7); - ScalarStuff.addMaybeI16(fbb, (short)7); - ScalarStuff.addDefaultI16(fbb, (short)7); - ScalarStuff.addJustU16(fbb, 8); - ScalarStuff.addMaybeU16(fbb, 8); - ScalarStuff.addDefaultU16(fbb, 8); - ScalarStuff.addJustI32(fbb, 9); - ScalarStuff.addMaybeI32(fbb, 9); - ScalarStuff.addDefaultI32(fbb, 9); - ScalarStuff.addJustU32(fbb, (long)10); - ScalarStuff.addMaybeU32(fbb, (long)10); - ScalarStuff.addDefaultU32(fbb, (long)10); - ScalarStuff.addJustI64(fbb, 11L); - ScalarStuff.addMaybeI64(fbb, 11L); - ScalarStuff.addDefaultI64(fbb, 11L); - ScalarStuff.addJustU64(fbb, 12L); - ScalarStuff.addMaybeU64(fbb, 12L); - ScalarStuff.addDefaultU64(fbb, 12L); - ScalarStuff.addJustF32(fbb, 13.0f); - ScalarStuff.addMaybeF32(fbb, 13.0f); - ScalarStuff.addDefaultF32(fbb, 13.0f); - ScalarStuff.addJustF64(fbb, 14.0); - ScalarStuff.addMaybeF64(fbb, 14.0); - ScalarStuff.addDefaultF64(fbb, 14.0); - ScalarStuff.addJustBool(fbb, true); - ScalarStuff.addMaybeBool(fbb, true); - ScalarStuff.addDefaultBool(fbb, true); - ScalarStuff.addJustEnum(fbb, OptionalByte.Two); - ScalarStuff.addMaybeEnum(fbb, OptionalByte.Two); - ScalarStuff.addDefaultEnum(fbb, OptionalByte.Two); - - pos = ScalarStuff.endScalarStuff(fbb); - - fbb.finish(pos); - - scalarStuff = ScalarStuff.getRootAsScalarStuff(fbb.dataBuffer()); - - assertThat(scalarStuff.justI8()).isEqualTo((byte)5); - assertThat(scalarStuff.maybeI8()).isEqualTo((byte)5); - assertThat(scalarStuff.defaultI8()).isEqualTo((byte)5); - assertThat(scalarStuff.justU8()).isEqualTo(6); - assertThat(scalarStuff.maybeU8()).isEqualTo(6); - assertThat(scalarStuff.defaultU8()).isEqualTo(6); - assertThat(scalarStuff.justI16()).isEqualTo((short)7); - assertThat(scalarStuff.maybeI16()).isEqualTo((short)7); - assertThat(scalarStuff.defaultI16()).isEqualTo((short)7); - assertThat(scalarStuff.justU16()).isEqualTo(8); - assertThat(scalarStuff.maybeU16()).isEqualTo(8); - assertThat(scalarStuff.defaultU16()).isEqualTo(8); - assertThat(scalarStuff.justI32()).isEqualTo(9); - assertThat(scalarStuff.maybeI32()).isEqualTo(9); - assertThat(scalarStuff.defaultI32()).isEqualTo(9); - assertThat(scalarStuff.justU32()).isEqualTo(10L); - assertThat(scalarStuff.maybeU32()).isEqualTo(10L); - assertThat(scalarStuff.defaultU32()).isEqualTo(10L); - assertThat(scalarStuff.justI64()).isEqualTo(11L); - assertThat(scalarStuff.maybeI64()).isEqualTo(11L); - assertThat(scalarStuff.defaultI64()).isEqualTo(11L); - assertThat(scalarStuff.justU64()).isEqualTo(12L); - assertThat(scalarStuff.maybeU64()).isEqualTo(12L); - assertThat(scalarStuff.defaultU64()).isEqualTo(12L); - assertThat(scalarStuff.justF32()).isEqualTo(13.0f); - assertThat(scalarStuff.maybeF32()).isEqualTo(13.0f); - assertThat(scalarStuff.defaultF32()).isEqualTo(13.0f); - assertThat(scalarStuff.justF64()).isEqualTo(14.0); - assertThat(scalarStuff.maybeF64()).isEqualTo(14.0); - assertThat(scalarStuff.defaultF64()).isEqualTo(14.0); - assertThat(scalarStuff.justBool()).isTrue(); - assertThat(scalarStuff.maybeBool()).isTrue(); - assertThat(scalarStuff.defaultBool()).isTrue(); - assertThat(scalarStuff.justEnum()).isEqualTo(OptionalByte.Two); - assertThat(scalarStuff.maybeEnum()).isEqualTo(OptionalByte.Two); - assertThat(scalarStuff.defaultEnum()).isEqualTo(OptionalByte.Two); - - assertThat(scalarStuff.hasMaybeI8()).isTrue(); - assertThat(scalarStuff.hasMaybeI16()).isTrue(); - assertThat(scalarStuff.hasMaybeI32()).isTrue(); - assertThat(scalarStuff.hasMaybeI64()).isTrue(); - assertThat(scalarStuff.hasMaybeU8()).isTrue(); - assertThat(scalarStuff.hasMaybeU16()).isTrue(); - assertThat(scalarStuff.hasMaybeU32()).isTrue(); - assertThat(scalarStuff.hasMaybeU64()).isTrue(); - assertThat(scalarStuff.hasMaybeF32()).isTrue(); - assertThat(scalarStuff.hasMaybeF64()).isTrue(); - assertThat(scalarStuff.hasMaybeBool()).isTrue(); - assertThat(scalarStuff.hasMaybeEnum()).isTrue(); - } - - static void TestObject(MonsterT monster) { - assertThat(monster.getHp()).isEqualTo((short) 80); - // default - assertThat(monster.getMana()).isEqualTo((short) 150); - - assertThat(monster.getName()).isEqualTo("MyMonster"); - assertThat(monster.getColor()).isEqualTo((Integer) Color.Blue); - // monster.friendly() // can't access, deprecated - - Vec3T pos = monster.getPos(); - assertThat(pos.getX()).isEqualTo(1.0f); - assertThat(pos.getY()).isEqualTo(2.0f); - assertThat(pos.getZ()).isEqualTo(3.0f); - assertThat(pos.getTest1()).isEqualTo(3.0); - // issue: int != byte - assertThat(pos.getTest2()).isEqualTo((int) Color.Green); - TestT t = pos.getTest3(); - assertThat(t.getA()).isEqualTo((short) 5); - assertThat(t.getB()).isEqualTo((byte) 6); - - assertThat(monster.getTest().getType()).isEqualTo((byte) Any.Monster); - MonsterT monster2 = (MonsterT) monster.getTest().getValue(); - assertThat(monster2 != null).isTrue(); - assertThat(monster2.getName()).isEqualTo("Fred"); - - int[] inv = monster.getInventory(); - assertThat(inv.length).isEqualTo(5); - int[] expInv = {0, 1, 2, 3, 4}; - for (int i = 0; i < inv.length; i++) - assertThat(expInv[i]).isEqualTo(inv[i]); - - TestT[] test4 = monster.getTest4(); - TestT test_0 = test4[0]; - TestT test_1 = test4[1]; - assertThat(test4.length).isEqualTo(2); - assertThat(test_0.getA()).isEqualTo((short) 10); - assertThat(test_0.getB()).isEqualTo((byte) 20); - assertThat(test_1.getA()).isEqualTo((short) 30); - assertThat(test_1.getB()).isEqualTo((byte) 40); - - String[] testarrayofstring = monster.getTestarrayofstring(); - assertThat(testarrayofstring.length).isEqualTo(2); - assertThat(testarrayofstring[0]).isEqualTo("test1"); - assertThat(testarrayofstring[1]).isEqualTo("test2"); - - MonsterT[] testarrayoftables = monster.getTestarrayoftables(); - assertThat(testarrayoftables.length).isEqualTo(0); - - MonsterT enemy = monster.getEnemy(); - assertThat(enemy != null).isTrue(); - assertThat(enemy.getName()).isEqualTo("Fred"); - - int[] testnestedflatbuffer = monster.getTestnestedflatbuffer(); - assertThat(testnestedflatbuffer.length).isEqualTo(0); - - assertThat(monster.getTestempty() == null).isTrue(); - - assertThat(monster.getTestbool()).isTrue(); - - boolean[] testarrayofbools = monster.getTestarrayofbools(); - assertThat(testarrayofbools.length).isEqualTo(3); - assertThat(testarrayofbools[0]).isTrue(); - assertThat(testarrayofbools[1]).isFalse(); - assertThat(testarrayofbools[2]).isTrue(); - - assertThat(monster.getTestf()).isEqualTo(3.14159f); - assertThat(monster.getTestf2()).isEqualTo(3.0f); - assertThat(monster.getTestf3()).isEqualTo(0.0f); - assertThat(monster.getTestf3()).isEqualTo(0.0f); - - AbilityT[] testarrayofsortedstruct = monster.getTestarrayofsortedstruct(); - assertThat(testarrayofsortedstruct.length).isEqualTo(3); - assertThat(testarrayofsortedstruct[0].getId()).isEqualTo((long) 0); - assertThat(testarrayofsortedstruct[1].getId()).isEqualTo((long) 1); - assertThat(testarrayofsortedstruct[2].getId()).isEqualTo((long) 5); - assertThat(testarrayofsortedstruct[0].getDistance()).isEqualTo((long) 45); - assertThat(testarrayofsortedstruct[1].getDistance()).isEqualTo((long) 21); - assertThat(testarrayofsortedstruct[2].getDistance()).isEqualTo((long) 12); - - int[] flex = monster.getFlex(); - assertThat(flex.length).isEqualTo(0); - - long[] vectorOfLongs = monster.getVectorOfLongs(); - assertThat(vectorOfLongs.length).isEqualTo(5); - long l = 1; - for (int i = 0; i < vectorOfLongs.length; i++) { - assertThat(vectorOfLongs[i]).isEqualTo(l); - l *= 100; - } - - double[] vectorOfDoubles = monster.getVectorOfDoubles(); - assertThat(vectorOfDoubles.length).isEqualTo(3); - assertThat(vectorOfDoubles[0]).isEqualTo(-1.7976931348623157E308); - assertThat(vectorOfDoubles[1]).isEqualTo(0.0); - assertThat(vectorOfDoubles[2]).isEqualTo(1.7976931348623157E308); - - assertThat(monster.getParentNamespaceTest() == null).isTrue(); - ReferrableT[] vectorOfReferrables = monster.getVectorOfReferrables(); - assertThat(vectorOfReferrables.length).isEqualTo(0); - - assertThat(monster.getSignedEnum()).isEqualTo((byte) -1); - } - - static void TestPackUnpack(ByteBuffer bb) { - Monster m = Monster.getRootAsMonster(bb); - MonsterT mObject = m.unpack(); - TestObject(mObject); - FlatBufferBuilder fbb = new FlatBufferBuilder(); - int monster = Monster.pack(fbb, mObject); - Monster.finishMonsterBuffer(fbb, monster); - TestBuffer(fbb.dataBuffer()); - - byte[] bytes = mObject.serializeToBinary(); - MonsterT newMonsterT = MonsterT.deserializeFromBinary(bytes); - TestObject(newMonsterT); - } -} diff --git a/third_party/flatbuffers/java/src/test/java/MyGame b/third_party/flatbuffers/java/src/test/java/MyGame deleted file mode 120000 index 0ba918ed0..000000000 --- a/third_party/flatbuffers/java/src/test/java/MyGame +++ /dev/null @@ -1 +0,0 @@ -../../../../tests/MyGame \ No newline at end of file diff --git a/third_party/flatbuffers/java/src/test/java/NamespaceA b/third_party/flatbuffers/java/src/test/java/NamespaceA deleted file mode 120000 index 37a8d897e..000000000 --- a/third_party/flatbuffers/java/src/test/java/NamespaceA +++ /dev/null @@ -1 +0,0 @@ -../../../../tests/namespace_test/NamespaceA \ No newline at end of file diff --git a/third_party/flatbuffers/java/src/test/java/NamespaceC b/third_party/flatbuffers/java/src/test/java/NamespaceC deleted file mode 120000 index c1e44a8c9..000000000 --- a/third_party/flatbuffers/java/src/test/java/NamespaceC +++ /dev/null @@ -1 +0,0 @@ -../../../../tests/namespace_test/NamespaceC \ No newline at end of file diff --git a/third_party/flatbuffers/java/src/test/java/optional_scalars b/third_party/flatbuffers/java/src/test/java/optional_scalars deleted file mode 120000 index 44a35f967..000000000 --- a/third_party/flatbuffers/java/src/test/java/optional_scalars +++ /dev/null @@ -1 +0,0 @@ -../../../../tests/optional_scalars \ No newline at end of file diff --git a/third_party/flatbuffers/java/src/test/java/union_vector b/third_party/flatbuffers/java/src/test/java/union_vector deleted file mode 120000 index cc82221f5..000000000 --- a/third_party/flatbuffers/java/src/test/java/union_vector +++ /dev/null @@ -1 +0,0 @@ -../../../../tests/union_vector \ No newline at end of file diff --git a/third_party/flatbuffers/java/src/test/resources/monsterdata_test.mon b/third_party/flatbuffers/java/src/test/resources/monsterdata_test.mon deleted file mode 100644 index da0ed8698fcafc71115525dc6fe40fead48515d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 600 zcmZ{hy-EX75QWcfepo{wDPn7@MFf=;7J};!lEP>}3kwSi7ZZq4vs)xsm~^QGA&-#4 z(uWYl!Z%1jpFk8Wtk!dGb|nZ-^39w(Gr2RnX#=S2?;S9pfdL%GG>Y^~B#9DMu}0+* zAcbv|afvo|QAHPh9Gbk`5jn;QPJc81i5e$0ShTDveRrMC<(I_fxHe~{qvOy52Bb*x zWW@X<*?8`Z#nrHPEAE-=lUGuTdi5k0Z1nD~KVQ1JW*k4pXHTQ@_f{O)#xCAZ7Iffr zhtIDak`d>1-v=@%u##mZqc+~2rJraZL0zi{CaStfxC&-Til|pT7C#SR7{+(+v^?|T zv_pX?ul~UEgOw@0OsyVmF~?1(b=LfQEb`Zy^Y?De