26 #include "../../codec.h"
31 #include "../../binary.h"
35 int main(
int ,
char* [])
37 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
43 msg_in1.set_telegram(
"hello!");
46 gettimeofday(&t,
nullptr);
49 msg_in1.mutable_header()->set_time(now);
50 msg_in1.mutable_header()->set_time_signed(now);
51 msg_in1.mutable_header()->set_time_double(now / 1000000);
55 msg_in1.mutable_header()->set_pasttime_double(past);
56 msg_in1.mutable_header()->set_futuretime_double(future);
59 msg_in1.mutable_header()->set_time_precision(now + msec);
60 msg_in1.mutable_header()->set_time_double_precision((now + t.tv_usec) / 1000000.0);
62 msg_in1.mutable_header()->set_source_platform(1);
63 msg_in1.mutable_header()->set_dest_platform(3);
64 msg_in1.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
65 msg_in1.set_const_int(3);
67 codec.info(msg_in1.GetDescriptor(), &std::cout);
68 std::cout <<
"Message in:\n" << msg_in1.DebugString() << std::endl;
69 codec.load(msg_in1.GetDescriptor());
70 std::cout <<
"Try encode..." << std::endl;
72 codec.encode(&bytes1, msg_in1);
73 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
76 bytes1 += std::string(10,
'\0');
78 std::cout <<
"Try decode..." << std::endl;
80 auto* msg_out1 = codec.decode<GobyMessage*>(bytes1);
81 std::cout <<
"... got Message out:\n" << msg_out1->DebugString() << std::endl;
82 assert(msg_in1.SerializeAsString() == msg_out1->SerializeAsString());
85 std::cout <<
"all tests passed" << std::endl;