This commit is contained in:
iranl
2025-06-25 22:52:12 +02:00
parent 5fe5614686
commit 6c74d62531
519 changed files with 191600 additions and 5 deletions

View File

@@ -0,0 +1,38 @@
There are two tests.
"test-generated-code" is a simple test that can easily be adapted.
"test-generated-code2" is a comprehensive test.
--
If you have a quick problem, hack at "test-generated-code";
but i don't want that file to be too hard to navigate,
so you must eventually add a test to "test-generated-code2".
I appreciate additional test cases!
Please submit them as issues in the tracking system, or email me.
--
Here are the files involved in each test:
test.proto Protobuf declarations for the simple test.
test.pb-c.c Protobuf-C generated code based on test.proto
test.pb-c.h Protobuf-C generated code based on test.proto
test-full.proto Protobuf declarations for the exhaustive test.
test-full.pb-c.c Protobuf-C generated code based on test-full.proto
test-full.pb-c.h Protobuf-C generated code based on test-full.proto
test-full.pb.cc Protobuf (C++) generated code based on test-full.proto
test-full.pb.h Protobuf (C++) generated code based on test-full.proto
generated-code/
test-generated-code.c Actual test code.
test-generated-code Test executable.
generated-code2/
cxx-generate-packed-data.cc C++ code to generated data to compare with C.
cxx-generate-packed-data Program whichs generates data (using C++ api)
test-full-cxx-output.inc Output of cxx-generate-packed-data.
test-generated-code2.c Actual test code.
test-generated-code2 Test executable.

View File

@@ -0,0 +1,71 @@
#ifdef PROTO3
#include "t/test-proto3.pb-c.h"
#else
#include "t/test.pb-c.h"
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
Foo__Person__PhoneNumber__Comment comment = FOO__PERSON__PHONE_NUMBER__COMMENT__INIT;
Foo__Person__PhoneNumber phone = FOO__PERSON__PHONE_NUMBER__INIT;
Foo__Person__PhoneNumber *phone_numbers[1];
Foo__Person person = FOO__PERSON__INIT;
Foo__Person *person2;
unsigned char simple_pad[8];
size_t size, size2;
unsigned char *packed;
ProtobufCBufferSimple bs = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_pad);
comment.comment = "protobuf-c guy";
phone.number = "1234";
#ifndef PROTO3
phone.has_type = 1;
#endif
phone.type = FOO__PERSON__PHONE_TYPE__WORK;
phone.comment = &comment;
phone_numbers[0] = &phone;
person.name = "dave b";
person.id = 42;
person.n_phone = 1;
person.phone = phone_numbers;
size = foo__person__get_packed_size (&person);
packed = malloc (size);
assert (packed);
size2 = foo__person__pack (&person, packed);
assert (size == size2);
foo__person__pack_to_buffer (&person, &bs.base);
assert (bs.len == size);
assert (memcmp (bs.data, packed, size) == 0);
PROTOBUF_C_BUFFER_SIMPLE_CLEAR (&bs);
person2 = foo__person__unpack (NULL, size, packed);
assert (person2 != NULL);
assert (person2->id == 42);
#ifndef PROTO3
assert (person2->email == NULL);
#else
assert (strcmp (person2->email, "") == 0);
#endif
assert (strcmp (person2->name, "dave b") == 0);
assert (person2->n_phone == 1);
assert (strcmp (person2->phone[0]->number, "1234") == 0);
assert (person2->phone[0]->type == FOO__PERSON__PHONE_TYPE__WORK);
assert (strcmp (person2->phone[0]->comment->comment, "protobuf-c guy") == 0);
foo__person__free_unpacked (person2, NULL);
free (packed);
printf ("test succeeded.\n");
return 0;
}

View File

