26#include "../../codec.h"
32#include "../../binary.h"
35static_assert(TestMessage1::DCCL_ID == 4);
36static_assert(TestMessage1::DCCL_MAX_BYTES == 64);
38static_assert(TestMessage2::DCCL_ID == 5);
39static_assert(TestMessage2::DCCL_MAX_BYTES == 64);
41template <
typename Message>
void run_test(
dccl::Codec& codec, Message& msg_in)
43 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
45 codec.encode(&bytes, msg_in);
46 dccl::dlog.
is(dccl::logger::INFO) &&
47 dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
49 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
51 auto msg_out = codec.decode<std::unique_ptr<google::protobuf::Message>>(bytes);
52 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n"
53 << msg_out->DebugString() << std::endl;
54 assert(msg_in.SerializeAsString() == msg_out->SerializeAsString());
57int main(
int argc,
char* argv[])
60 for (
int i = 1; i < argc; ++i)
62 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
66 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
69 codec.load_library(
"libtest_autoload" SHARED_LIBRARY_SUFFIX);
71 if (dccl::dlog.is(dccl::logger::INFO))
72 codec.info_all(&dccl::dlog);
76 run_test(codec, msg_in1);
80 run_test(codec, msg_in2);
84 run_test(codec, msg_in3);
86 TestMessage3SupersetName msg_in4;
88 run_test(codec, msg_in4);
90 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.
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...