25 #include <google/protobuf/descriptor.pb.h>
27 #include "../../binary.h"
28 #include "../../codec.h"
29 #include "../../codecs3/field_codec_default.h"
33 void decode_check(
const std::string& encoded);
37 TestMsgUnpack msg_unpack;
39 int main(
int ,
char* [])
41 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
43 msg_pack.set_five_bit_padding(0);
44 msg_pack.set_value(ENUM2_H);
45 msg_unpack.set_value(ENUM2_H);
47 codec.info(msg_pack.GetDescriptor());
48 codec.info(msg_unpack.GetDescriptor());
50 codec.load(msg_pack.GetDescriptor());
51 codec.load(msg_unpack.GetDescriptor());
53 std::cout <<
"Try encode..." << std::endl;
54 std::string bytes_pack;
55 codec.encode(&bytes_pack, msg_pack);
56 std::cout <<
"... got packed bytes (hex): " <<
dccl::hex_encode(bytes_pack) << std::endl;
58 std::string bytes_unpack;
59 codec.encode(&bytes_unpack, msg_unpack);
60 std::cout <<
"... got unpacked bytes (hex): " <<
dccl::hex_encode(bytes_unpack) << std::endl;
62 std::cout <<
"Try decode..." << std::endl;
63 TestMsgPack msg_pack_out;
64 TestMsgUnpack msg_unpack_out;
66 codec.decode(bytes_pack, &msg_pack_out);
67 codec.decode(bytes_unpack, &msg_unpack_out);
68 assert(msg_pack_out.SerializeAsString() == msg_pack.SerializeAsString());
69 assert(msg_unpack_out.SerializeAsString() == msg_unpack.SerializeAsString());
70 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 ...
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...