ZIO
Python and C++ interface to ZeroMQ and Zyre
test_encoding.cpp
Go to the documentation of this file.
1 
4 #include "zio/cppzmq.hpp"
5 #include "zio/main.hpp"
6 #include "zio/logging.hpp"
7 #include <czmq.h> // normally we don't use this directly in ZIO
8 #include <string>
9 #include <vector>
10 
11 int main()
12 {
13  zio::init_all();
14 
15  const std::string prefix="ZIO4TEXTTo be or not to be that ?"; // length 33, ascii 33 is !
16 
17  zmsg_t* msg = zmsg_new();
18  zmsg_addstr(msg, prefix.c_str());
19  struct XYZ {
20  uint64_t a{0x6644444444444444},b{0x5555555555555555}, c{0x4466666666666666};
21  } xyz;
22  zmsg_addmem(msg, &xyz, sizeof(XYZ));
23  zframe_t* frame = zmsg_encode(msg);
24  std::vector<std::uint8_t> ret(zframe_data(frame), zframe_data(frame) + zframe_size(frame));
25 
26  {
27  zio::message_t cppmsg(zframe_data(frame), zframe_size(frame));
28  zio::multipart_t cppmmsg = zio::multipart_t::decode(cppmsg);
29  assert(cppmmsg.size() == 2);
30  assert(cppmmsg.at(0).to_string() == prefix);
31  }
32 
33  zframe_destroy(&frame);
34  zmsg_destroy(&msg);
35 
36  zio::debug("{} {}", prefix.size(), prefix);
37 
38  for (size_t ind=0; ind<ret.size(); ++ind) {
39  zio::debug("{}: {} ({})", ind, ret[ind], (int)ret[ind]);
40  }
41 
42  return 0;
43 
44 }
int main()
void init_all()
Definition: main.cpp:22