我正在使用 Simulation Open Framework Architecture SOFA (C++
语言),我的目标是在一些 sofa 源 native 数据与其他外部应用程序之间设置某种通信类型。通过这个订单,我使用 ZeroMQ 将沙发数据传输到 Python 外部应用程序。
在 SOFA (C++
) 中,我有以下 instrumentData
结构
#include <sofa/core/behavior/BaseController.h>
#include <sofa/defaulttype/VecTypes.h>
// To Quat datatype
#include <sofa/defaulttype/Quat.h>
using sofa::defaulttype::Quat;
using std::string;
namespace sofa
{
namespace component
{
namespace controller
{
struct instrumentData
{
typedef sofa::defaulttype::Vec3d Vec3d;
Vec3d pos;
Quat quat;
int btnState;
float openInst;
bool blnDataReady;
};
}
}
}
我正在尝试通过 zmq 与以下数据成员 instrumentData
结构进行数据通信,并序列化/反序列化我正在使用的这些数据 Google Protocol Buffer按照我的 python 命运数据应用程序的顺序理解并解释它的 instrumentData 数据成员结构的内容。目前,此数据成员结构以二进制格式/内容到达您的目的地。
Google Protocol Buffer 要求以 .proto
文件扩展名中构建的格式描述协议(protocol),其中是必需的
you'll need to start with a .proto file. The definitions in a .proto file are simple: you add a message for each data structure you want to serialize, then specify a name and a type for each field in the message.
如何在我的 instrumentdata.proto
文件中表示以下字段:pos
、quat
、bool
... ?
typedef sofa::defaulttype::Vec3d Vec3d;
Vec3d pos;
using sofa::defaulttype::Quat;
Quat quat;
bool blnDataReady;
目前,in the documentation不清楚我应该如何定义与 Vectors 和其他数据类型相关的字段,例如 SOFA 原生的 Quat
(四元数)。
Vec3d
和 Quat
由以下元素组成:
void ZMQServerComponent::instrumentDataSend(instrumentData a)
{
a.pos = sofa::defaulttype::Vec3d(1.0f, 1.0f, 1.0f);
a.quat = defaulttype::Quat(1.0f, 1.0f, 4.0f, 1.0f);
}
可以定义为enumerators ?
更新
目前我正在根据 documentation 构建的暂定 instumentdata.proto
文件是:
sintax = "proto3";
message InstrumentData {
// enum Pos {}
// enum Quat {}
int32 btnState;
float openInst;
bool blnDataReady
}
虽然我对这个单一的协议(protocol)定义有一些疑问
最佳答案
根据描述,Vec3d
和 Quat
不是枚举,而是结构,您可以将其描述为单独的 message
类型,例如
message Vec3d {
float x = 1;
float y = 2;
float z = 3;
}
和
message Quat {
float a = 1;
float b = 2;
float c = 3;
float d = 4;
}
然后可以在 InstrumentData
中使用这些消息类型消息类型
message InstrumentData {
Vec3d pos = 1;
Quat quat = 2;
int32 btnState = 3;
float openInst = 4;
bool blnDataReady = 5;
}
关于c++ - 使用 Google Protocol Buffer - 如何在 .proto 文件中定义字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48509370/