我正在发送这样的消息:
char buffer[175];
sprintf(buffer, "MD: %4ld %2d %10s %5s %7.2f %5d\n"
, id
, position
, *(MktDepthOperation::ENUMS) operation
, *(MktDeptSide::ENUMS)side
, price
, size);
PrintProcessId, printf(buffer);
SolSendMessage("testhello", buffer);
...
void SolSendMessage(const char* topic, const char *text_p)
{
...
if (s_canSend) {
if ((rc = solClient_session_sendMsg(session_p, msg_p)) != SOLCLIENT_OK) {
...
}
在子方面,我只是转储消息。 如何从编码 solace 专有格式的二进制缓冲区扫描回字段? 我试图避免使用 google protocol buffers
并使用推荐的 Solace 专有格式
.
solClient_rxMsgCallback_returnCode_t
messageReceiveCallback ( solClient_opaqueSession_pt opaqueSession_p, solClient_opaqueMsg_pt msg_p, void *user_p )
{
//printf ( "Received message:\n" );
solClient_msg_dump ( msg_p, NULL, 0 );
printf ( "\n" );
msgCount++;
return SOLCLIENT_CALLBACK_OK;
}
最佳答案
从您的代码片段中不清楚如何在消息上设置缓冲区。要使用 Solace API 简单地发送和接收消息的二进制附件中的字符串,您可以在发送时使用 solClient_msg_setBinaryAttachment,在接收时使用 solClient_msg_getBinaryAttachment 检索字符串。不建议扫描 solClient_msg_dump 的输出,因为这将包含有关消息 header 的额外信息。此消息转储实用程序作为编程辅助工具提供,以方便消息应用程序的开发和测试,而不是直接提取消息中的数据。
另一个选择是使用 Solace 结构化数据类型。 Solace SDT 是结构化的、独立于语言和体系结构的数据类型。它们可以在消息中使用,以促进异构网络中二进制数据的交换,该网络具有使用不同硬件架构和编程语言的客户端。如果您要发送固定数据结构,则可以使用“createBinaryAttachmentStream”创建结构化数据流。
例如如果您有固定的数据结构,例如:
struct MD {
long id;
int position;
char operation[10];
char side[5];
float price;
int size);
}
您可以创建结构化数据流,然后为每个成员调用addInt64/addInt32/addString/addString/addFloat/addInt
。在接收端,您可以通过调用 getInt64/getInt32 等来检索 dataStructure 成员。否则,如果您不使用已知的数据结构,则可以使用映射而不是流并为每个成员命名适本地字段。
有关 Solace 结构化数据类型的更多信息,请参见此处: https://docs.solace.com/Solace-PubSub-Messaging-APIs/Developer-Guide/SDT-Containers.htm
关于c++ - 将安慰专有的二进制消息获取到 sscanf 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53218340/