29#include "../../codec.h"
39 msg_in.set_req_i32(-50);
40 msg_in.set_req_ui32(512);
41 msg_in.set_opt_i32(200);
42 msg_in.set_opt_ui32(100);
45 codec.encode(&encoded, msg_in);
48 codec.decode(encoded, &msg_out);
50 assert(msg_in.req_i32() == msg_out.req_i32());
51 assert(msg_in.req_ui32() == msg_out.req_ui32());
52 assert(msg_out.has_opt_i32());
53 assert(msg_in.opt_i32() == msg_out.opt_i32());
54 assert(msg_out.has_opt_ui32());
55 assert(msg_in.opt_ui32() == msg_out.opt_ui32());
56 assert(!msg_out.has_child());
59 codec2.
decode(encoded, &msg2_out);
61 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Msg in: " << msg_in.ShortDebugString() << std::endl;
62 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Msg out: " << msg_out.ShortDebugString() << std::endl;
63 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Msg2 out: " << msg2_out.ShortDebugString() << std::endl;
65 assert(msg_in.req_i32() == msg2_out.req_i32());
66 assert(msg_in.req_ui32() == msg2_out.req_ui32());
67 assert(msg2_out.has_opt_i32());
68 assert(msg_in.opt_i32() == msg2_out.opt_i32());
69 assert(msg2_out.has_opt_ui32());
70 assert(msg_in.opt_ui32() == msg2_out.opt_ui32());
71 assert(!msg2_out.has_child());
78 msg_in.set_req_i32(0);
79 msg_in.set_req_ui32(10);
83 codec.encode(&encoded, msg_in);
86 codec.decode(encoded, &msg_out);
88 assert(msg_in.req_i32() == msg_out.req_i32());
89 assert(msg_in.req_ui32() == msg_out.req_ui32());
90 assert(!msg_out.has_opt_i32());
91 assert(!msg_out.has_opt_ui32());
100 codec.encode(&encoded, msg_in);
103 codec.decode(encoded, &msg_out);
105 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Msg in: " << msg_in.ShortDebugString() << std::endl;
106 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Msg out: " << msg_out.ShortDebugString() << std::endl;
108 assert(msg_in.req_i32() == msg_out.req_i32());
111 assert(msg_out.req_ui32() == 10);
118 msg_in.mutable_child()->set_req_dbl(0.4);
121 codec.encode(&encoded, msg_in);
124 codec.decode(encoded, &msg_out);
126 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Msg in: " << msg_in.ShortDebugString() << std::endl;
127 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Msg out: " << msg_out.ShortDebugString() << std::endl;
129 assert(msg_in.req_i32() == msg_out.req_i32());
132int main(
int argc,
char* argv[])
134 bool verbose =
false;
135 for (
int i = 1; i < argc; ++i)
137 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
141 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
145 codec3.
load<Proto3Msg>();
146 codec2.
load<Proto2Msg>();
147 codec3.
info<Proto3Msg>(&dccl::dlog);
148 codec2.
info<Proto2Msg>(&dccl::dlog);
150 test1(codec3, codec2);
155 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 ...
void info(std::ostream *os=nullptr, int user_id=-1) const
Writes a human readable summary (including field sizes) of the provided DCCL type to the stream provi...
CharIterator decode(CharIterator begin, CharIterator end, ProtobufMessage *msg, bool header_only=false)
Decode a DCCL message when the type is known at compile time.
std::size_t load()
All messages must be explicited loaded and validated (size checks, option extensions checks,...
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.