26#include "../../codec.h"
30int main(
int argc,
char* argv[])
33 for (
int i = 1; i < argc; ++i)
35 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
39 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
44 ShortIDMsg short_id_msg;
45 codec.load(short_id_msg.GetDescriptor());
46 codec.info(short_id_msg.GetDescriptor(), &dccl::dlog);
49 assert(codec.size(short_id_msg) == 1);
50 codec.encode(&encoded, short_id_msg);
51 assert(codec.id(encoded) == 2);
52 codec.decode(encoded, &short_id_msg);
56 LongIDMsg long_id_msg;
58 codec.load(long_id_msg.GetDescriptor());
59 codec.info(long_id_msg.GetDescriptor(), &dccl::dlog);
60 assert(codec.size(long_id_msg) == 2);
61 codec.encode(&encoded, long_id_msg);
62 assert(codec.id(encoded) == 10000);
63 assert(encoded.size() == 2);
64 codec.decode(encoded, &long_id_msg);
69 codec.id(std::string());
75 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Expected exception: " << e.what() << std::endl;
79 codec.id(encoded.substr(0, 1));
85 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Expected exception: " << e.what() << std::endl;
90 ShortIDEdgeMsg short_id_edge_msg;
92 codec.load(short_id_edge_msg.GetDescriptor());
93 codec.info(short_id_edge_msg.GetDescriptor(), &dccl::dlog);
94 assert(codec.size(short_id_edge_msg) == 1);
95 codec.encode(&encoded, short_id_edge_msg);
96 assert(codec.id(encoded) == 127);
97 codec.decode(encoded, &short_id_edge_msg);
101 LongIDEdgeMsg long_id_edge_msg;
103 codec.load(long_id_edge_msg.GetDescriptor());
104 codec.info(long_id_edge_msg.GetDescriptor(), &dccl::dlog);
105 codec.encode(&encoded, long_id_edge_msg);
106 assert(codec.id(encoded) == 128);
107 codec.decode(encoded, &long_id_edge_msg);
108 assert(codec.size(long_id_edge_msg) == 2);
112 TooLongIDMsg too_long_id_msg;
116 codec.load(too_long_id_msg.GetDescriptor());
125 ShortIDMsgWithData short_id_msg_with_data;
127 codec.load(short_id_msg_with_data.GetDescriptor());
128 codec.info(short_id_msg_with_data.GetDescriptor(), &dccl::dlog);
130 short_id_msg_with_data.set_in_head(42);
131 short_id_msg_with_data.set_in_body(37);
132 codec.encode(&encoded, short_id_msg_with_data);
133 assert(codec.id(encoded) == 3);
134 codec.decode(encoded, &short_id_msg_with_data);
137 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.