32#include "../../binary.h"
33#include "../../codec.h"
38template <
typename BarMsg>
void run_test(
const std::string& label)
43 msg_in.mutable_foo()->mutable_header()->set_field(42);
44 msg_in.mutable_foo()->set_body_field(99);
45 msg_in.set_bar_body(77);
47 codec.load(msg_in.GetDescriptor());
48 if (dccl::dlog.is(dccl::logger::INFO))
50 codec.info(msg_in.GetDescriptor(), &dccl::dlog);
52 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << label <<
" message in:\n" << msg_in.DebugString() << std::endl;
55 codec.encode(&bytes, msg_in);
56 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << label <<
" encoded (hex): " <<
dccl::hex_encode(bytes) << std::endl;
59 codec.decode(bytes, &msg_out);
60 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << label <<
" message out:\n" << msg_out.DebugString() << std::endl;
63 assert(msg_out.foo().header().field() == msg_in.foo().header().field());
65 assert(msg_out.foo().body_field() == msg_in.foo().body_field());
66 assert(msg_out.bar_body() == msg_in.bar_body());
68 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
70 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << label <<
" passed.\n" << std::endl;
73int main(
int argc,
char* argv[])
76 for (
int i = 1; i < argc; ++i)
78 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
82 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
84 run_test<BarV4>(
"BarV4 (codec_version=4)");
85 run_test<BarV5>(
"BarV5 (codec_version=5)");
87 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...