forked from PatWie/tf_zmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.cpp
53 lines (37 loc) · 1.21 KB
/
dump.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "includes/zmq.hpp"
#include "includes/tensor_msg.hpp"
#include <msgpack.hpp>
#include <iostream>
#include <chrono>
#include <string>
#include <thread>
int main () {
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_PULL);
socket.bind ("ipc:///tmp/ipc-socket-0");
while (true) {
zmq::message_t rawmsg;
// message reader
socket.recv (&rawmsg);
msgpack::object_handle oh = msgpack::unpack(static_cast<char*>(rawmsg.data()), rawmsg.size());
// list of tensors
std::vector<tensor_msg> tensors;
// read and convert
msgpack::object obj = oh.get();
char* ptr = static_cast<char*>(rawmsg.data());
int off = 0;
std::cout << "buf: ";
for (int i = 0; i < rawmsg.size(); ++i)
{
std::cout << std::hex << std::setw(2) << std::setfill('0');
std::cout << (static_cast<int>(ptr[i]) & 0xff) << ' ';
}
std::cout << std::endl;
std::cout << "obj: ";
std::cout << obj << std::endl;
// wait
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
return 0;
}