26#include "../../binary.h"
27#include "../../codec.h"
34int main(
int argc,
char* argv[])
37 for (
int i = 1; i < argc; ++i)
39 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
43 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
52 msg_in1.set_int32_val(1);
53 msg_in2.set_bool_val(
false);
54 msg_in3.set_string_val(
"string1");
55 msg_in4.set_string_val(
"string2");
57 std::list<const google::protobuf::Message*> msgs;
58 msgs.push_back(&msg_in1);
59 msgs.push_back(&msg_in2);
60 msgs.push_back(&msg_in3);
61 msgs.push_back(&msg_in4);
63 std::list<const google::protobuf::Descriptor*> descs;
64 descs.push_back(msg_in1.GetDescriptor());
65 descs.push_back(msg_in2.GetDescriptor());
66 descs.push_back(msg_in3.GetDescriptor());
67 descs.push_back(msg_in4.GetDescriptor());
69 for (
auto desc : descs)
71 if (dccl::dlog.is(dccl::logger::INFO))
73 codec.info(desc, &dccl::dlog);
82 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message " << ++i <<
" in:\n" << msg->DebugString() << std::endl;
83 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
84 codec.encode(&bytes1, *msg);
86 bytes1 += std::string(4,
'\0');
88 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
89 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
93 std::list<std::shared_ptr<google::protobuf::Message>> msgs_out;
96 std::string::iterator begin = bytes1.begin(), end = bytes1.end();
99 auto it = codec.loaded().find(codec.id(begin, end));
100 if (it == codec.loaded().end())
103 std::shared_ptr<google::protobuf::Message> msg =
105 begin = codec.decode(begin, end, msg.get());
106 msgs_out.push_back(msg);
111 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << e.what() << std::endl;
114 std::list<const google::protobuf::Message*>::const_iterator in_it = msgs.begin();
116 assert(msgs.size() == msgs_out.size());
118 for (
const auto& it : msgs_out)
121 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message " << ++i <<
" out:\n" << it->DebugString() << std::endl;
122 assert((*in_it)->SerializeAsString() == it->SerializeAsString());
129 std::list<std::shared_ptr<google::protobuf::Message>> msgs_out;
132 while (!bytes1.empty())
134 codec.decode<std::shared_ptr<google::protobuf::Message>>(&bytes1));
138 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << e.what() << std::endl;
141 std::list<const google::protobuf::Message*>::const_iterator in_it = msgs.begin();
143 assert(msgs.size() == msgs_out.size());
145 for (
const auto& it : msgs_out)
148 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message " << ++i <<
" out:\n" << it->DebugString() << std::endl;
149 assert((*in_it)->SerializeAsString() == it->SerializeAsString());
154 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 ...
static GoogleProtobufMessagePointer new_protobuf_message(const std::string &protobuf_type_name, bool user_pool_first=false)
Create a new (empty) Google Protobuf message of a given type by name.
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...