27 #include "../../codec.h"
28 #include "../../codecs2/field_codec_default.h"
33 #include "../../binary.h"
38 using time_point = std::chrono::time_point<std::chrono::system_clock>;
39 static time_point now() {
return time_point(std::chrono::microseconds(fixed_time_usec)); }
42 int main(
int ,
char* [])
44 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
50 msg_in1.set_telegram(
"hello!");
53 gettimeofday(&t,
nullptr);
56 msg_in1.mutable_header()->set_time(now);
57 msg_in1.mutable_header()->set_time_signed(now);
58 msg_in1.mutable_header()->set_time_double(now / 1000000);
62 msg_in1.mutable_header()->set_pasttime_double(past);
63 msg_in1.mutable_header()->set_futuretime_double(future);
66 msg_in1.mutable_header()->set_time_precision(now + msec);
67 msg_in1.mutable_header()->set_time_double_precision((now + t.tv_usec) / 1000000.0);
69 msg_in1.mutable_header()->set_source_platform(1);
70 msg_in1.mutable_header()->set_dest_platform(3);
71 msg_in1.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
72 msg_in1.set_const_int(3);
74 codec.info(msg_in1.GetDescriptor(), &std::cout);
75 std::cout <<
"Message in:\n" << msg_in1.DebugString() << std::endl;
76 codec.load(msg_in1.GetDescriptor());
77 std::cout <<
"Try encode..." << std::endl;
79 codec.encode(&bytes1, msg_in1);
80 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
83 bytes1 += std::string(10,
'\0');
85 std::cout <<
"Try decode..." << std::endl;
87 auto* msg_out1 = codec.decode<GobyMessage*>(bytes1);
88 std::cout <<
"... got Message out:\n" << msg_out1->DebugString() << std::endl;
89 assert(msg_in1.SerializeAsString() == msg_out1->SerializeAsString());
100 dccl::v2::TimeCodecClock::set_clock<DummyClock<past_now + 1000000>>();
104 msg_in1.set_time(past_now);
106 std::cout <<
"Message in:\n" << msg_in1.DebugString() << std::endl;
107 codec.load(msg_in1.GetDescriptor());
108 std::cout <<
"Try encode..." << std::endl;
110 codec.encode(&bytes1, msg_in1);
111 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
113 std::cout <<
"Try decode..." << std::endl;
114 auto msg_out1 = codec.decode<std::unique_ptr<google::protobuf::Message>>(bytes1);
115 std::cout <<
"... got Message out:\n" << msg_out1->DebugString() << std::endl;
116 assert(msg_in1.SerializeAsString() == msg_out1->SerializeAsString());
119 std::cout <<
"all tests passed" << std::endl;