28#include "../../native_protobuf/dccl_native_protobuf.h"
29#include <google/protobuf/descriptor.pb.h>
31#include "../../binary.h"
32#include "../../codec.h"
38int main(
int argc,
char* argv[])
41 for (
int i = 1; i < argc; ++i)
43 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
47 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
48 codec.load<TestMsg>();
49 codec.info<TestMsg>();
63 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
64 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
66 codec.encode(&bytes, msg_in);
67 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
69 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
70 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << codec.max_size(msg_in.GetDescriptor()) << std::endl;
73 codec.decode(bytes, &msg_out);
75 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
76 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
95 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;
102 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << codec.max_size(msg_in.GetDescriptor()) << std::endl;
105 codec.decode(bytes, &msg_out);
107 msg_in.mutable_a()->RemoveLast();
109 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
110 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
125 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
126 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
128 codec.encode(&bytes, msg_in);
129 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
131 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
132 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << codec.max_size(msg_in.GetDescriptor()) << std::endl;
135 codec.decode(bytes, &msg_out);
137 auto bmin = dccl::test::TestMsg::descriptor()
138 ->FindFieldByName(
"b")
140 .GetExtension(dccl::field)
145 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
146 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
152 codec.load<InvalidTestMsgMissingMaxRepeat>();
163 codec.load<InvalidTestMsgMaxRepeatLessThanOne>();
174 codec.load<InvalidTestMsgMaxRepeatLessThanMinRepeat>();
182 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_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...