26 #include <google/protobuf/descriptor.pb.h>
28 #include "../../binary.h"
29 #include "../../codec.h"
30 #include "../../codecs3/field_codec_default.h"
34 void decode_check(
const std::string& encoded);
38 TestMsgUnpack msg_unpack;
40 int 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;