@@ -0,0 +1,62 @@
/* data included from the c++ packed-data generator,
and from the c test code. */
#define THOUSAND 1000
#define MILLION 1000000
#define BILLION 1000000000LL
#define TRILLION 1000000000000LL
#define QUADRILLION 1000000000000000LL
#define QUINTILLION 1000000000000000000LL
int32_t int32_arr0[2] = { -1, 1 };
int32_t int32_arr1[5] = { 42, 666, -1123123, 0, 47 };
int32_t int32_arr_min_max[2] = { INT32_MIN, INT32_MAX };
uint32_t uint32_roundnumbers[4] = { BILLION, MILLION, 1, 0 };
uint32_t uint32_0_max[2] = { 0, UINT32_MAX };
int64_t int64_roundnumbers[15] = { -QUINTILLION, -QUADRILLION, -TRILLION,
-BILLION, -MILLION, -THOUSAND,
1,
THOUSAND, MILLION, BILLION,
TRILLION, QUADRILLION, QUINTILLION };
int64_t int64_min_max[2] = { INT64_MIN, INT64_MAX };
uint64_t uint64_roundnumbers[9] = { 1,
THOUSAND, MILLION, BILLION,
TRILLION, QUADRILLION, QUINTILLION };
uint64_t uint64_0_1_max[3] = { 0, 1, UINT64_MAX };
uint64_t uint64_random[] = {0,
666,
4200000000ULL,
16ULL * (uint64_t) QUINTILLION + 33 };
#define FLOATING_POINT_RANDOM \
-1000.0, -100.0, -42.0, 0, 666, 131313
float float_random[] = { FLOATING_POINT_RANDOM };
double double_random[] = { FLOATING_POINT_RANDOM };
protobuf_c_boolean boolean_0[] = {0 };
protobuf_c_boolean boolean_1[] = {1 };
protobuf_c_boolean boolean_random[] = {0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,1,1,0,1,1,0 };
TEST_ENUM_SMALL_TYPE_NAME enum_small_0[] = { TEST_ENUM_SMALL(VALUE) };
TEST_ENUM_SMALL_TYPE_NAME enum_small_1[] = { TEST_ENUM_SMALL(OTHER_VALUE) };
#define T(v) (TEST_ENUM_SMALL_TYPE_NAME)(v)
TEST_ENUM_SMALL_TYPE_NAME enum_small_random[] = {T(0),T(1),T(1),T(0),T(0),T(1),T(1),T(1),T(0),T(0),T(0),T(0),T(0),T(1),T(1),T(1),T(1),T(1),T(1),T(0),T(1),T(1),T(0),T(1),T(1),T(0) };
#undef T
#define T(v) (TEST_ENUM_TYPE_NAME)(v)
TEST_ENUM_TYPE_NAME enum_0[] = { T(0) };
TEST_ENUM_TYPE_NAME enum_1[] = { T(1) };
TEST_ENUM_TYPE_NAME enum_random[] = {
T(0), T(268435455), T(127), T(16384), T(16383),
T(2097152), T(2097151), T(128), T(268435456),
T(0), T(2097152), T(268435455), T(127), T(16383), T(16384) };
#undef T
const char *repeated_strings_0[] = { "onestring" };
const char *repeated_strings_1[] = { "two", "string" };
const char *repeated_strings_2[] = { "many", "tiny", "little", "strings", "should", "be", "handled" };
const char *repeated_strings_3[] = { "one very long strings XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" };

View File

@@ -0,0 +1 @@
issue204

View File

