mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
Remake
This commit is contained in:
@@ -367,6 +367,39 @@ public class FlatBufferBuilder {
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
/**
|
||||
* Create a vector of tables.
|
||||
*
|
||||
* @param offsets Offsets of the tables.
|
||||
* @return Returns offset of the vector.
|
||||
*/
|
||||
public int createVectorOfTables(int[] offsets) {
|
||||
notNested();
|
||||
startVector(4, offsets.length, 4);
|
||||
for(int i = offsets.length - 1; i >= 0; i--) addOffset(offsets[i]);
|
||||
return endVector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a vector of sorted by the key tables.
|
||||
*
|
||||
* @param type Type of the tables.
|
||||
* @param offsets Offsets of the tables.
|
||||
* @return Returns offset of the sorted vector.
|
||||
*/
|
||||
public <T> int createSortedTableVector(Class<T> type, int[] offsets) {
|
||||
try{
|
||||
return (int)type.getMethod("createMySortedTableVector", FlatBufferBuilder.class, ByteBuffer.class, int[].class).invoke(null, this, bb, offsets);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the string `s` in the buffer using UTF-8. If {@code s} is
|
||||
* already a {@link CharBuffer}, this method is allocation free.
|
||||
|
||||
@@ -56,9 +56,11 @@ public class Table {
|
||||
* @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) {
|
||||
int vtable = bb_pos - bb.getInt(bb_pos);
|
||||
return vtable_offset < bb.getShort(vtable) ? bb.getShort(vtable + vtable_offset) : 0;
|
||||
protected int __offset(int vtable_offset) { return __offset(vtable_offset, bb_pos - bb.getInt(bb_pos), bb, false); }
|
||||
|
||||
protected static int __offset(int vtable_offset, int vtable, ByteBuffer _bb, boolean invoked_static) {
|
||||
if (!invoked_static) return vtable_offset < _bb.getShort(vtable) ? _bb.getShort(vtable + vtable_offset) : 0;
|
||||
else return _bb.getShort(vtable + vtable_offset - _bb.getInt(vtable)) + vtable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,11 +85,15 @@ public class Table {
|
||||
* @return Returns a `String` from the data stored inside the FlatBuffer at `offset`.
|
||||
*/
|
||||
protected String __string(int offset) {
|
||||
return __string(offset, bb);
|
||||
}
|
||||
|
||||
protected static String __string(int offset, ByteBuffer _bb) {
|
||||
CharsetDecoder decoder = UTF8_DECODER.get();
|
||||
decoder.reset();
|
||||
|
||||
offset += bb.getInt(offset);
|
||||
ByteBuffer src = bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
|
||||
offset += _bb.getInt(offset);
|
||||
ByteBuffer src = _bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
|
||||
int length = src.getInt(offset);
|
||||
src.position(offset + SIZEOF_INT);
|
||||
src.limit(offset + SIZEOF_INT + length);
|
||||
|
||||
Reference in New Issue
Block a user