26#include "../../codec.h"
31#include "../../binary.h"
35int main(
int argc,
char* argv[])
38 for (
int i = 1; i < argc; ++i)
40 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
44 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &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 if (dccl::dlog.is(dccl::logger::INFO))
76 codec.info(msg_in1.GetDescriptor(), &dccl::dlog);
78 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in1.DebugString() << std::endl;
79 codec.load(msg_in1.GetDescriptor());
80 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
82 codec.encode(&bytes1, msg_in1);
83 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
86 bytes1 += std::string(10,
'\0');
88 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
90 auto* msg_out1 = codec.decode<GobyMessage*>(bytes1);
91 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out1->DebugString() << std::endl;
92 assert(msg_in1.SerializeAsString() == msg_out1->SerializeAsString());
95 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...