• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3// https://developers.google.com/protocol-buffers/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9//     * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11//     * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15//     * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// Author: kenton@google.com (Kenton Varda)
32//  Based on original Protocol Buffers design by
33//  Sanjay Ghemawat, Jeff Dean, and others.
34//
35// A proto file we will use for unit testing.
36//
37// LINT: ALLOW_GROUPS, LEGACY_NAMES
38
39syntax = "proto2";
40
41// Some generic_services option(s) added automatically.
42// See:  http://go/proto2-generic-services-default
43option cc_generic_services = true;     // auto-added
44option java_generic_services = true;   // auto-added
45option py_generic_services = true;     // auto-added
46option cc_enable_arenas = true;
47
48import "google/protobuf/unittest_import.proto";
49
50// We don't put this in a package within proto2 because we need to make sure
51// that the generated code doesn't depend on being in the proto2 namespace.
52// In test_util.h we do "using namespace unittest = protobuf_unittest".
53package protobuf_unittest;
54
55// Protos optimized for SPEED use a strict superset of the generated code
56// of equivalent ones optimized for CODE_SIZE, so we should optimize all our
57// tests for speed unless explicitly testing code size optimization.
58option optimize_for = SPEED;
59
60option java_outer_classname = "UnittestProto";
61
62// This proto includes every type of field in both singular and repeated
63// forms.
64message TestAllTypes {
65  message NestedMessage {
66    // The field name "b" fails to compile in proto1 because it conflicts with
67    // a local variable named "b" in one of the generated methods.  Doh.
68    // This file needs to compile in proto1 to test backwards-compatibility.
69    optional int32 bb = 1;
70  }
71
72  enum NestedEnum {
73    FOO = 1;
74    BAR = 2;
75    BAZ = 3;
76    NEG = -1;  // Intentionally negative.
77  }
78
79  // Singular
80  optional    int32 optional_int32    =  1;
81  optional    int64 optional_int64    =  2;
82  optional   uint32 optional_uint32   =  3;
83  optional   uint64 optional_uint64   =  4;
84  optional   sint32 optional_sint32   =  5;
85  optional   sint64 optional_sint64   =  6;
86  optional  fixed32 optional_fixed32  =  7;
87  optional  fixed64 optional_fixed64  =  8;
88  optional sfixed32 optional_sfixed32 =  9;
89  optional sfixed64 optional_sfixed64 = 10;
90  optional    float optional_float    = 11;
91  optional   double optional_double   = 12;
92  optional     bool optional_bool     = 13;
93  optional   string optional_string   = 14;
94  optional    bytes optional_bytes    = 15;
95
96  optional group OptionalGroup = 16 {
97    optional int32 a = 17;
98  }
99
100  optional NestedMessage                        optional_nested_message  = 18;
101  optional ForeignMessage                       optional_foreign_message = 19;
102  optional protobuf_unittest_import.ImportMessage optional_import_message  = 20;
103
104  optional NestedEnum                           optional_nested_enum     = 21;
105  optional ForeignEnum                          optional_foreign_enum    = 22;
106  optional protobuf_unittest_import.ImportEnum    optional_import_enum     = 23;
107
108  optional string optional_string_piece = 24 [ctype=STRING_PIECE];
109  optional string optional_cord = 25 [ctype=CORD];
110
111  // Defined in unittest_import_public.proto
112  optional protobuf_unittest_import.PublicImportMessage
113      optional_public_import_message = 26;
114
115  optional NestedMessage optional_lazy_message = 27 [lazy=true];
116
117  // Repeated
118  repeated    int32 repeated_int32    = 31;
119  repeated    int64 repeated_int64    = 32;
120  repeated   uint32 repeated_uint32   = 33;
121  repeated   uint64 repeated_uint64   = 34;
122  repeated   sint32 repeated_sint32   = 35;
123  repeated   sint64 repeated_sint64   = 36;
124  repeated  fixed32 repeated_fixed32  = 37;
125  repeated  fixed64 repeated_fixed64  = 38;
126  repeated sfixed32 repeated_sfixed32 = 39;
127  repeated sfixed64 repeated_sfixed64 = 40;
128  repeated    float repeated_float    = 41;
129  repeated   double repeated_double   = 42;
130  repeated     bool repeated_bool     = 43;
131  repeated   string repeated_string   = 44;
132  repeated    bytes repeated_bytes    = 45;
133
134  repeated group RepeatedGroup = 46 {
135    optional int32 a = 47;
136  }
137
138  repeated NestedMessage                        repeated_nested_message  = 48;
139  repeated ForeignMessage                       repeated_foreign_message = 49;
140  repeated protobuf_unittest_import.ImportMessage repeated_import_message  = 50;
141
142  repeated NestedEnum                           repeated_nested_enum     = 51;
143  repeated ForeignEnum                          repeated_foreign_enum    = 52;
144  repeated protobuf_unittest_import.ImportEnum    repeated_import_enum     = 53;
145
146  repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
147  repeated string repeated_cord = 55 [ctype=CORD];
148
149  repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
150
151  // Singular with defaults
152  optional    int32 default_int32    = 61 [default =  41    ];
153  optional    int64 default_int64    = 62 [default =  42    ];
154  optional   uint32 default_uint32   = 63 [default =  43    ];
155  optional   uint64 default_uint64   = 64 [default =  44    ];
156  optional   sint32 default_sint32   = 65 [default = -45    ];
157  optional   sint64 default_sint64   = 66 [default =  46    ];
158  optional  fixed32 default_fixed32  = 67 [default =  47    ];
159  optional  fixed64 default_fixed64  = 68 [default =  48    ];
160  optional sfixed32 default_sfixed32 = 69 [default =  49    ];
161  optional sfixed64 default_sfixed64 = 70 [default = -50    ];
162  optional    float default_float    = 71 [default =  51.5  ];
163  optional   double default_double   = 72 [default =  52e3  ];
164  optional     bool default_bool     = 73 [default = true   ];
165  optional   string default_string   = 74 [default = "hello"];
166  optional    bytes default_bytes    = 75 [default = "world"];
167
168  optional NestedEnum  default_nested_enum  = 81 [default = BAR        ];
169  optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
170  optional protobuf_unittest_import.ImportEnum
171      default_import_enum = 83 [default = IMPORT_BAR];
172
173  optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
174  optional string default_cord = 85 [ctype=CORD,default="123"];
175
176  // For oneof test
177  oneof oneof_field {
178    uint32 oneof_uint32 = 111;
179    NestedMessage oneof_nested_message = 112;
180    string oneof_string = 113;
181    bytes oneof_bytes = 114;
182  }
183}
184
185// This proto includes a recursively nested message.
186message NestedTestAllTypes {
187  optional NestedTestAllTypes child = 1;
188  optional TestAllTypes payload = 2;
189  repeated NestedTestAllTypes repeated_child = 3;
190}
191
192message TestDeprecatedFields {
193  optional int32 deprecated_int32 = 1 [deprecated=true];
194  oneof oneof_fields {
195    int32 deprecated_int32_in_oneof = 2 [deprecated=true];
196  }
197}
198
199message TestDeprecatedMessage {
200  option deprecated = true;
201}
202
203// Define these after TestAllTypes to make sure the compiler can handle
204// that.
205message ForeignMessage {
206  optional int32 c = 1;
207  optional int32 d = 2;
208}
209
210enum ForeignEnum {
211  FOREIGN_FOO = 4;
212  FOREIGN_BAR = 5;
213  FOREIGN_BAZ = 6;
214}
215
216message TestReservedFields {
217  reserved 2, 15, 9 to 11;
218  reserved "bar", "baz";
219}
220
221message TestAllExtensions {
222  extensions 1 to max;
223}
224
225extend TestAllExtensions {
226  // Singular
227  optional    int32 optional_int32_extension    =  1;
228  optional    int64 optional_int64_extension    =  2;
229  optional   uint32 optional_uint32_extension   =  3;
230  optional   uint64 optional_uint64_extension   =  4;
231  optional   sint32 optional_sint32_extension   =  5;
232  optional   sint64 optional_sint64_extension   =  6;
233  optional  fixed32 optional_fixed32_extension  =  7;
234  optional  fixed64 optional_fixed64_extension  =  8;
235  optional sfixed32 optional_sfixed32_extension =  9;
236  optional sfixed64 optional_sfixed64_extension = 10;
237  optional    float optional_float_extension    = 11;
238  optional   double optional_double_extension   = 12;
239  optional     bool optional_bool_extension     = 13;
240  optional   string optional_string_extension   = 14;
241  optional    bytes optional_bytes_extension    = 15;
242
243  optional group OptionalGroup_extension = 16 {
244    optional int32 a = 17;
245  }
246
247  optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
248  optional ForeignMessage optional_foreign_message_extension = 19;
249  optional protobuf_unittest_import.ImportMessage
250    optional_import_message_extension = 20;
251
252  optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
253  optional ForeignEnum optional_foreign_enum_extension = 22;
254  optional protobuf_unittest_import.ImportEnum
255    optional_import_enum_extension = 23;
256
257  optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
258  optional string optional_cord_extension = 25 [ctype=CORD];
259
260  optional protobuf_unittest_import.PublicImportMessage
261    optional_public_import_message_extension = 26;
262
263  optional TestAllTypes.NestedMessage
264    optional_lazy_message_extension = 27 [lazy=true];
265
266  // Repeated
267  repeated    int32 repeated_int32_extension    = 31;
268  repeated    int64 repeated_int64_extension    = 32;
269  repeated   uint32 repeated_uint32_extension   = 33;
270  repeated   uint64 repeated_uint64_extension   = 34;
271  repeated   sint32 repeated_sint32_extension   = 35;
272  repeated   sint64 repeated_sint64_extension   = 36;
273  repeated  fixed32 repeated_fixed32_extension  = 37;
274  repeated  fixed64 repeated_fixed64_extension  = 38;
275  repeated sfixed32 repeated_sfixed32_extension = 39;
276  repeated sfixed64 repeated_sfixed64_extension = 40;
277  repeated    float repeated_float_extension    = 41;
278  repeated   double repeated_double_extension   = 42;
279  repeated     bool repeated_bool_extension     = 43;
280  repeated   string repeated_string_extension   = 44;
281  repeated    bytes repeated_bytes_extension    = 45;
282
283  repeated group RepeatedGroup_extension = 46 {
284    optional int32 a = 47;
285  }
286
287  repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
288  repeated ForeignMessage repeated_foreign_message_extension = 49;
289  repeated protobuf_unittest_import.ImportMessage
290    repeated_import_message_extension = 50;
291
292  repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
293  repeated ForeignEnum repeated_foreign_enum_extension = 52;
294  repeated protobuf_unittest_import.ImportEnum
295    repeated_import_enum_extension = 53;
296
297  repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
298  repeated string repeated_cord_extension = 55 [ctype=CORD];
299
300  repeated TestAllTypes.NestedMessage
301    repeated_lazy_message_extension = 57 [lazy=true];
302
303  // Singular with defaults
304  optional    int32 default_int32_extension    = 61 [default =  41    ];
305  optional    int64 default_int64_extension    = 62 [default =  42    ];
306  optional   uint32 default_uint32_extension   = 63 [default =  43    ];
307  optional   uint64 default_uint64_extension   = 64 [default =  44    ];
308  optional   sint32 default_sint32_extension   = 65 [default = -45    ];
309  optional   sint64 default_sint64_extension   = 66 [default =  46    ];
310  optional  fixed32 default_fixed32_extension  = 67 [default =  47    ];
311  optional  fixed64 default_fixed64_extension  = 68 [default =  48    ];
312  optional sfixed32 default_sfixed32_extension = 69 [default =  49    ];
313  optional sfixed64 default_sfixed64_extension = 70 [default = -50    ];
314  optional    float default_float_extension    = 71 [default =  51.5  ];
315  optional   double default_double_extension   = 72 [default =  52e3  ];
316  optional     bool default_bool_extension     = 73 [default = true   ];
317  optional   string default_string_extension   = 74 [default = "hello"];
318  optional    bytes default_bytes_extension    = 75 [default = "world"];
319
320  optional TestAllTypes.NestedEnum
321    default_nested_enum_extension = 81 [default = BAR];
322  optional ForeignEnum
323    default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
324  optional protobuf_unittest_import.ImportEnum
325    default_import_enum_extension = 83 [default = IMPORT_BAR];
326
327  optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
328                                                       default="abc"];
329  optional string default_cord_extension = 85 [ctype=CORD, default="123"];
330
331  // For oneof test
332  optional uint32 oneof_uint32_extension = 111;
333  optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112;
334  optional string oneof_string_extension = 113;
335  optional bytes oneof_bytes_extension = 114;
336}
337
338message TestGroup {
339  optional group OptionalGroup = 16 {
340    optional int32 a = 17;
341  }
342  optional ForeignEnum optional_foreign_enum = 22;
343}
344
345message TestGroupExtension {
346  extensions 1 to max;
347}
348
349message TestNestedExtension {
350  extend TestAllExtensions {
351    // Check for bug where string extensions declared in tested scope did not
352    // compile.
353    optional string test = 1002 [default="test"];
354    // Used to test if generated extension name is correct when there are
355    // underscores.
356    optional string nested_string_extension = 1003;
357  }
358
359  extend TestGroupExtension {
360    optional group OptionalGroup_extension = 16 {
361      optional int32 a = 17;
362    }
363    optional ForeignEnum optional_foreign_enum_extension = 22;
364  }
365}
366
367// We have separate messages for testing required fields because it's
368// annoying to have to fill in required fields in TestProto in order to
369// do anything with it.  Note that we don't need to test every type of
370// required filed because the code output is basically identical to
371// optional fields for all types.
372message TestRequired {
373  required int32 a = 1;
374  optional int32 dummy2 = 2;
375  required int32 b = 3;
376
377  extend TestAllExtensions {
378    optional TestRequired single = 1000;
379    repeated TestRequired multi  = 1001;
380  }
381
382  // Pad the field count to 32 so that we can test that IsInitialized()
383  // properly checks multiple elements of has_bits_.
384  optional int32 dummy4  =  4;
385  optional int32 dummy5  =  5;
386  optional int32 dummy6  =  6;
387  optional int32 dummy7  =  7;
388  optional int32 dummy8  =  8;
389  optional int32 dummy9  =  9;
390  optional int32 dummy10 = 10;
391  optional int32 dummy11 = 11;
392  optional int32 dummy12 = 12;
393  optional int32 dummy13 = 13;
394  optional int32 dummy14 = 14;
395  optional int32 dummy15 = 15;
396  optional int32 dummy16 = 16;
397  optional int32 dummy17 = 17;
398  optional int32 dummy18 = 18;
399  optional int32 dummy19 = 19;
400  optional int32 dummy20 = 20;
401  optional int32 dummy21 = 21;
402  optional int32 dummy22 = 22;
403  optional int32 dummy23 = 23;
404  optional int32 dummy24 = 24;
405  optional int32 dummy25 = 25;
406  optional int32 dummy26 = 26;
407  optional int32 dummy27 = 27;
408  optional int32 dummy28 = 28;
409  optional int32 dummy29 = 29;
410  optional int32 dummy30 = 30;
411  optional int32 dummy31 = 31;
412  optional int32 dummy32 = 32;
413
414  required int32 c = 33;
415}
416
417message TestRequiredForeign {
418  optional TestRequired optional_message = 1;
419  repeated TestRequired repeated_message = 2;
420  optional int32 dummy = 3;
421}
422
423message TestRequiredMessage {
424  optional TestRequired optional_message = 1;
425  repeated TestRequired repeated_message = 2;
426  required TestRequired required_message = 3;
427}
428
429// Test that we can use NestedMessage from outside TestAllTypes.
430message TestForeignNested {
431  optional TestAllTypes.NestedMessage foreign_nested = 1;
432}
433
434// TestEmptyMessage is used to test unknown field support.
435message TestEmptyMessage {
436}
437
438// Like above, but declare all field numbers as potential extensions.  No
439// actual extensions should ever be defined for this type.
440message TestEmptyMessageWithExtensions {
441  extensions 1 to max;
442}
443
444// Needed for a Python test.
445message TestPickleNestedMessage {
446  message NestedMessage {
447    optional int32 bb = 1;
448    message NestedNestedMessage {
449      optional int32 cc = 1;
450    }
451  }
452}
453
454message TestMultipleExtensionRanges {
455  extensions 42;
456  extensions 4143 to 4243;
457  extensions 65536 to max;
458}
459
460// Test that really large tag numbers don't break anything.
461message TestReallyLargeTagNumber {
462  // The largest possible tag number is 2^28 - 1, since the wire format uses
463  // three bits to communicate wire type.
464  optional int32 a = 1;
465  optional int32 bb = 268435455;
466}
467
468message TestRecursiveMessage {
469  optional TestRecursiveMessage a = 1;
470  optional int32 i = 2;
471}
472
473// Test that mutual recursion works.
474message TestMutualRecursionA {
475  message SubMessage {
476    optional TestMutualRecursionB b = 1;
477  }
478  optional TestMutualRecursionB bb = 1;
479  optional group SubGroup = 2 {
480    optional SubMessage sub_message = 3;  // Needed because of bug in javatest
481    optional TestAllTypes not_in_this_scc = 4;
482  }
483}
484
485message TestMutualRecursionB {
486  optional TestMutualRecursionA a = 1;
487  optional int32 optional_int32 = 2;
488}
489
490message TestIsInitialized {
491  message SubMessage {
492    optional group SubGroup = 1 {
493      required int32 i = 2;
494    }
495  }
496  optional SubMessage sub_message = 1;
497}
498
499// Test that groups have disjoint field numbers from their siblings and
500// parents.  This is NOT possible in proto1; only google.protobuf.  When attempting
501// to compile with proto1, this will emit an error; so we only include it
502// in protobuf_unittest_proto.
503message TestDupFieldNumber {                        // NO_PROTO1
504  optional int32 a = 1;                             // NO_PROTO1
505  optional group Foo = 2 { optional int32 a = 1; }  // NO_PROTO1
506  optional group Bar = 3 { optional int32 a = 1; }  // NO_PROTO1
507}                                                   // NO_PROTO1
508
509// Additional messages for testing lazy fields.
510message TestEagerMessage {
511  optional TestAllTypes sub_message = 1 [lazy=false];
512}
513message TestLazyMessage {
514  optional TestAllTypes sub_message = 1 [lazy=true];
515}
516
517// Needed for a Python test.
518message TestNestedMessageHasBits {
519  message NestedMessage {
520    repeated int32 nestedmessage_repeated_int32 = 1;
521    repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
522  }
523  optional NestedMessage optional_nested_message = 1;
524}
525
526
527// Test an enum that has multiple values with the same number.
528enum TestEnumWithDupValue {
529  option allow_alias = true;
530
531  FOO1 = 1;
532  BAR1 = 2;
533  BAZ = 3;
534  FOO2 = 1;
535  BAR2 = 2;
536}
537
538// Test an enum with large, unordered values.
539enum TestSparseEnum {
540  SPARSE_A = 123;
541  SPARSE_B = 62374;
542  SPARSE_C = 12589234;
543  SPARSE_D = -15;
544  SPARSE_E = -53452;
545  SPARSE_F = 0;
546  SPARSE_G = 2;
547}
548
549// Test message with CamelCase field names.  This violates Protocol Buffer
550// standard style.
551message TestCamelCaseFieldNames {
552  optional int32 PrimitiveField = 1;
553  optional string StringField = 2;
554  optional ForeignEnum EnumField = 3;
555  optional ForeignMessage MessageField = 4;
556  optional string StringPieceField = 5 [ctype=STRING_PIECE];
557  optional string CordField = 6 [ctype=CORD];
558
559  repeated int32 RepeatedPrimitiveField = 7;
560  repeated string RepeatedStringField = 8;
561  repeated ForeignEnum RepeatedEnumField = 9;
562  repeated ForeignMessage RepeatedMessageField = 10;
563  repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
564  repeated string RepeatedCordField = 12 [ctype=CORD];
565}
566
567
568// We list fields out of order, to ensure that we're using field number and not
569// field index to determine serialization order.
570message TestFieldOrderings {
571  optional string my_string = 11;
572  extensions 2 to 10;
573  optional int64 my_int = 1;
574  extensions 12 to 100;
575  optional float my_float = 101;
576  message NestedMessage {
577    optional int64 oo = 2;
578    // The field name "b" fails to compile in proto1 because it conflicts with
579    // a local variable named "b" in one of the generated methods.  Doh.
580    // This file needs to compile in proto1 to test backwards-compatibility.
581    optional int32 bb = 1;
582  }
583
584  optional NestedMessage optional_nested_message  = 200;
585}
586
587extend TestFieldOrderings {
588  optional string my_extension_string = 50;
589  optional int32 my_extension_int = 5;
590}
591
592message TestExtensionOrderings1 {
593  extend TestFieldOrderings {
594    optional TestExtensionOrderings1 test_ext_orderings1 = 13;
595  }
596  optional string my_string = 1;
597}
598
599message TestExtensionOrderings2 {
600  extend TestFieldOrderings {
601    optional TestExtensionOrderings2 test_ext_orderings2 = 12;
602  }
603  message TestExtensionOrderings3 {
604    extend TestFieldOrderings {
605      optional TestExtensionOrderings3 test_ext_orderings3 = 14;
606    }
607    optional string my_string = 1;
608  }
609  optional string my_string = 1;
610}
611
612message TestExtremeDefaultValues {
613  optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
614  optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
615  optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
616  optional  int32 small_int32  = 4 [default = -0x7FFFFFFF];
617  optional  int64 small_int64  = 5 [default = -0x7FFFFFFFFFFFFFFF];
618  optional  int32 really_small_int32 = 21 [default = -0x80000000];
619  optional  int64 really_small_int64 = 22 [default = -0x8000000000000000];
620
621  // The default value here is UTF-8 for "\u1234".  (We could also just type
622  // the UTF-8 text directly into this text file rather than escape it, but
623  // lots of people use editors that would be confused by this.)
624  optional string utf8_string = 6 [default = "\341\210\264"];
625
626  // Tests for single-precision floating-point values.
627  optional float zero_float = 7 [default = 0];
628  optional float one_float = 8 [default = 1];
629  optional float small_float = 9 [default = 1.5];
630  optional float negative_one_float = 10 [default = -1];
631  optional float negative_float = 11 [default = -1.5];
632  // Using exponents
633  optional float large_float = 12 [default = 2E8];
634  optional float small_negative_float = 13 [default = -8e-28];
635
636  // Text for nonfinite floating-point values.
637  optional double inf_double = 14 [default = inf];
638  optional double neg_inf_double = 15 [default = -inf];
639  optional double nan_double = 16 [default = nan];
640  optional float inf_float = 17 [default = inf];
641  optional float neg_inf_float = 18 [default = -inf];
642  optional float nan_float = 19 [default = nan];
643
644  // Tests for C++ trigraphs.
645  // Trigraphs should be escaped in C++ generated files, but they should not be
646  // escaped for other languages.
647  // Note that in .proto file, "\?" is a valid way to escape ? in string
648  // literals.
649  optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
650
651  // String defaults containing the character '\000'
652  optional string string_with_zero       = 23 [default = "hel\000lo"];
653  optional  bytes bytes_with_zero        = 24 [default = "wor\000ld"];
654  optional string string_piece_with_zero = 25 [ctype=STRING_PIECE,
655                                               default="ab\000c"];
656  optional string cord_with_zero         = 26 [ctype=CORD,
657                                               default="12\0003"];
658  optional string replacement_string     = 27 [default="${unknown}"];
659}
660
661message SparseEnumMessage {
662  optional TestSparseEnum sparse_enum = 1;
663}
664
665// Test String and Bytes: string is for valid UTF-8 strings
666message OneString {
667  optional string data = 1;
668}
669
670message MoreString {
671  repeated string data = 1;
672}
673
674message OneBytes {
675  optional bytes data = 1;
676}
677
678message MoreBytes {
679  repeated bytes data = 1;
680}
681
682// Test int32, uint32, int64, uint64, and bool are all compatible
683message Int32Message {
684  optional int32 data = 1;
685}
686
687message Uint32Message {
688  optional uint32 data = 1;
689}
690
691message Int64Message {
692  optional int64 data = 1;
693}
694
695message Uint64Message {
696  optional uint64 data = 1;
697}
698
699message BoolMessage {
700  optional bool data = 1;
701}
702
703// Test oneofs.
704message TestOneof {
705  oneof foo {
706    int32 foo_int = 1;
707    string foo_string = 2;
708    TestAllTypes foo_message = 3;
709    group FooGroup = 4 {
710      optional int32 a = 5;
711      optional string b = 6;
712    }
713  }
714}
715
716message TestOneofBackwardsCompatible {
717  optional int32 foo_int = 1;
718  optional string foo_string = 2;
719  optional TestAllTypes foo_message = 3;
720  optional group FooGroup = 4 {
721    optional int32 a = 5;
722    optional string b = 6;
723  }
724}
725
726message TestOneof2 {
727  oneof foo {
728    int32 foo_int = 1;
729    string foo_string = 2;
730    string foo_cord = 3 [ctype=CORD];
731    string foo_string_piece = 4 [ctype=STRING_PIECE];
732    bytes foo_bytes = 5;
733    NestedEnum foo_enum = 6;
734    NestedMessage foo_message = 7;
735    group FooGroup = 8 {
736      optional int32 a = 9;
737      optional string b = 10;
738    }
739    NestedMessage foo_lazy_message = 11 [lazy=true];
740  }
741
742  oneof bar {
743    int32 bar_int = 12 [default = 5];
744    string bar_string = 13 [default = "STRING"];
745    string bar_cord = 14 [ctype=CORD, default = "CORD"];
746    string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"];
747    bytes bar_bytes = 16 [default = "BYTES"];
748    NestedEnum bar_enum = 17 [default = BAR];
749  }
750
751  optional int32 baz_int = 18;
752  optional string baz_string = 19 [default = "BAZ"];
753
754  message NestedMessage {
755    optional int64 qux_int = 1;
756    repeated int32 corge_int = 2;
757  }
758
759  enum NestedEnum {
760    FOO = 1;
761    BAR = 2;
762    BAZ = 3;
763  }
764}
765
766message TestRequiredOneof {
767  oneof foo {
768    int32 foo_int = 1;
769    string foo_string = 2;
770    NestedMessage foo_message = 3;
771  }
772  message NestedMessage {
773    required double required_double = 1;
774  }
775}
776
777
778// Test messages for packed fields
779
780message TestPackedTypes {
781  repeated    int32 packed_int32    =  90 [packed = true];
782  repeated    int64 packed_int64    =  91 [packed = true];
783  repeated   uint32 packed_uint32   =  92 [packed = true];
784  repeated   uint64 packed_uint64   =  93 [packed = true];
785  repeated   sint32 packed_sint32   =  94 [packed = true];
786  repeated   sint64 packed_sint64   =  95 [packed = true];
787  repeated  fixed32 packed_fixed32  =  96 [packed = true];
788  repeated  fixed64 packed_fixed64  =  97 [packed = true];
789  repeated sfixed32 packed_sfixed32 =  98 [packed = true];
790  repeated sfixed64 packed_sfixed64 =  99 [packed = true];
791  repeated    float packed_float    = 100 [packed = true];
792  repeated   double packed_double   = 101 [packed = true];
793  repeated     bool packed_bool     = 102 [packed = true];
794  repeated ForeignEnum packed_enum  = 103 [packed = true];
795}
796
797// A message with the same fields as TestPackedTypes, but without packing. Used
798// to test packed <-> unpacked wire compatibility.
799message TestUnpackedTypes {
800  repeated    int32 unpacked_int32    =  90 [packed = false];
801  repeated    int64 unpacked_int64    =  91 [packed = false];
802  repeated   uint32 unpacked_uint32   =  92 [packed = false];
803  repeated   uint64 unpacked_uint64   =  93 [packed = false];
804  repeated   sint32 unpacked_sint32   =  94 [packed = false];
805  repeated   sint64 unpacked_sint64   =  95 [packed = false];
806  repeated  fixed32 unpacked_fixed32  =  96 [packed = false];
807  repeated  fixed64 unpacked_fixed64  =  97 [packed = false];
808  repeated sfixed32 unpacked_sfixed32 =  98 [packed = false];
809  repeated sfixed64 unpacked_sfixed64 =  99 [packed = false];
810  repeated    float unpacked_float    = 100 [packed = false];
811  repeated   double unpacked_double   = 101 [packed = false];
812  repeated     bool unpacked_bool     = 102 [packed = false];
813  repeated ForeignEnum unpacked_enum  = 103 [packed = false];
814}
815
816message TestPackedExtensions {
817  extensions 1 to max;
818}
819
820extend TestPackedExtensions {
821  repeated    int32 packed_int32_extension    =  90 [packed = true];
822  repeated    int64 packed_int64_extension    =  91 [packed = true];
823  repeated   uint32 packed_uint32_extension   =  92 [packed = true];
824  repeated   uint64 packed_uint64_extension   =  93 [packed = true];
825  repeated   sint32 packed_sint32_extension   =  94 [packed = true];
826  repeated   sint64 packed_sint64_extension   =  95 [packed = true];
827  repeated  fixed32 packed_fixed32_extension  =  96 [packed = true];
828  repeated  fixed64 packed_fixed64_extension  =  97 [packed = true];
829  repeated sfixed32 packed_sfixed32_extension =  98 [packed = true];
830  repeated sfixed64 packed_sfixed64_extension =  99 [packed = true];
831  repeated    float packed_float_extension    = 100 [packed = true];
832  repeated   double packed_double_extension   = 101 [packed = true];
833  repeated     bool packed_bool_extension     = 102 [packed = true];
834  repeated ForeignEnum packed_enum_extension  = 103 [packed = true];
835}
836
837message TestUnpackedExtensions {
838  extensions 1 to max;
839}
840
841extend TestUnpackedExtensions {
842  repeated    int32 unpacked_int32_extension    =  90 [packed = false];
843  repeated    int64 unpacked_int64_extension    =  91 [packed = false];
844  repeated   uint32 unpacked_uint32_extension   =  92 [packed = false];
845  repeated   uint64 unpacked_uint64_extension   =  93 [packed = false];
846  repeated   sint32 unpacked_sint32_extension   =  94 [packed = false];
847  repeated   sint64 unpacked_sint64_extension   =  95 [packed = false];
848  repeated  fixed32 unpacked_fixed32_extension  =  96 [packed = false];
849  repeated  fixed64 unpacked_fixed64_extension  =  97 [packed = false];
850  repeated sfixed32 unpacked_sfixed32_extension =  98 [packed = false];
851  repeated sfixed64 unpacked_sfixed64_extension =  99 [packed = false];
852  repeated    float unpacked_float_extension    = 100 [packed = false];
853  repeated   double unpacked_double_extension   = 101 [packed = false];
854  repeated     bool unpacked_bool_extension     = 102 [packed = false];
855  repeated ForeignEnum unpacked_enum_extension  = 103 [packed = false];
856}
857
858// Used by ExtensionSetTest/DynamicExtensions.  The test actually builds
859// a set of extensions to TestAllExtensions dynamically, based on the fields
860// of this message type.
861message TestDynamicExtensions {
862  enum DynamicEnumType {
863    DYNAMIC_FOO = 2200;
864    DYNAMIC_BAR = 2201;
865    DYNAMIC_BAZ = 2202;
866  }
867  message DynamicMessageType {
868    optional int32 dynamic_field = 2100;
869  }
870
871  optional fixed32 scalar_extension = 2000;
872  optional ForeignEnum enum_extension = 2001;
873  optional DynamicEnumType dynamic_enum_extension = 2002;
874
875  optional ForeignMessage message_extension = 2003;
876  optional DynamicMessageType dynamic_message_extension = 2004;
877
878  repeated string repeated_extension = 2005;
879  repeated sint32 packed_extension = 2006 [packed = true];
880}
881
882message TestRepeatedScalarDifferentTagSizes {
883  // Parsing repeated fixed size values used to fail. This message needs to be
884  // used in order to get a tag of the right size; all of the repeated fields
885  // in TestAllTypes didn't trigger the check.
886  repeated fixed32 repeated_fixed32 = 12;
887  // Check for a varint type, just for good measure.
888  repeated int32   repeated_int32   = 13;
889
890  // These have two-byte tags.
891  repeated fixed64 repeated_fixed64 = 2046;
892  repeated int64   repeated_int64   = 2047;
893
894  // Three byte tags.
895  repeated float   repeated_float   = 262142;
896  repeated uint64  repeated_uint64  = 262143;
897}
898
899// Test that if an optional or required message/group field appears multiple
900// times in the input, they need to be merged.
901message TestParsingMerge {
902  // RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
903  // except that all fields are repeated. In the tests, we will serialize the
904  // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
905  // Repeated fields in RepeatedFieldsGenerator are expected to be merged into
906  // the corresponding required/optional fields in TestParsingMerge.
907  message RepeatedFieldsGenerator {
908    repeated TestAllTypes field1 = 1;
909    repeated TestAllTypes field2 = 2;
910    repeated TestAllTypes field3 = 3;
911    repeated group Group1 = 10 {
912      optional TestAllTypes field1 = 11;
913    }
914    repeated group Group2 = 20 {
915      optional TestAllTypes field1 = 21;
916    }
917    repeated TestAllTypes ext1 = 1000;
918    repeated TestAllTypes ext2 = 1001;
919  }
920  required TestAllTypes required_all_types = 1;
921  optional TestAllTypes optional_all_types = 2;
922  repeated TestAllTypes repeated_all_types = 3;
923  optional group OptionalGroup = 10 {
924    optional TestAllTypes optional_group_all_types = 11;
925  }
926  repeated group RepeatedGroup = 20 {
927    optional TestAllTypes repeated_group_all_types = 21;
928  }
929  extensions 1000 to max;
930  extend TestParsingMerge {
931    optional TestAllTypes optional_ext = 1000;
932    repeated TestAllTypes repeated_ext = 1001;
933  }
934}
935
936message TestCommentInjectionMessage {
937  // */ <- This should not close the generated doc comment
938  optional string a = 1 [default="*/ <- Neither should this."];
939}
940
941
942// Test that RPC services work.
943message FooRequest  {}
944message FooResponse {}
945
946message FooClientMessage {}
947message FooServerMessage{}
948
949service TestService {
950  rpc Foo(FooRequest) returns (FooResponse);
951  rpc Bar(BarRequest) returns (BarResponse);
952}
953
954
955message BarRequest  {}
956message BarResponse {}
957
958message TestJsonName {
959  optional int32 field_name1 = 1;
960  optional int32 fieldName2 = 2;
961  optional int32 FieldName3 = 3;
962  optional int32 _field_name4 = 4;
963  optional int32 FIELD_NAME5 = 5;
964  optional int32 field_name6 = 6 [json_name = "@type"];
965}
966
967message TestHugeFieldNumbers {
968  optional int32 optional_int32 = 536870000;
969  optional int32 fixed_32 = 536870001;
970  repeated int32 repeated_int32 = 536870002 [packed = false];
971  repeated int32 packed_int32 = 536870003 [packed = true];
972
973  optional ForeignEnum optional_enum = 536870004;
974  optional string optional_string = 536870005;
975  optional bytes optional_bytes = 536870006;
976  optional ForeignMessage optional_message = 536870007;
977
978  optional group OptionalGroup = 536870008 {
979    optional int32 group_a = 536870009;
980  }
981
982  map<string, string> string_string_map = 536870010;
983
984  oneof oneof_field {
985    uint32 oneof_uint32 = 536870011;
986    TestAllTypes oneof_test_all_types = 536870012;
987    string oneof_string = 536870013;
988    bytes oneof_bytes = 536870014;
989  }
990
991  extensions  536860000 to 536869999;
992}
993
994extend TestHugeFieldNumbers {
995  optional TestAllTypes test_all_types = 536860000;
996}
997
998message TestExtensionInsideTable {
999  optional int32 field1 = 1;
1000  optional int32 field2 = 2;
1001  optional int32 field3 = 3;
1002  optional int32 field4 = 4;
1003  extensions 5 to 5;
1004  optional int32 field6 = 6;
1005  optional int32 field7 = 7;
1006  optional int32 field8 = 8;
1007  optional int32 field9 = 9;
1008  optional int32 field10 = 10;
1009}
1010
1011extend TestExtensionInsideTable {
1012  optional int32 test_extension_inside_table_extension = 5;
1013}
1014
1015enum VeryLargeEnum {
1016  ENUM_LABEL_DEFAULT = 0;
1017  ENUM_LABEL_1 = 1;
1018  ENUM_LABEL_2 = 2;
1019  ENUM_LABEL_3 = 3;
1020  ENUM_LABEL_4 = 4;
1021  ENUM_LABEL_5 = 5;
1022  ENUM_LABEL_6 = 6;
1023  ENUM_LABEL_7 = 7;
1024  ENUM_LABEL_8 = 8;
1025  ENUM_LABEL_9 = 9;
1026  ENUM_LABEL_10 = 10;
1027  ENUM_LABEL_11 = 11;
1028  ENUM_LABEL_12 = 12;
1029  ENUM_LABEL_13 = 13;
1030  ENUM_LABEL_14 = 14;
1031  ENUM_LABEL_15 = 15;
1032  ENUM_LABEL_16 = 16;
1033  ENUM_LABEL_17 = 17;
1034  ENUM_LABEL_18 = 18;
1035  ENUM_LABEL_19 = 19;
1036  ENUM_LABEL_20 = 20;
1037  ENUM_LABEL_21 = 21;
1038  ENUM_LABEL_22 = 22;
1039  ENUM_LABEL_23 = 23;
1040  ENUM_LABEL_24 = 24;
1041  ENUM_LABEL_25 = 25;
1042  ENUM_LABEL_26 = 26;
1043  ENUM_LABEL_27 = 27;
1044  ENUM_LABEL_28 = 28;
1045  ENUM_LABEL_29 = 29;
1046  ENUM_LABEL_30 = 30;
1047  ENUM_LABEL_31 = 31;
1048  ENUM_LABEL_32 = 32;
1049  ENUM_LABEL_33 = 33;
1050  ENUM_LABEL_34 = 34;
1051  ENUM_LABEL_35 = 35;
1052  ENUM_LABEL_36 = 36;
1053  ENUM_LABEL_37 = 37;
1054  ENUM_LABEL_38 = 38;
1055  ENUM_LABEL_39 = 39;
1056  ENUM_LABEL_40 = 40;
1057  ENUM_LABEL_41 = 41;
1058  ENUM_LABEL_42 = 42;
1059  ENUM_LABEL_43 = 43;
1060  ENUM_LABEL_44 = 44;
1061  ENUM_LABEL_45 = 45;
1062  ENUM_LABEL_46 = 46;
1063  ENUM_LABEL_47 = 47;
1064  ENUM_LABEL_48 = 48;
1065  ENUM_LABEL_49 = 49;
1066  ENUM_LABEL_50 = 50;
1067  ENUM_LABEL_51 = 51;
1068  ENUM_LABEL_52 = 52;
1069  ENUM_LABEL_53 = 53;
1070  ENUM_LABEL_54 = 54;
1071  ENUM_LABEL_55 = 55;
1072  ENUM_LABEL_56 = 56;
1073  ENUM_LABEL_57 = 57;
1074  ENUM_LABEL_58 = 58;
1075  ENUM_LABEL_59 = 59;
1076  ENUM_LABEL_60 = 60;
1077  ENUM_LABEL_61 = 61;
1078  ENUM_LABEL_62 = 62;
1079  ENUM_LABEL_63 = 63;
1080  ENUM_LABEL_64 = 64;
1081  ENUM_LABEL_65 = 65;
1082  ENUM_LABEL_66 = 66;
1083  ENUM_LABEL_67 = 67;
1084  ENUM_LABEL_68 = 68;
1085  ENUM_LABEL_69 = 69;
1086  ENUM_LABEL_70 = 70;
1087  ENUM_LABEL_71 = 71;
1088  ENUM_LABEL_72 = 72;
1089  ENUM_LABEL_73 = 73;
1090  ENUM_LABEL_74 = 74;
1091  ENUM_LABEL_75 = 75;
1092  ENUM_LABEL_76 = 76;
1093  ENUM_LABEL_77 = 77;
1094  ENUM_LABEL_78 = 78;
1095  ENUM_LABEL_79 = 79;
1096  ENUM_LABEL_80 = 80;
1097  ENUM_LABEL_81 = 81;
1098  ENUM_LABEL_82 = 82;
1099  ENUM_LABEL_83 = 83;
1100  ENUM_LABEL_84 = 84;
1101  ENUM_LABEL_85 = 85;
1102  ENUM_LABEL_86 = 86;
1103  ENUM_LABEL_87 = 87;
1104  ENUM_LABEL_88 = 88;
1105  ENUM_LABEL_89 = 89;
1106  ENUM_LABEL_90 = 90;
1107  ENUM_LABEL_91 = 91;
1108  ENUM_LABEL_92 = 92;
1109  ENUM_LABEL_93 = 93;
1110  ENUM_LABEL_94 = 94;
1111  ENUM_LABEL_95 = 95;
1112  ENUM_LABEL_96 = 96;
1113  ENUM_LABEL_97 = 97;
1114  ENUM_LABEL_98 = 98;
1115  ENUM_LABEL_99 = 99;
1116  ENUM_LABEL_100 = 100;
1117};
1118