29#include "../../native_protobuf/dccl_native_protobuf.h"
31#include "../../binary.h"
32#include "../../codec.h"
41int main(
int argc,
char* argv[])
44 for (
int i = 1; i < argc; ++i)
46 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
50 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
52 codec.load_library(DCCL_NATIVE_PROTOBUF_NAME);
56 msg_in.set_double_oneof1(10.56);
57 msg_in.mutable_msg_oneof2()->set_val(100.123);
59 codec.load(msg_in.GetDescriptor());
60 codec.info(msg_in.GetDescriptor());
62 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
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;
69 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << codec.max_size(msg_in.GetDescriptor()) << std::endl;
72 codec.decode(bytes, &msg_out);
74 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
75 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
81 msg_in.set_non_default_double(1200.56);
82 msg_in.mutable_msg_oneof2()->set_val(100.123);
84 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
85 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
87 codec.encode(&bytes, msg_in);
88 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
90 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
91 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << codec.max_size(msg_in.GetDescriptor()) << std::endl;
94 codec.decode(bytes, &msg_out);
96 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
97 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
103 InvalidTestMsg msg_in;
104 msg_in.set_double_oneof1(10.56);
105 msg_in.mutable_msg_oneof2()->set_val(100.123);
107 codec.load(msg_in.GetDescriptor());
108 codec.info(msg_in.GetDescriptor());
115 "Oneof field used in header - oneof fields cannot be encoded in the header.") ==
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...