27#include "../../codec.h"
32using dccl::operator<<;
39void decode(
const std::string& bytes);
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<GobyMessage1>();
53 codec.load<GobyMessage2>();
54 codec.load<GobyMessage3>();
56 codec.info<GobyMessage1>(&dccl::dlog);
57 codec.info<GobyMessage2>(&dccl::dlog);
58 codec.info<GobyMessage3>(&dccl::dlog);
60 msg_in1.set_int32_val(1);
61 msg_in2.set_bool_val(
false);
62 msg_in3.set_string_val(
"string1");
64 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
65 std::string bytes1, bytes2, bytes3;
66 codec.encode(&bytes1, msg_in1);
67 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes for GobyMessage1 (hex): " <<
dccl::hex_encode(bytes1) << std::endl;
68 codec.encode(&bytes2, msg_in2);
69 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes for GobyMessage2 (hex): " <<
dccl::hex_encode(bytes2) << std::endl;
70 codec.encode(&bytes3, msg_in3);
71 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes for GobyMessage3 (hex): " <<
dccl::hex_encode(bytes3) << std::endl;
73 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
80 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
83void decode(
const std::string& bytes)
85 unsigned dccl_id = codec.id(bytes);
87 if (dccl_id == codec.id<GobyMessage1>())
89 GobyMessage1 msg_out1;
90 codec.decode(bytes, &msg_out1);
92 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Got..." << msg_out1 << std::endl;
93 assert(msg_out1.SerializeAsString() == msg_in1.SerializeAsString());
95 else if (dccl_id == codec.id<GobyMessage2>())
97 GobyMessage2 msg_out2;
98 codec.decode(bytes, &msg_out2);
100 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Got..." << msg_out2 << std::endl;
101 assert(msg_out2.SerializeAsString() == msg_in2.SerializeAsString());
103 else if (dccl_id == codec.id<GobyMessage3>())
105 GobyMessage3 msg_out3;
106 codec.decode(bytes, &msg_out3);
108 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Got..." << msg_out3 << std::endl;
109 assert(msg_out3.SerializeAsString() == msg_in3.SerializeAsString());
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...