29#include "../../codec.h"
30#include "../../codecs2/field_codec_default.h"
32#include "../../binary.h"
37int main(
int argc,
char* argv[])
40 for (
int i = 1; i < argc; ++i)
42 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
46 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
50 if (dccl::dlog.is(dccl::logger::INFO))
52 codec.info<TestMsg>(&dccl::dlog);
54 codec.load<TestMsg>();
57 TestMsg msg_in, msg_out;
59 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
61 codec.load(msg_in.GetDescriptor());
63 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
65 codec.encode(&bytes, msg_in);
66 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
68 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
70 codec.decode(bytes, &msg_out);
72 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
74 assert(!msg_out.has_msg1());
75 assert(!msg_out.msg1_repeat_size());
76 assert(!msg_out.has_msg2());
77 assert(!msg_out.msg2_repeat_size());
78 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
83 TestMsg msg_in, msg_out;
85 msg_in.mutable_msg1()->set_val(0.1);
86 msg_in.add_msg1_repeat()->set_val(0.11);
87 msg_in.add_msg1_repeat()->set_val(0.12);
88 msg_in.add_msg1_repeat()->set_val(0.13);
89 msg_in.mutable_msg2()->set_val(0.2);
90 msg_in.add_msg2_repeat()->set_val(0.21);
91 msg_in.add_msg2_repeat()->set_val(0.22);
92 msg_in.add_msg2_repeat()->set_val(0.23);
94 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
96 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
98 codec.encode(&bytes, msg_in);
99 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
101 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
103 codec.decode(bytes, &msg_out);
105 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
107 assert(msg_out.has_msg1());
108 assert(msg_out.msg1_repeat_size() == 3);
109 assert(msg_out.has_msg2());
110 assert(msg_out.msg2_repeat_size() == 3);
111 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
116 TestMsg msg_in, msg_out;
118 msg_in.mutable_msg1();
119 msg_in.mutable_msg2()->set_val(1);
120 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
122 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
124 codec.encode(&bytes, msg_in);
125 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
127 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
129 codec.decode(bytes, &msg_out);
131 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
133 assert(msg_out.has_msg1());
134 assert(msg_out.has_msg2());
135 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
138 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...