【发布时间】:2020-01-09 15:50:56
【问题描述】:
我们假设以下 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 结构的向量。 Flatbuffer 1.11.0 生成的 Java 类 Ipv6List 不包括通常的 create 帮助器。阅读文档似乎是一种通过防止创建临时对象来提高性能的设计选择。
查看其他方法,有一个Ipv6List#startEntriesVector 静态函数,但没有关联的addX 和endX 函数。这是我想要做的:
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 结构的向量并将其与列表关联吗?
【问题讨论】:
标签: java flatbuffers