我正在做一个项目,我需要能够通过Qpid发送字节数组,但是Variant不知道数组是什么。有什么方法可以将字节数组转换成某种变体,比如unit8的变量::list,或者变量::string,然后当我得到响应时,我可以将字符串或列表转换回byte[]?
谢谢,
发布于 2014-10-24 08:31:53
我会使用qpid::types::Variant::List
。将所有字节(我假设您使用的是unsigned char
)转换为uint8_t
,然后将它们附加到列表中。
示例:
unsigned char bytesToSend[] = {104, 101, 108, 108, 111}; /* "hello" */
int lengthOfArray = sizeof(bytesToSend)/sizeof(byteToSend[0]);
qpid::types::Variant::List lstToSend;
for(int i = 0; i < lengthOfArray; i++){
uint8_t thisByte = (uint8_t)bytesToSend[i];
lstToSend.push_back(qpid::types::Variant(thisByte));
}
qpid::messaging::Message msg;
qpid::messaging::encode(lstToSend, msg);
yourSender.send(msg, false); /* change false to true if you want to sync with the broker. */
我还没有测试这一点,但它应该提供一个总体的概述。
如果你还有更多的问题,请随便问,我会尽我所能去回答。
参考文献:
https://stackoverflow.com/questions/26476629
复制相似问题