28 #include "../../native_protobuf/dccl_native_protobuf.h"
29 #include <google/protobuf/descriptor.pb.h>
31 #include "../../binary.h"
32 #include "../../codec.h"
38 int main(
int ,
char* [])
40 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
41 codec.load<TestMsg>();
42 codec.info<TestMsg>();
56 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
57 std::cout <<
"Try encode..." << std::endl;
59 codec.encode(&bytes, msg_in);
60 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
62 std::cout <<
"Try decode..." << std::endl;
63 std::cout << codec.max_size(msg_in.GetDescriptor()) << std::endl;
66 codec.decode(bytes, &msg_out);
68 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
69 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
88 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
89 std::cout <<
"Try encode..." << std::endl;
91 codec.encode(&bytes, msg_in);
92 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
94 std::cout <<
"Try decode..." << std::endl;
95 std::cout << codec.max_size(msg_in.GetDescriptor()) << std::endl;
98 codec.decode(bytes, &msg_out);
100 msg_in.mutable_a()->RemoveLast();
102 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
103 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
118 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
119 std::cout <<
"Try encode..." << std::endl;
121 codec.encode(&bytes, msg_in);
122 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
124 std::cout <<
"Try decode..." << std::endl;
125 std::cout << codec.max_size(msg_in.GetDescriptor()) << std::endl;
128 codec.decode(bytes, &msg_out);
130 auto bmin = dccl::test::TestMsg::descriptor()
131 ->FindFieldByName(
"b")
133 .GetExtension(dccl::field)
138 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
139 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
145 codec.load<InvalidTestMsgMissingMaxRepeat>();
156 codec.load<InvalidTestMsgMaxRepeatLessThanOne>();
167 codec.load<InvalidTestMsgMaxRepeatLessThanMinRepeat>();
175 std::cout <<
"All tests passed." << std::endl;