26#include <google/protobuf/descriptor.pb.h>
28#include "../../binary.h"
29#include "../../codec.h"
30#include "../../codecs3/field_codec_default.h"
34void decode_check(
const std::string& encoded);
38TestMsgUnpack msg_unpack;
40int main(
int ,
char* [])
42 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
44 msg_pack.set_five_bit_padding(0);
45 msg_pack.set_value(ENUM2_H);
46 msg_unpack.set_value(ENUM2_H);
48 codec.info(msg_pack.GetDescriptor());
49 codec.info(msg_unpack.GetDescriptor());
51 codec.load(msg_pack.GetDescriptor());
52 codec.load(msg_unpack.GetDescriptor());
54 std::cout <<
"Try encode..." << std::endl;
55 std::string bytes_pack;
56 codec.encode(&bytes_pack, msg_pack);
57 std::cout <<
"... got packed bytes (hex): " <<
dccl::hex_encode(bytes_pack) << std::endl;
59 std::string bytes_unpack;
60 codec.encode(&bytes_unpack, msg_unpack);
61 std::cout <<
"... got unpacked bytes (hex): " <<
dccl::hex_encode(bytes_unpack) << std::endl;
63 std::cout <<
"Try decode..." << std::endl;
64 TestMsgPack msg_pack_out;
65 TestMsgUnpack msg_unpack_out;
67 codec.decode(bytes_pack, &msg_pack_out);
68 codec.decode(bytes_unpack, &msg_unpack_out);
69 assert(msg_pack_out.SerializeAsString() == msg_pack.SerializeAsString());
70 assert(msg_unpack_out.SerializeAsString() == msg_unpack.SerializeAsString());
71 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...