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)); }
42int main(
int argc,
char* argv[])
45 for (
int i = 1; i < argc; ++i)
47 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
51 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
57 msg_in1.set_telegram(
"hello!");
60 gettimeofday(&t,
nullptr);
63 msg_in1.mutable_header()->set_time(now);
64 msg_in1.mutable_header()->set_time_signed(now);
65 msg_in1.mutable_header()->set_time_double(now / 1000000);
69 msg_in1.mutable_header()->set_pasttime_double(past);
70 msg_in1.mutable_header()->set_futuretime_double(future);
73 msg_in1.mutable_header()->set_time_precision(now + msec);
74 msg_in1.mutable_header()->set_time_double_precision((now + t.tv_usec) / 1000000.0);
76 msg_in1.mutable_header()->set_source_platform(1);
77 msg_in1.mutable_header()->set_dest_platform(3);
78 msg_in1.mutable_header()->set_dest_type(Header::PUBLISH_OTHER);
79 msg_in1.set_const_int(3);
81 if (dccl::dlog.is(dccl::logger::INFO))
83 codec.info(msg_in1.GetDescriptor(), &dccl::dlog);
85 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in1.DebugString() << std::endl;
86 codec.load(msg_in1.GetDescriptor());
87 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
89 codec.encode(&bytes1, msg_in1);
90 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
93 bytes1 += std::string(10,
'\0');
95 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
97 auto* msg_out1 = codec.decode<GobyMessage*>(bytes1);
98 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out1->DebugString() << std::endl;
99 assert(msg_in1.SerializeAsString() == msg_out1->SerializeAsString());
110 dccl::v2::TimeCodecClock::set_clock<DummyClock<past_now + 1000000>>();
114 msg_in1.set_time(past_now);
116 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in1.DebugString() << std::endl;
117 codec.load(msg_in1.GetDescriptor());
118 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
120 codec.encode(&bytes1, msg_in1);
121 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
123 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
124 auto msg_out1 = codec.decode<std::unique_ptr<google::protobuf::Message>>(bytes1);
125 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out1->DebugString() << std::endl;
126 assert(msg_in1.SerializeAsString() == msg_out1->SerializeAsString());
129 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
bool is(logger::Verbosity verbosity, logger::Group group=logger::GENERAL)
Indicates the verbosity of the Logger until the next std::flush or std::endl. The boolean return is u...
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Dynamic Compact Control Language namespace.
google::protobuf::int64 int64
a signed 64 bit integer
void hex_encode(CharIterator begin, CharIterator end, std::string *out, bool upper_case=false)
Encodes a (little-endian) hexadecimal string from a byte string. Index 0 of begin is written to index...