49 TestMessage source = TestMessage_init_zero;
50 source.values.push_back(5);
51 source.values.push_back(4);
52 source.values.push_back(3);
53 source.values.push_back(2);
54 source.values.push_back(1);
57 std::vector<uint8_t> serialized;
60 serialized.resize(
size);
63 if (!
pb_encode(&outstream, TestMessage_fields, &source)) {
69 TestMessage destination;
71 if (!
pb_decode(&instream, TestMessage_fields, &destination)) {
75 if (source.values != destination.values) {
76 fprintf(
stderr,
"Result does not match\n");
77 fprintf(
stderr,
"source(%d): ", (
int)source.values.size());
78 for (std::vector<int>::iterator i = source.values.begin(); i != source.values.end(); ++i)
80 fprintf(
stderr,
"%d, ", *i);
82 fprintf(
stderr,
"\nencoded(%d): ", (
int)serialized.size());
83 for (
unsigned i = 0; i != std::min(serialized.size(), outstream.bytes_written); ++i) {
84 fprintf(
stderr,
"0x%02x ", serialized[i]);
86 fprintf(
stderr,
"\ndestination(%d): ", (
int)destination.values.size());
87 for (std::vector<int>::iterator i = destination.values.begin(); i != destination.values.end(); ++i)
89 fprintf(
stderr,
"%d, ", *i);