ZIO
Python and C++ interface to ZeroMQ and Zyre
test_str.cpp
Go to the documentation of this file.
1 #include <czmq.h>
2 #include <string>
3 #include <iomanip>
4 #include <iostream>
5 using namespace std;
6 int main()
7 {
8 
9  zsock_t* o = zsock_new(ZMQ_PAIR);
10  zsock_bind(o, "inproc://teststr");
11  zsock_t* i = zsock_new(ZMQ_PAIR);
12  zsock_connect(i, "inproc://teststr");
13 
14  // from port::send()
15  zmsg_t* msg = zmsg_new();
16  zmsg_addstrf(msg, "ZIO%d%s%s", 4, "TEXT",
17  "Live long int and be unsigned");
18  uint64_t coords[2] = {0xf12edeadbeaf, (uint64_t)zclock_time()};
19  zmsg_addmem(msg, coords, 2*sizeof(uint64_t));
20  zmsg_addmem(msg, NULL, 0);
21  zmsg_send(&msg, o);
22 
23 
24  msg = zmsg_recv(i);
25  char* got = zmsg_popstr(msg);
26  std::string gots = got;
27  free (got);
28  cerr << "Size: " << gots.size() << " " << strlen(got)
29  << ": " << gots << endl;
30 
31  char lvl = gots[3];
32  std::string format = gots.substr(4,4);
33  std::string label = gots.substr(8);
34  cerr << "h1: L" << lvl << " " << format << " \"" << label << "\"\n";
35 
36  zframe_t* ogf = zmsg_pop(msg);
37  uint64_t* og = (uint64_t*)zframe_data(ogf); // not at all safe
38  uint64_t origin=og[0], granule=og[1];
39  zframe_destroy(&ogf);
40 
41  cerr << "h2: "
42  << std::hex << std::uppercase << " o=0X" << origin
43  << " (" << std::dec << origin << " )"
44  << std::hex << std::uppercase << " g=0X" << granule
45  << " (" << std::dec << granule << " )"
46  << endl;
47 
48  int nleft = zmsg_size(msg);
49  cerr << "pay: " << nleft << " frames" << endl;
50  while (nleft) {
51  --nleft;
52  zframe_t* frame = zmsg_pop(msg);
53  cerr << "\tframe size: " << zframe_size(frame) << endl;
54  zframe_destroy(&frame);
55  }
56 
57  zmsg_destroy(&msg);
58  zsock_destroy(&i);
59  zsock_destroy(&o);
60  return 0;
61 }
int main()
Definition: test_str.cpp:6