本文整理汇总了Java中com.google.flatbuffers.FlatBufferBuilder.dataBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java FlatBufferBuilder.dataBuffer方法的具体用法?Java FlatBufferBuilder.dataBuffer怎么用?Java FlatBufferBuilder.dataBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.flatbuffers.FlatBufferBuilder
的用法示例。
在下文中一共展示了FlatBufferBuilder.dataBuffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: testPutMultipleBinary
import com.google.flatbuffers.FlatBufferBuilder; //导入方法依赖的package包/类
@Test
public void testPutMultipleBinary() throws Exception {
FlatBufferBuilder builder = new FlatBufferBuilder(1);
int[] metric = new int[2];
Map<String, String> t = new HashMap<>();
t.put("tag1", "value1");
t.put("tag2", "value2");
metric[0] = createMetric(builder, "sys.cpu.user", TEST_TIME, 1.0D, t);
t = new HashMap<>();
t.put("tag3", "value3");
t.put("tag4", "value4");
metric[1] = createMetric(builder, "sys.cpu.idle", TEST_TIME + 1, 1.0D, t);
int metricVector = timely.api.flatbuffer.Metrics.createMetricsVector(builder, metric);
timely.api.flatbuffer.Metrics.startMetrics(builder);
timely.api.flatbuffer.Metrics.addMetrics(builder, metricVector);
int metrics = timely.api.flatbuffer.Metrics.endMetrics(builder);
timely.api.flatbuffer.Metrics.finishMetricsBuffer(builder, metrics);
ByteBuffer binary = builder.dataBuffer();
byte[] data = new byte[binary.remaining()];
binary.get(data, 0, binary.remaining());
LOG.debug("Sending {} bytes", data.length);
final TestServer m = new TestServer(conf);
m.run();
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 54325);
DatagramPacket packet = new DatagramPacket("".getBytes(UTF_8), 0, 0, address.getAddress(), 54325);
try (DatagramSocket sock = new DatagramSocket()) {
packet.setData(data);
sock.send(packet);
while (2 != m.getUdpRequests().getCount()) {
Thread.sleep(5);
}
Assert.assertEquals(2, m.getUdpRequests().getResponses().size());
Assert.assertEquals(MetricRequest.class, m.getUdpRequests().getResponses().get(0).getClass());
// @formatter:off
MetricRequest actual = (MetricRequest) m.getUdpRequests().getResponses().get(0);
MetricRequest expected = new MetricRequest(
Metric.newBuilder()
.name("sys.cpu.user")
.value(TEST_TIME, 1.0D)
.tag(new Tag("tag1", "value1"))
.tag(new Tag("tag2", "value2"))
.build()
);
Assert.assertEquals(expected, actual);
Assert.assertEquals(MetricRequest.class, m.getUdpRequests().getResponses().get(1).getClass());
actual = (MetricRequest) m.getUdpRequests().getResponses().get(1);
expected = new MetricRequest(
Metric.newBuilder()
.name("sys.cpu.idle")
.value(TEST_TIME + 1, 1.0D)
.tag(new Tag("tag3", "value3"))
.tag(new Tag("tag4", "value4"))
.build()
);
Assert.assertEquals(expected, actual);
// @formatter:on
} finally {
m.shutdown();
}
}
示例3: testPutMultipleBinary
import com.google.flatbuffers.FlatBufferBuilder; //导入方法依赖的package包/类
@Test
public void testPutMultipleBinary() throws Exception {
FlatBufferBuilder builder = new FlatBufferBuilder(1);
int[] metric = new int[2];
Map<String, String> t = new HashMap<>();
t.put("tag1", "value1");
t.put("tag2", "value2");
metric[0] = createMetric(builder, "sys.cpu.user", TEST_TIME, 1.0D, t);
t = new HashMap<>();
t.put("tag3", "value3");
t.put("tag4", "value4");
metric[1] = createMetric(builder, "sys.cpu.idle", TEST_TIME + 1, 1.0D, t);
int metricVector = timely.api.flatbuffer.Metrics.createMetricsVector(builder, metric);
timely.api.flatbuffer.Metrics.startMetrics(builder);
timely.api.flatbuffer.Metrics.addMetrics(builder, metricVector);
int metrics = timely.api.flatbuffer.Metrics.endMetrics(builder);
timely.api.flatbuffer.Metrics.finishMetricsBuffer(builder, metrics);
ByteBuffer binary = builder.dataBuffer();
byte[] data = new byte[binary.remaining()];
binary.get(data, 0, binary.remaining());
LOG.debug("Sending {} bytes", data.length);
final TestServer m = new TestServer(conf);
m.run();
try (Socket sock = new Socket("127.0.0.1", 54321);) {
sock.getOutputStream().write(data);
sock.getOutputStream().flush();
while (2 != m.getTcpRequests().getCount()) {
LOG.debug("Thread sleeping");
Thread.sleep(5);
}
Assert.assertEquals(2, m.getTcpRequests().getResponses().size());
Assert.assertEquals(MetricRequest.class, m.getTcpRequests().getResponses().get(0).getClass());
// @formatter:off
MetricRequest actual = (MetricRequest) m.getTcpRequests().getResponses().get(0);
MetricRequest expected = new MetricRequest(
Metric.newBuilder()
.name("sys.cpu.user")
.value(TEST_TIME, 1.0D)
.tag(new Tag("tag1", "value1"))
.tag(new Tag("tag2", "value2"))
.build()
);
Assert.assertEquals(expected, actual);
Assert.assertEquals(MetricRequest.class, m.getTcpRequests().getResponses().get(1).getClass());
actual = (MetricRequest) m.getTcpRequests().getResponses().get(1);
expected = new MetricRequest(
Metric.newBuilder()
.name("sys.cpu.idle")
.value(TEST_TIME + 1, 1.0D)
.tag(new Tag("tag3", "value3"))
.tag(new Tag("tag4", "value4"))
.build()
);
// @formatter:on
Assert.assertEquals(expected, actual);
} finally {
m.shutdown();
}
}
示例4: testScalarEncoding
import com.google.flatbuffers.FlatBufferBuilder; //导入方法依赖的package包/类
@Test
public void testScalarEncoding() {
val scalar = Nd4j.trueScalar(2.0f);
FlatBufferBuilder bufferBuilder = new FlatBufferBuilder(0);
val fb = scalar.toFlatArray(bufferBuilder);
bufferBuilder.finish(fb);
val db = bufferBuilder.dataBuffer();
val flat = FlatArray.getRootAsFlatArray(db);
val restored = Nd4j.createFromFlatArray(flat);
assertEquals(scalar, restored);
}
示例5: testVectorEncoding
import com.google.flatbuffers.FlatBufferBuilder; //导入方法依赖的package包/类
@Test
public void testVectorEncoding() {
val scalar = Nd4j.trueVector(new float[]{1, 2, 3, 4, 5});
FlatBufferBuilder bufferBuilder = new FlatBufferBuilder(0);
val fb = scalar.toFlatArray(bufferBuilder);
bufferBuilder.finish(fb);
val db = bufferBuilder.dataBuffer();
val flat = FlatArray.getRootAsFlatArray(db);
val restored = Nd4j.createFromFlatArray(flat);
assertEquals(scalar, restored);
}