Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 作为顶部元件的扁平联轴节_C_Flatbuffers - Fatal编程技术网

C 作为顶部元件的扁平联轴节

C 作为顶部元件的扁平联轴节,c,flatbuffers,C,Flatbuffers,我参考了下面的链接来理解Union是如何在flatbuffers中编码/解码的 我对IDL的定义如下 table EthEndpoint { // ethernet fields } table WifiEndpoint { // wifi fields } union EndpointData { EthEndpoint, WifiEndpoint } flatcc_builder_t builder; flatcc_builder_init(&am

我参考了下面的链接来理解Union是如何在flatbuffers中编码/解码的

我对IDL的定义如下

table EthEndpoint
{
    // ethernet fields
}

table WifiEndpoint
{
    // wifi fields
}

union EndpointData
{
    EthEndpoint,
    WifiEndpoint
}


flatcc_builder_t builder;
flatcc_builder_init(&builder);

EthEndpoint_start(&builder)
// populate using EthEndpoint_*_add(&builder, ...)
EthEndpoint_ref_t eth_ep = EthEndpoint_end(&builder);

EndpointData_ref_t ep = EndpointData_as_EthEndpoint(eth_ep);

how to add ep to builder? There are no generated methods EndpointData_start/ EndpointData_end/ EndpointData_create.

size_t size;
void *buf = flatcc_builder_get_direct_buffer(&builder, &size);

// store the buffer to disk
flatcc_builder_clear(&builder);

如何将ep添加到生成器?没有EndpointData\u start/EndpointData\u end/EndpointData\u create。

不能将并集作为缓冲区的根。添加一个包装它的表,然后使用生成的代码来设置类型和值。

它在任何地方都有文档记录吗?如果是,我为没有正确阅读而道歉。如果没有,我们能否将其添加到文档中?是的:我已经创建了另一个表和联合作为一个字段,这解决了我的问题。至少在上面的链接中没有找到任何明确表示“联合字段不能用作根元素”的引用,我可能遗漏了什么。谢谢你的评论。