@@ -0,0 +1,48 @@
#include <stdlib.h>
#include "t/issue251/issue251.pb-c.h"
int main(void)
{
TwoOneofs msg = TWO_ONEOFS__INIT;
const ProtobufCFieldDescriptor *field;
unsigned off1, off2, off_name;
field = protobuf_c_message_descriptor_get_field_by_name(
msg.base.descriptor,
"first_oneof");
assert (field);
off_name = field->offset;
field = protobuf_c_message_descriptor_get_field(
msg.base.descriptor,
10);
assert (field);
off1 = field->offset;
field = protobuf_c_message_descriptor_get_field(
msg.base.descriptor,
11);
assert (field);
off2 = field->offset;
assert (off_name == off1);
assert (off1 == off2);
field = protobuf_c_message_descriptor_get_field_by_name(
msg.base.descriptor,
"second_oneof");
assert (field);
off_name = field->offset;
field = protobuf_c_message_descriptor_get_field(
msg.base.descriptor,
20);
assert (field);
off1 = field->offset;
field = protobuf_c_message_descriptor_get_field(
msg.base.descriptor,
21);
assert (field);
off2 = field->offset;
assert (off_name == off1);
assert (off1 == off2);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,15 @@
import "protobuf-c/protobuf-c.proto";
option (pb_c_file).use_oneof_field_name = true;
message two_oneofs {
oneof first_oneof {
bool a = 10;
bool b = 11;
}
oneof second_oneof {
bool c = 20;
bool d = 21;
}
}

View File

@@ -0,0 +1 @@
issue220

View File

@@ -0,0 +1,13 @@
#include <assert.h>
#include <stdlib.h>
#include <limits.h>
#include "t/issue220/issue220.pb-c.h"
int main(void)
{
assert(_MESSAGE_TYPE1__FLAG_IS_INT_SIZE == INT_MAX);
assert(_MESSAGE_TYPE2__ANOTHER_FLAG_IS_INT_SIZE == INT_MAX);
assert(_TOP_LEVEL__SUBMESSAGES__CASE_IS_INT_SIZE == INT_MAX);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,20 @@
message TopLevel {
oneof submessages {
MessageType1 type1 = 1;
MessageType2 type2 = 2;
}
}
message MessageType1 {
enum Flag {
OK = 1;
}
optional Flag flag = 1;
}
message MessageType2 {
enum AnotherFlag {
OK = 1;
}
optional AnotherFlag flag = 1;
}

View File

@@ -0,0 +1 @@
issue251

View File

@@ -0,0 +1,12 @@
#include <stdlib.h>
#include "t/issue251/issue251.pb-c.h"
int main(void)
{
/*
* The problem in #251 caused invalid code to be generated in the
* .pb-c.h file, so there's nothing for us to do here.
*/
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,11 @@
message two_oneofs {
oneof first_oneof {
bool a = 10;
bool b = 11;
}
oneof second_oneof {
bool c = 20;
bool d = 21;
}
}

View File

@@ -0,0 +1 @@
issue330

View File

@@ -0,0 +1,25 @@
#include <stdlib.h>
#include <string.h>
#include "t/issue330/issue330.pb-c.h"
int main(void)
{
/* Output of $ echo acl_id: 2 acl_id: 3 | protoc issue330.proto \
* --encode=pbr_route | xxd -i: 0x52, 0x02, 0x02, 0x03
*/
uint8_t protoc[] = {0x52, 0x02, 0x02, 0x03};
PbrRoute msg = PBR_ROUTE__INIT;
int ids[] = {2, 3};
uint8_t buf[16] = {0};
size_t sz = 0;
msg.n_acl_id = 2;
msg.acl_id = ids;
sz = pbr_route__pack(&msg, buf);
assert (sz == sizeof protoc);
assert (memcmp (protoc, buf, sz) == 0);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,5 @@
syntax = "proto3";
message pbr_route {
repeated int32 acl_id = 10;
}

View File

@@ -0,0 +1 @@
issue375

View File

@@ -0,0 +1,24 @@
#include <assert.h>
#include <stdlib.h>
#include "t/issue375/issue375.pb-c.h"
int main(void) {
// This buffer represents some serialized bytes where we have a length
// delimiter of 2^32 - 1 bytes for a particular repeated int32 field.
// We want to make sure that parsing a length delimiter this large does
// not cause a problematic integer overflow.
uint8_t buffer[] = {
// Field 1 with wire type 2 (length-delimited)
0x0a,
// Varint length delimiter: 2^32 - 1
0xff, 0xff, 0xff, 0xff, 0x0f,
};
// The parser should detect that this message is malformed and return
// null.
Issue375__TestMessage* m =
issue375__test_message__unpack(NULL, sizeof(buffer), buffer);
assert(m == NULL);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,7 @@
syntax = "proto2";
package issue375;
message TestMessage {
repeated int32 nums = 1;
}

View File

@@ -0,0 +1,12 @@
syntax = "proto3";
message EnumIntTest {
enum Label {
LABEL_1 = 0;
LABEL_2 = 1;
}
oneof label {
Label label_label = 123;
uint64 label_uint64 = 124;
}
}

View File

@@ -0,0 +1 @@
issue440

View File

@@ -0,0 +1,30 @@
#include <stdlib.h>
#include <string.h>
#include "t/issue440/issue440.pb-c.h"
int main(void)
{
/* Output of $ echo "int: 1 int: -142342 int: 0 int: 423423222" | \
* protoc issue440.proto --encode=Int | xxd -i:
* 0x0a, 0x11, 0x01, 0xfa, 0xa7, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
* 0x01, 0x00, 0xf6, 0xd9, 0xf3, 0xc9, 0x01
*
* Output of $ echo "int: 1 int: -142342 int: 0 int: 423423222" | \
* protoc issue440.proto --encode=Int | protoc issue440.proto \
* --decode=Boolean: boolean: true boolean: true boolean: false boolean: true
*/
uint8_t protoc[] = {0x0a, 0x11, 0x01, 0xfa, 0xa7, 0xf7, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf6, 0xd9, 0xf3, 0xc9,
0x01};
Boolean *msg = boolean__unpack (NULL, sizeof protoc, protoc);
assert(msg);
assert(msg->n_boolean == 4);
assert(msg->boolean[0] == 1);
assert(msg->boolean[1] == 1);
assert(msg->boolean[2] == 0);
assert(msg->boolean[3] == 1);
boolean__free_unpacked (msg, NULL);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,9 @@
syntax = "proto3";
message Int {
repeated int32 int = 1;
}
message Boolean {
repeated bool boolean = 1;
}

View File

@@ -0,0 +1,423 @@
package foo;
import "protobuf-c/protobuf-c.proto";
option (pb_c_file).const_strings = true;
message SubMess {
required int32 test = 4;
optional int32 val1 = 6;
optional int32 val2 = 7;
repeated int32 rep = 8;
message SubSubMess {
optional int32 val1 = 1 [default = 100];
repeated int32 rep = 4;
optional bytes bytes1 = 2 [default = "a \0 char"];
optional string str1 = 3 [default = "hello world\n"];
optional string str2 = 5 [default = "hello\0world\n",
(pb_c_field).string_as_bytes = true];
}
optional SubSubMess sub1 = 9;
optional SubSubMess sub2 = 10;
};
enum TestEnumSmall {
NEG_VALUE = -1;
VALUE = 0;
OTHER_VALUE = 1;
}
// these number are specifically chosen to test the
// boundaries of when an enum requires a certain number of bytes.
// e.g. 16383 requires 3 bytes; 16384 requires 4.
enum TestEnum {
VALUENEG123456 = -123456;
VALUENEG1 = -1;
VALUE0 = 0;
VALUE1 = 1;
VALUE127 = 127;
VALUE128 = 128;
VALUE16383 = 16383;
VALUE16384 = 16384;
VALUE2097151 = 2097151;
VALUE2097152 = 2097152;
VALUE268435455 = 268435455;
VALUE268435456 = 268435456;
}
enum TestEnumDupValues {
VALUE_A = 42;
VALUE_B = 42;
VALUE_C = 42;
VALUE_D = 666;
VALUE_E = 666;
VALUE_F = 1000;
VALUE_AA = 1000;
VALUE_BB = 1001;
option allow_alias = true;
}
message TestFieldNo15 { // should use 1 byte header
required string test = 15;
}
message TestFieldNo16 { // requires 2 byte header
required string test = 16;
}
message TestFieldNo2047 { // should use 2 byte header
required string test = 2047;
}
message TestFieldNo2048 { // requires 3 byte header
required string test = 2048;
}
message TestFieldNo262143 { // should use 3 byte header
required string test = 262143;
}
message TestFieldNo262144 { // requires 4 byte header
required string test = 262144;
}
message TestFieldNo33554431 { // should use 4 byte header
required string test = 33554431;
}
message TestFieldNo33554432 { // requires 5 byte header
required string test = 33554432;
}
message TestMess {
repeated int32 test_int32 = 1;
repeated sint32 test_sint32 = 2;
repeated sfixed32 test_sfixed32 = 3;
repeated int64 test_int64 = 4;
repeated sint64 test_sint64 = 5;
repeated sfixed64 test_sfixed64 = 6;
repeated uint32 test_uint32 = 7;
repeated fixed32 test_fixed32 = 8;
repeated uint64 test_uint64 = 9;
repeated fixed64 test_fixed64 = 10;
repeated float test_float = 11;
repeated double test_double = 12;
repeated bool test_boolean = 13;
repeated TestEnumSmall test_enum_small = 14;
repeated TestEnum test_enum = 15;
repeated string test_string = 16;
repeated bytes test_bytes = 17;
repeated SubMess test_message = 18;
}
message TestMessPacked {
repeated int32 test_int32 = 1 [packed=true];
repeated sint32 test_sint32 = 2 [packed=true];
repeated sfixed32 test_sfixed32 = 3 [packed=true];
repeated int64 test_int64 = 4 [packed=true];
repeated sint64 test_sint64 = 5 [packed=true];
repeated sfixed64 test_sfixed64 = 6 [packed=true];
repeated uint32 test_uint32 = 7 [packed=true];
repeated fixed32 test_fixed32 = 8 [packed=true];
repeated uint64 test_uint64 = 9 [packed=true];
repeated fixed64 test_fixed64 = 10 [packed=true];
repeated float test_float = 11 [packed=true];
repeated double test_double = 12 [packed=true];
repeated bool test_boolean = 13 [packed=true];
repeated TestEnumSmall test_enum_small = 14 [packed=true];
repeated TestEnum test_enum = 15 [packed=true];
}
message TestMessOptional {
option (pb_c_msg).gen_pack_helpers = false;
option (pb_c_msg).gen_init_helpers = false;
optional int32 test_int32 = 1;
optional sint32 test_sint32 = 2;
optional sfixed32 test_sfixed32 = 3;
optional int64 test_int64 = 4;
optional sint64 test_sint64 = 5;
optional sfixed64 test_sfixed64 = 6;
optional uint32 test_uint32 = 7;
optional fixed32 test_fixed32 = 8;
optional uint64 test_uint64 = 9;
optional fixed64 test_fixed64 = 10;
optional float test_float = 11;
optional double test_double = 12;
optional bool test_boolean = 13;
optional TestEnumSmall test_enum_small = 14;
optional TestEnum test_enum = 15;
optional string test_string = 16;
optional bytes test_bytes = 17;
optional SubMess test_message = 18;
}
message TestMessOneof {
oneof test_oneof {
int32 test_int32 = 1;
sint32 test_sint32 = 2;
sfixed32 test_sfixed32 = 3;
int64 test_int64 = 4;
sint64 test_sint64 = 5;
sfixed64 test_sfixed64 = 6;
uint32 test_uint32 = 7;
fixed32 test_fixed32 = 8;
uint64 test_uint64 = 9;
fixed64 test_fixed64 = 10;
float test_float = 11;
double test_double = 12;
bool test_boolean = 13;
TestEnumSmall test_enum_small = 14;
TestEnum test_enum = 15;
string test_string = 16;
bytes test_bytes = 17;
SubMess test_message = 18;
}
optional int32 opt_int = 19;
}
message TestMessRequiredInt32 {
required int32 test = 42;
}
message TestMessRequiredSInt32 {
required sint32 test = 43;
}
message TestMessRequiredSFixed32 {
required sfixed32 test = 100;
}
message TestMessRequiredInt64 {
required int64 test = 1;
}
message TestMessRequiredSInt64 {
required sint64 test = 11;
}
message TestMessRequiredSFixed64 {
required sfixed64 test = 12;
}
message TestMessRequiredUInt32 {
required uint32 test = 1;
}
message TestMessRequiredFixed32 {
required fixed32 test = 1;
}
message TestMessRequiredUInt64 {
required uint64 test = 1;
}
message TestMessRequiredFixed64 {
required fixed64 test = 1;
}
message TestMessRequiredFloat {
required float test = 1;
}
message TestMessRequiredDouble {
required double test = 1;
}
message TestMessRequiredBool {
required bool test = 1;
}
message TestMessRequiredEnum {
required TestEnum test = 1;
}
message TestMessRequiredEnumSmall {
required TestEnumSmall test = 1;
}
message TestMessRequiredString {
required string test = 1;
}
message TestMessRequiredBytes {
required bytes test = 1;
}
message TestMessRequiredMessage {
required SubMess test = 1;
}
message EmptyMess {
}
message DefaultRequiredValues {
required int32 v_int32 = 1 [default = -42];
required uint32 v_uint32 = 2 [default = 666];
required int32 v_int64 = 3 [default = 100000];
required uint32 v_uint64 = 4 [default = 100001];
required float v_float = 5 [default = 2.5];
required double v_double = 6 [default = 4.5];
required string v_string = 7 [default = "hi mom\n"];
required bytes v_bytes = 8 [default = "a \0 character"];
}
message DefaultOptionalValues {
optional int32 v_int32 = 1 [default = -42];
optional uint32 v_uint32 = 2 [default = 666];
optional int32 v_int64 = 3 [default = 100000];
optional uint32 v_uint64 = 4 [default = 100001];
optional float v_float = 5 [default = 2.5];
optional double v_double = 6 [default = 4.5];
optional string v_string = 7 [default = "hi mom\n"];
optional bytes v_bytes = 8 [default = "a \0 character"];
}
message LowerCase {
enum CaseEnum {
UPPER = 1;
lower = 2;
}
optional CaseEnum value = 1 [default = lower];
}
message AllocValues {
optional bytes o_bytes = 1;
repeated string r_string = 2;
required string a_string = 3;
required bytes a_bytes = 4;
required DefaultRequiredValues a_mess = 5;
}
message TestRequiredFieldsBitmap {
required string field1 = 1;
optional string field2 = 2;
optional string field3 = 3;
optional string field4 = 4;
optional string field5 = 5;
optional string field6 = 6;
optional string field7 = 7;
optional string field8 = 8;
optional string field9 = 9;
optional string field10 = 10;
optional string field11 = 11;
optional string field12 = 12;
optional string field13 = 13;
optional string field14 = 14;
optional string field15 = 15;
optional string field16 = 16;
optional string field17 = 17;
optional string field18 = 18;
optional string field19 = 19;
optional string field20 = 20;
optional string field21 = 21;
optional string field22 = 22;
optional string field23 = 23;
optional string field24 = 24;
optional string field25 = 25;
optional string field26 = 26;
optional string field27 = 27;
optional string field28 = 28;
optional string field29 = 29;
optional string field30 = 30;
optional string field31 = 31;
optional string field32 = 32;
optional string field33 = 33;
optional string field34 = 34;
optional string field35 = 35;
optional string field36 = 36;
optional string field37 = 37;
optional string field38 = 38;
optional string field39 = 39;
optional string field40 = 40;
optional string field41 = 41;
optional string field42 = 42;
optional string field43 = 43;
optional string field44 = 44;
optional string field45 = 45;
optional string field46 = 46;
optional string field47 = 47;
optional string field48 = 48;
optional string field49 = 49;
optional string field50 = 50;
optional string field51 = 51;
optional string field52 = 52;
optional string field53 = 53;
optional string field54 = 54;
optional string field55 = 55;
optional string field56 = 56;
optional string field57 = 57;
optional string field58 = 58;
optional string field59 = 59;
optional string field60 = 60;
optional string field61 = 61;
optional string field62 = 62;
optional string field63 = 63;
optional string field64 = 64;
optional string field65 = 65;
optional string field66 = 66;
optional string field67 = 67;
optional string field68 = 68;
optional string field69 = 69;
optional string field70 = 70;
optional string field71 = 71;
optional string field72 = 72;
optional string field73 = 73;
optional string field74 = 74;
optional string field75 = 75;
optional string field76 = 76;
optional string field77 = 77;
optional string field78 = 78;
optional string field79 = 79;
optional string field80 = 80;
optional string field81 = 81;
optional string field82 = 82;
optional string field83 = 83;
optional string field84 = 84;
optional string field85 = 85;
optional string field86 = 86;
optional string field87 = 87;
optional string field88 = 88;
optional string field89 = 89;
optional string field90 = 90;
optional string field91 = 91;
optional string field92 = 92;
optional string field93 = 93;
optional string field94 = 94;
optional string field95 = 95;
optional string field96 = 96;
optional string field97 = 97;
optional string field98 = 98;
optional string field99 = 99;
optional string field100 = 100;
optional string field101 = 101;
optional string field102 = 102;
optional string field103 = 103;
optional string field104 = 104;
optional string field105 = 105;
optional string field106 = 106;
optional string field107 = 107;
optional string field108 = 108;
optional string field109 = 109;
optional string field110 = 110;
optional string field111 = 111;
optional string field112 = 112;
optional string field113 = 113;
optional string field114 = 114;
optional string field115 = 115;
optional string field116 = 116;
optional string field117 = 117;
optional string field118 = 118;
optional string field119 = 119;
optional string field120 = 120;
optional string field121 = 121;
optional string field122 = 122;
optional string field123 = 123;
optional string field124 = 124;
optional string field125 = 125;
optional string field126 = 126;
optional string field127 = 127;
optional string field128 = 128;
required string field129 = 129;
}
message TestFieldFlags {
optional int32 no_flags1 = 1;
required int32 no_flags2 = 2;
repeated int32 no_flags3 = 3;
repeated int32 packed = 4 [packed=true];
repeated int32 packed_deprecated = 5 [packed=true, deprecated=true];
repeated int32 deprecated = 6 [deprecated=true];
}
message TestMessageCheck {
message SubMessage {
required string str = 1;
}
required SubMessage required_msg = 1;
repeated SubMessage repeated_msg = 2;
optional SubMessage optional_msg = 3;
required string required_string = 4;
repeated string repeated_string = 5;
optional string optional_string = 6;
required bytes required_bytes = 7;
repeated bytes repeated_bytes = 8;
optional bytes optional_bytes = 9;
}
message TestMessSubMess {
required TestMess rep_mess = 1;
required TestMessOptional opt_mess = 2;
required TestMessOneof oneof_mess = 3;
required SubMess req_mess = 4;
required DefaultOptionalValues def_mess = 5;
}

View File

@@ -0,0 +1,13 @@
package foo;
option optimize_for = CODE_SIZE;
enum TestEnumLite {
LITE = 0;
LITE1 = 1;
}
message TestMessLite {
required int32 field1 = 1;
required TestEnumLite field2 = 2;
}

View File

@@ -0,0 +1,40 @@
syntax = "proto3";
package foo;
message Person {
string name = 1;
int32 id = 2;
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
message Comment {
string comment = 1;
}
string number = 1;
PhoneType type = 2;
Comment comment = 3;
}
repeated PhoneNumber phone = 4;
}
message LookupResult
{
Person person = 1;
}
message Name {
string name = 1;
};
service DirLookup {
rpc ByName (Name) returns (LookupResult);
}

View File

@@ -0,0 +1,42 @@
package foo;
import "protobuf-c/protobuf-c.proto";
option (pb_c_file).c_package = "foo";
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
message Comment {
required string comment = 1;
}
required string number = 1;
optional PhoneType type = 2 [default = HOME];
optional Comment comment = 3;
}
repeated PhoneNumber phone = 4;
}
message LookupResult
{
optional Person person = 1;
}
message Name {
optional string name = 1;
};
service DirLookup {
rpc ByName (Name) returns (LookupResult);
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2014, The protobuf-c authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "protobuf-c.h"
int
main(int argc, char **argv)
{
printf("PACKAGE_VERSION = %s\n",
PACKAGE_VERSION);
printf("PROTOBUF_C_VERSION = %s\n",
PROTOBUF_C_VERSION);
printf("PROTOBUF_C_VERSION_NUMBER = %d\n",
PROTOBUF_C_VERSION_NUMBER);
printf("protobuf_c_version() = %s\n",
protobuf_c_version());
printf("protobuf_c_version_number() = %d\n",
protobuf_c_version_number());
assert(strcmp(PACKAGE_VERSION, PROTOBUF_C_VERSION) == 0);
assert(strcmp(PROTOBUF_C_VERSION, protobuf_c_version()) == 0);
assert(PROTOBUF_C_VERSION_NUMBER == protobuf_c_version_number());
return EXIT_SUCCESS;
}