views:

47

answers:

1

Does anybody have some example code showing the pipeline of serializing a std::string sending it through a boost::interprocess::message_queue and getting it back out again?

+1  A: 

You need to serialize your data because boost::interprocess::message_queue operates on byte arrays. If all your messages are strings, just do:

size_t const max_msg_size = 0x100;
boost::interprocess::message_queue q(..., max_msg_size);

// sending
std::string s(...);
q.send(s.data(), s.size(), 0);

// receiving
std::string s;
s.resize(max_msg_size);
size_t msg_size;
unsigned msg_prio;
q.receive(&s[0], s.size(), msg_size, msg_prio);
s.resize(msg_size);
Maxim Yegorushkin
Thanks for that.
bradgonesurfing