-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_unpack_msg.cpp
More file actions
50 lines (41 loc) · 1.17 KB
/
test_unpack_msg.cpp
File metadata and controls
50 lines (41 loc) · 1.17 KB
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
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "include/raimd/md_msg.h"
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <hex_string>" << std::endl;
return 1;
}
// Convert the hex string to a byte array
size_t len = strlen(argv[1]);
if (len % 2 != 0) {
std::cerr << "Invalid hex string length" << std::endl;
return 1;
}
size_t byteArrayLen = len / 2;
unsigned char* byteArray = new unsigned char[byteArrayLen];
for (size_t i = 0; i < byteArrayLen; ++i) {
sscanf(argv[1] + 2*i, "%2hhx", &byteArray[i]);
}
// Create a memory manager
rai::md::MDMsgMem mem;
// Unpack the message
rai::md::MDMsg* msg = rai::md::MDMsg::unpack(
byteArray, 0, byteArrayLen, 0, nullptr, mem
);
if (!msg) {
std::cerr << "Failed to unpack message" << std::endl;
delete[] byteArray;
return 1;
}
// Create an output object
rai::md::MDOutput out;
// Print the unpacked message
out.printf("Unpacked message:\n");
msg->print(&out);
// Clean up
delete[] byteArray;
delete msg;
return 0;
}