本文整理汇总了Java中com.google.flatbuffers.FlatBufferBuilder类的典型用法代码示例。如果您正苦于以下问题:Java FlatBufferBuilder类的具体用法?Java FlatBufferBuilder怎么用?Java FlatBufferBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FlatBufferBuilder类属于com.google.flatbuffers包,在下文中一共展示了FlatBufferBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Setup
public void setup() throws JsonProcessingException {
//FlatBuffers
ByteBuffer byteBuff = ByteBuffer.allocate(128);
fbb = new FlatBufferBuilder(byteBuff);
Person.createPhoneBookVector(fbb, data);
int nameOffset = fbb.createString(name);
int emailOffset = fbb.createString(email);
Person.createPhoneBookVector(fbb, data);
Person.startPerson(fbb);
Person.addName(fbb, nameOffset);
Person.addId(fbb, id);
Person.addEmail(fbb, emailOffset);
int bla = Person.endPerson(fbb);
fbb.finish(bla);
msgFlatBuffer = fbb.sizedByteArray();
}
示例2: SerializationFlatBuffers
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Benchmark
//@BenchmarkMode(Mode.AverageTime)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
//@Fork(1)
public byte[] SerializationFlatBuffers() {
ByteBuffer byteBuff = ByteBuffer.allocate(128);
fbb = new FlatBufferBuilder(byteBuff);
int nameOffset = fbb.createString(name);
int emailOffset = fbb.createString(email);
Person.createPhoneBookVector(fbb, data);
Person.startPerson(fbb);
Person.addName(fbb, nameOffset);
Person.addId(fbb, id);
Person.addEmail(fbb, emailOffset);
int bla = Person.endPerson(fbb);
fbb.finish(bla);
return fbb.sizedByteArray();
}
示例3: encodeRecord
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Override
protected void encodeRecord(RecordContext ctx, FlatBufferBuilder fbb, int baseOffset) {
int orderIdOffset = fbb.createString(getOrderId());
OrderReceivedEventRecord.startOrderReceivedEventRecord(fbb);
OrderReceivedEventRecord.addBase(fbb, baseOffset);
OrderReceivedEventRecord.addOrderId(fbb, orderIdOffset);
OrderReceivedEventRecord.addOrderId(fbb, orderIdOffset);
if (getSize() != null) {
OrderReceivedEventRecord.addSize(fbb, getSize().doubleValue());
}
if (getFunds() != null) {
OrderReceivedEventRecord.addFunds(fbb, getFunds().doubleValue());
}
OrderReceivedEventRecord.addOrderType(fbb, orderType == OrderType.LIMIT ? GdaxOrderType.Limit : GdaxOrderType.Market);
int offset = OrderReceivedEventRecord.endOrderReceivedEventRecord(fbb);
fbb.finish(offset);
}
示例4: encodeRecord
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Override
protected void encodeRecord(RecordContext ctx, FlatBufferBuilder fbb, int baseOffset) {
int orderIdOffset = fbb.createString(getOrderId());
int reasonOffset = fbb.createString(getReason());
OrderDoneEventRecord.startOrderDoneEventRecord(fbb);
OrderDoneEventRecord.addBase(fbb, baseOffset);
OrderDoneEventRecord.addOrderId(fbb, orderIdOffset);
if (getRemainingSize() != null) {
OrderDoneEventRecord.addRemainingSize(fbb, getRemainingSize().doubleValue());
}
OrderDoneEventRecord.addReason(fbb, reasonOffset);
int offset = OrderDoneEventRecord.endOrderDoneEventRecord(fbb);
fbb.finish(offset);
}
示例5: encodeRecord
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Override
public byte[] encodeRecord(RecordContext ctx) {
FlatBufferBuilder fbb = new FlatBufferBuilder(16);
int productIdOffset = fbb.createString(productId.getURN());
OrderUpdateEventRecord.startOrderUpdateEventRecord(fbb);
OrderUpdateEventRecord.addSide(fbb, side == Side.BUY ? GdaxSide.Buy : GdaxSide.Sell);
if (price != null) {
OrderUpdateEventRecord.addPrice(fbb, price.doubleValue());
}
OrderUpdateEventRecord.addProductId(fbb, productIdOffset);
int baseOffset = OrderUpdateEventRecord.endOrderUpdateEventRecord(fbb);
encodeRecord(ctx, fbb, baseOffset);
return fbb.sizedByteArray();
}
示例6: FragmentWritableBatch
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
public FragmentWritableBatch(
final QueryId queryId,
final int sendMajorFragmentId,
final int sendMinorFragmentId,
final int receiveMajorFragmentId,
ArrowRecordBatch recordBatch,
final int... receiveMinorFragmentId){
this.buffers = recordBatch.getBuffers().toArray(new ByteBuf[0]);
this.recordCount = recordBatch.getLength();
FlatBufferBuilder fbbuilder = new FlatBufferBuilder();
fbbuilder.finish(recordBatch.writeTo(fbbuilder));
ByteBuffer arrowRecordBatch = fbbuilder.dataBuffer();
final FragmentRecordBatch.Builder builder = FragmentRecordBatch.newBuilder()
.setArrowRecordBatch(ByteString.copyFrom(arrowRecordBatch))
.setQueryId(queryId)
.setReceivingMajorFragmentId(receiveMajorFragmentId)
.setSendingMajorFragmentId(sendMajorFragmentId)
.setSendingMinorFragmentId(sendMinorFragmentId);
for(final int i : receiveMinorFragmentId){
builder.addReceivingMinorFragmentId(i);
}
this.header = builder.build();
}
示例7: testDataSetSchema
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Test
public void testDataSetSchema() throws Exception {
try(
final KVStoreProvider kvstore = new LocalKVStoreProvider(DremioTest.CLASSPATH_SCAN_RESULT, null, true, false);
) {
kvstore.start();
final NamespaceService ns = new NamespaceServiceImpl(kvstore);
Field field1 = new Field("a", true, new Int(32, true), null);
Field child1 = new Field("c", true, Utf8.INSTANCE, null);
Field field2 = new Field("b", true, Struct.INSTANCE, ImmutableList.of(child1));
Schema schema = new Schema(ImmutableList.of(field1, field2));
FlatBufferBuilder builder = new FlatBufferBuilder();
schema.getSchema(builder);
builder.finish(schema.getSchema(builder));
addSource(ns, "s");
addPhysicalDS(ns, "s.foo", builder.sizedByteArray());
ByteBuffer bb = ByteBuffer.wrap(DatasetHelper.getSchemaBytes(ns.getDataset(new NamespaceKey(PathUtils.parseFullPath("s.foo")))).toByteArray());
Schema returnedSchema = Schema.convertSchema(org.apache.arrow.flatbuf.Schema.getRootAsSchema(bb));
assertEquals(schema, returnedSchema);
}
}
示例8: createPeople
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
public static int createPeople(FlatBufferBuilder builder,
int idOffset,
long index,
int guidOffset,
int nameOffset,
int genderOffset,
int companyOffset,
int emailOffset,
int friendsOffset) {
builder.startObject(8);
People.addIndex(builder, index);
People.addFriends(builder, friendsOffset);
People.addEmail(builder, emailOffset);
People.addCompany(builder, companyOffset);
People.addGender(builder, genderOffset);
People.addName(builder, nameOffset);
People.addGuid(builder, guidOffset);
People.addId(builder, idOffset);
return People.endPeople(builder);
}
示例9: getFlatConfiguration
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
/**
* This method
* @param builder
* @return
*/
public int getFlatConfiguration(FlatBufferBuilder builder) {
byte prof = profilingMode == OpExecutioner.ProfilingMode.INF_PANIC ? ProfilingMode.INF_PANIC :
profilingMode == OpExecutioner.ProfilingMode.NAN_PANIC ? ProfilingMode.NAN_PANIC :
profilingMode == OpExecutioner.ProfilingMode.ANY_PANIC ? ProfilingMode.ANY_PANIC : ProfilingMode.NONE;
byte exec = executionMode == ExecutionMode.SEQUENTIAL ? org.nd4j.graph.ExecutionMode.SEQUENTIAL :
executionMode == ExecutionMode.AUTO ? org.nd4j.graph.ExecutionMode.AUTO :
executionMode == ExecutionMode.STRICT ? org.nd4j.graph.ExecutionMode.STRICT : -1;
byte outp = outputMode == OutputMode.IMPLICIT ? org.nd4j.graph.OutputMode.IMPLICIT :
outputMode == OutputMode.EXPLICIT ? org.nd4j.graph.OutputMode.EXPLICIT :
outputMode == OutputMode.EXPLICIT_AND_IMPLICIT ? org.nd4j.graph.OutputMode.EXPLICIT_AND_IMPLICIT :
outputMode == OutputMode.VARIABLE_SPACE ? org.nd4j.graph.OutputMode.VARIABLE_SPACE : -1;
if (exec == -1)
throw new UnsupportedOperationException("Unknown values were passed into configuration as ExecutionMode: [" + executionMode + "]");
if (outp == -1)
throw new UnsupportedOperationException("Unknown values were passed into configuration as OutputMode: [" + outputMode + "]");
return FlatConfiguration.createFlatConfiguration(builder, -1, prof, exec, outp, gatherTimings);
}
示例10: asFlatNode
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
protected int asFlatNode(String name, @NonNull SameDiff scope, @NonNull FlatBufferBuilder bufferBuilder) {
int scopeName = bufferBuilder.createString(name);
int flatNode = FlatNode.createFlatNode(bufferBuilder,
scopeName,
scopeName,
OpType.LOGIC,
10, // hardcoded value
0,
0,
0,
(byte) 0,
0,
0,
0,
0,
-1,
0.0f, 0, 0);
return flatNode;
}
示例11: asFlatProperties
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
/**
* This method converts this FunctionProperties instance to FlatBuffers representation
* @param bufferBuilder
* @return
*/
public int asFlatProperties(FlatBufferBuilder bufferBuilder) {
int iname = bufferBuilder.createString(name);
int ii = FlatProperties.createIVector(bufferBuilder, Ints.toArray(i));
int il = FlatProperties.createLVector(bufferBuilder, Longs.toArray(l));
int id = FlatProperties.createDVector(bufferBuilder, Doubles.toArray(d));
int arrays[] = new int[a.size()];
int cnt = 0;
for (val array: a) {
int off = array.toFlatArray(bufferBuilder);
arrays[cnt++] = off;
}
int ia = FlatProperties.createAVector(bufferBuilder, arrays);
return FlatProperties.createFlatProperties(bufferBuilder, iname, ii, il, id, ia);
}
示例12: encodeRecord
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Override
protected void encodeRecord(RecordContext ctx, FlatBufferBuilder fbb, int baseOffset) {
int orderIdOffset = fbb.createString(getOrderId());
OrderOpenEventRecord.startOrderOpenEventRecord(fbb);
OrderOpenEventRecord.addBase(fbb, baseOffset);
OrderOpenEventRecord.addOrderId(fbb, orderIdOffset);
if (getRemainingSize() != null) {
OrderOpenEventRecord.addRemainingSize(fbb, getRemainingSize().doubleValue());
}
int offset = OrderOpenEventRecord.endOrderOpenEventRecord(fbb);
fbb.finish(offset);
}
示例13: encodeRecord
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Override
protected void encodeRecord(RecordContext ctx, FlatBufferBuilder fbb, int baseOffset) {
int orderIdOffset = fbb.createString(getOrderId());
OrderChangeEventRecord.startOrderChangeEventRecord(fbb);
OrderChangeEventRecord.addOrderId(fbb, orderIdOffset);
OrderChangeEventRecord.addNewSize(fbb, getNewSize().doubleValue());
int offset = OrderChangeEventRecord.endOrderChangeEventRecord(fbb);
fbb.finish(offset);
}
示例14: encodeRecord
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
@Override
protected void encodeRecord(RecordContext ctx, FlatBufferBuilder fbb, int baseOffset) {
int makerIdOffset = fbb.createString(getMakerOrderId());
int takerIdOffset = fbb.createString(getTakerOrderId());
OrderMatchEventRecord.startOrderMatchEventRecord(fbb);
OrderMatchEventRecord.addBase(fbb, baseOffset);
OrderMatchEventRecord.addTradeId(fbb, tradeId);
OrderMatchEventRecord.addMakerOrderId(fbb, makerIdOffset);
OrderMatchEventRecord.addTakerOrderId(fbb, takerIdOffset);
OrderMatchEventRecord.addSize(fbb, getSize().doubleValue());
int offset = OrderMatchEventRecord.endOrderMatchEventRecord(fbb);
fbb.finish(offset);
}
示例15: createUser
import com.google.flatbuffers.FlatBufferBuilder; //导入依赖的package包/类
public static int createUser(FlatBufferBuilder builder,
int usernameOffset,
int nameOffset,
int height,
boolean enabled,
int purchasesOffset) {
builder.startObject(5);
User.addPurchases(builder, purchasesOffset);
User.addHeight(builder, height);
User.addName(builder, nameOffset);
User.addUsername(builder, usernameOffset);
User.addEnabled(builder, enabled);
return User.endUser(builder);
}