25#include "dccl/binary.h"
26#include "dccl/codec.h"
31int main(
int argc,
char* argv[])
34 for (
int i = 1; i < argc; ++i)
36 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
40 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
43 codec.load<MinLengthMsg>();
44 codec.info<MinLengthMsg>(&dccl::dlog);
54 msg_in.set_str_field(
"hello");
57 codec.encode(&encoded, msg_in);
60 codec.decode(encoded, &msg_out);
62 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
63 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Round-trip with fields at/above min_length: passed" << std::endl;
77 assert(codec.max_size<MinLengthMsg>() == 31);
78 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"max_size check: passed (31 bytes)" << std::endl;
88 codec.encode(&encoded, msg_in);
91 codec.decode(encoded, &msg_out);
93 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"msg_in: " << msg_in.ShortDebugString() << std::endl;
94 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"msg_out: " << msg_out.ShortDebugString() << std::endl;
99 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
100 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Round-trip with fields below min_length: passed" << std::endl;
108 msg_in.set_str_field(
"abc");
111 codec.encode(&encoded, msg_in);
113 MinLengthMsg msg_out;
114 codec.decode(encoded, &msg_out);
116 assert(!msg_out.has_opt_bytes());
117 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
118 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Optional bytes absent: passed" << std::endl;
123 codec.load<FixedLengthMsg>();
124 codec.info<FixedLengthMsg>(&dccl::dlog);
126 FixedLengthMsg msg_in;
130 codec.encode(&encoded, msg_in);
132 FixedLengthMsg msg_out;
133 codec.decode(encoded, &msg_out);
135 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
140 assert(codec.max_size<FixedLengthMsg>() == 6);
141 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Fixed-size bytes (min_length == max_length): passed" << std::endl;
148 codec.load<InvalidMinLengthMsg>();
149 assert(
false &&
"Expected exception for min_length > max_length");
153 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Invalid min_length > max_length correctly rejected: " << e.what()
158 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 ...
Exception class for 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_decode(const std::string &in, std::string *out)
Decodes a (little-endian) hexadecimal string to a byte string. Index 0 and 1 (first byte) of in are w...