java - 缺少在 Java 中创建结构 vector 的帮助程序

标签 java flatbuffers

让我们假设以下 FlatBuffer 架构作为示例:

struct Ipv6 {
    b0: byte;
    b1: byte;
    b2: byte;
    b3: byte;
    b4: byte;
    b5: byte;
    b6: byte;
    b7: byte;
    b8: byte;
    b9: byte;
    b10: byte;
    b11: byte;
    b12: byte;
    b13: byte;
    b14: byte;
    b15: byte;
}

table Ipv6List {
    entries: [Ipv6];
}

root_type Ipv6List;

我遇到的问题是创建一个包含Ipv6结构的 vector 。由 Flatbuffer 1.11.0 生成的 Java 类 Ipv6List 不包含通常的 create 帮助程序。阅读文档,这似乎是一种通过防止创建临时对象来提高性能的设计选择。

查看其他方法,有一个 Ipv6List#startEntriesVector 静态函数,但没有关联的 addXendX 函数。这是我正在尝试做的事情:

FlatBufferBuilder builder = new FlatBufferBuilder();

final byte[] inetAddressBytes =
        Inet6Address.getByName("2a01:e35:2e7a:490:6193:c54c:f740:f907").getAddress();

int ipv6Offset = Ipv6.createIpv6(builder,
        inetAddressBytes[0], inetAddressBytes[1], inetAddressBytes[2], inetAddressBytes[3],
        inetAddressBytes[4], inetAddressBytes[5], inetAddressBytes[6], inetAddressBytes[7],
        inetAddressBytes[8], inetAddressBytes[9], inetAddressBytes[10], inetAddressBytes[11],
        inetAddressBytes[12], inetAddressBytes[13], inetAddressBytes[14], inetAddressBytes[15]
);

Ipv6List.startEntriesVector(builder, 1);

// how to add the IP to the vector ?
// how to end the association and get the vector offset ?
// int ipsVectorOffset = ?;

int ipListOffset = Ipv6List.createIpv6List(builder, ipsVectorOffset);
builder.finish(ipListOffset);
ByteBuffer byteBuffer = builder.dataBuffer();

知道如何创建 Ipv6 结构 vector 并将其与列表关联吗?

最佳答案

结构体总是需要内联创建,因此操作顺序应该是:

Ipv6List.startEntriesVector(builder, 1);
Ipv6.createIpv6(builder,..);
o = builder.endVector();
Ipv6List.createIpv6List(builder, o);

关于java - 缺少在 Java 中创建结构 vector 的帮助程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59667674/

相关文章:

java - 如何从文件系统加载任意 java .class 文件并对其进行反射(reflect)?

java - 在android中移动圆圈

java - FlatBuffer 的零分配的 Java 实现是什么?

java - 深拷贝FlatBuffer对象的方法

java 流 : elegant way to filter according an exception is thrown

java - JAVA从目录中逐行读取多个文本文件

java - 我怎么知道 SMS 是否已到达 Twilio 中的目的地

c++ - 带有多个标志的 target_compile_definitions

c++ - 检查FlexBuffers缓冲区在C++中是否未损坏

c++ - 如何在 OSX 上构建 FlatBuffers ?