29 #include "../../native_protobuf/dccl_native_protobuf.h"
30 #include <google/protobuf/descriptor.pb.h>
32 #include "../../binary.h"
33 #include "../../codec.h"
42 int main(
int ,
char* [])
44 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
46 codec.load_library(DCCL_NATIVE_PROTOBUF_NAME);
50 msg_in.set_double_oneof1(10.56);
51 msg_in.mutable_msg_oneof2()->set_val(100.123);
53 codec.load(msg_in.GetDescriptor());
54 codec.info(msg_in.GetDescriptor());
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());
75 msg_in.set_non_default_double(1200.56);
76 msg_in.mutable_msg_oneof2()->set_val(100.123);
78 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
79 std::cout <<
"Try encode..." << std::endl;
81 codec.encode(&bytes, msg_in);
82 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
84 std::cout <<
"Try decode..." << std::endl;
85 std::cout << codec.max_size(msg_in.GetDescriptor()) << std::endl;
88 codec.decode(bytes, &msg_out);
90 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
91 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
97 InvalidTestMsg msg_in;
98 msg_in.set_double_oneof1(10.56);
99 msg_in.mutable_msg_oneof2()->set_val(100.123);
101 codec.load(msg_in.GetDescriptor());
102 codec.info(msg_in.GetDescriptor());
109 "Oneof field used in header - oneof fields cannot be encoded in the header.") ==