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; }
/** * 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 <T extends Table> int createSortedVectorOfTables(T obj, int[] offsets) { obj.sortTables(offsets, bb); return createVectorOfTables(offsets); }
public @Override void write(@NonNull RevObject o, @NonNull OutputStream out) throws IOException { final ByteBuffer dataBuffer; if (o instanceof FBRevObject) { dataBuffer = ((FBRevObject<?>) o).getTable().getByteBuffer().duplicate(); } else { FlatBufferBuilder fbb = WRITE_BUFFERS.get(); fbb.clear(); flatBuffers.encode(o, fbb); dataBuffer = fbb.dataBuffer(); } byte[] array; int off, len = dataBuffer.remaining(); if (dataBuffer.hasArray()) { array = dataBuffer.array(); off = dataBuffer.position(); } else { off = 0; array = new byte[len]; dataBuffer.get(array); } if (isLengthPrefixed()) { // write size in little endian (FlatBuffers is LE exclusively, so follow suite) out.write((len >>> 0) & 0xFF); out.write((len >>> 8) & 0xFF); out.write((len >>> 16) & 0xFF); out.write((len >>> 24) & 0xFF); } out.write(array, off, len); }
/** * 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 <T extends Table> int createSortedVectorOfTables(T obj, int[] offsets) { obj.sortTables(offsets, bb); return createVectorOfTables(offsets); }
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; }
/** * 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 <T extends Table> int createSortedVectorOfTables(T obj, int[] offsets) { obj.sortTables(offsets, bb); return createVectorOfTables(offsets); }
/** * 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 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 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; }
/** * 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; }
/** * 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; }