27#include "../../codec.h" 
   32using dccl::operator<<;
 
   39void decode(
const std::string& bytes);
 
   41int main(
int , 
char*  [])
 
   43    dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
 
   45    codec.load<GobyMessage1>();
 
   46    codec.load<GobyMessage2>();
 
   47    codec.load<GobyMessage3>();
 
   49    codec.info<GobyMessage1>(&dccl::dlog);
 
   50    codec.info<GobyMessage2>(&dccl::dlog);
 
   51    codec.info<GobyMessage3>(&dccl::dlog);
 
   53    msg_in1.set_int32_val(1);
 
   54    msg_in2.set_bool_val(
false);
 
   55    msg_in3.set_string_val(
"string1");
 
   57    std::cout << 
"Try encode..." << std::endl;
 
   58    std::string bytes1, bytes2, bytes3;
 
   59    codec.encode(&bytes1, msg_in1);
 
   60    std::cout << 
"... got bytes for GobyMessage1 (hex): " << 
dccl::hex_encode(bytes1) << std::endl;
 
   61    codec.encode(&bytes2, msg_in2);
 
   62    std::cout << 
"... got bytes for GobyMessage2 (hex): " << 
dccl::hex_encode(bytes2) << std::endl;
 
   63    codec.encode(&bytes3, msg_in3);
 
   64    std::cout << 
"... got bytes for GobyMessage3 (hex): " << 
dccl::hex_encode(bytes3) << std::endl;
 
   66    std::cout << 
"Try decode..." << std::endl;
 
   73    std::cout << 
"all tests passed" << std::endl;
 
   76void decode(
const std::string& bytes)
 
   78    unsigned dccl_id = codec.id(bytes);
 
   80    if (dccl_id == codec.id<GobyMessage1>())
 
   82        GobyMessage1 msg_out1;
 
   83        codec.decode(bytes, &msg_out1);
 
   85        std::cout << 
"Got..." << msg_out1 << std::endl;
 
   86        assert(msg_out1.SerializeAsString() == msg_in1.SerializeAsString());
 
   88    else if (dccl_id == codec.id<GobyMessage2>())
 
   90        GobyMessage2 msg_out2;
 
   91        codec.decode(bytes, &msg_out2);
 
   93        std::cout << 
"Got..." << msg_out2 << std::endl;
 
   94        assert(msg_out2.SerializeAsString() == msg_in2.SerializeAsString());
 
   96    else if (dccl_id == codec.id<GobyMessage3>())
 
   98        GobyMessage3 msg_out3;
 
   99        codec.decode(bytes, &msg_out3);
 
  101        std::cout << 
"Got..." << msg_out3 << std::endl;
 
  102        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 ...
 
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...