How to pass complex objects (std :: string) via boost :: interprocess :: message queue

Does anyone have some sample code showing the std :: string serialization pipeline sending it via boost :: interprocess :: message_queue and returning it back?

+3
source share
2 answers

You need to serialize the data because boost :: interprocess :: message_queue works 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);
+8
source

, , (, ), .

- :

int Tokenize(std::vector<MessageToken>&, const Message&) const;
int Merge(Message&, const std::vector<MessageToken>&) const;                                    

/ message_queue.

Maxim , max_msg_size.

0

Source: https://habr.com/ru/post/1758388/


All Articles