26 #include "../../native_protobuf/dccl_native_protobuf.h"
27 #include <google/protobuf/descriptor.pb.h>
29 #include "../../binary.h"
30 #include "../../codec.h"
36 int main(
int ,
char* [])
38 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
39 codec.load<TestMsg>();
40 codec.info<TestMsg>();
54 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
55 std::cout <<
"Try encode..." << std::endl;
57 codec.encode(&bytes, msg_in);
58 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
60 std::cout <<
"Try decode..." << std::endl;
61 std::cout << codec.max_size(msg_in.GetDescriptor()) << std::endl;
64 codec.decode(bytes, &msg_out);
66 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
67 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
86 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
87 std::cout <<
"Try encode..." << std::endl;
89 codec.encode(&bytes, msg_in);
90 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
92 std::cout <<
"Try decode..." << std::endl;
93 std::cout << codec.max_size(msg_in.GetDescriptor()) << std::endl;
96 codec.decode(bytes, &msg_out);
98 msg_in.mutable_a()->RemoveLast();
100 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
101 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
116 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
117 std::cout <<
"Try encode..." << std::endl;
119 codec.encode(&bytes, msg_in);
120 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
122 std::cout <<
"Try decode..." << std::endl;
123 std::cout << codec.max_size(msg_in.GetDescriptor()) << std::endl;
126 codec.decode(bytes, &msg_out);
128 auto bmin = dccl::test::TestMsg::descriptor()
129 ->FindFieldByName(
"b")
131 .GetExtension(dccl::field)
136 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
137 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
143 codec.load<InvalidTestMsgMissingMaxRepeat>();
154 codec.load<InvalidTestMsgMaxRepeatLessThanOne>();
165 codec.load<InvalidTestMsgMaxRepeatLessThanMinRepeat>();
173 std::cout <<
"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.
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
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...