I'm working on a project and I need to be able to send byte arrays through Qpid, but Variant has no idea what an array is. Is there some way, I can convert the byte array into something Variant, like maybe a Variant::list of unit8, or a Variant::string, then when I get the response, I can convert the string or list back into a byte[]?
Thanks,
I would use the qpid::types::Variant::List
. Convert all of your bytes (I assume you're using unsigned char
) to uint8_t
and then append them to the list.
Example:
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. */
I have not tested this, but it should provide a general overview.
If you have further questions, feel free to ask and I'll try to answer them as best as I can.
References: