1// Go support for Protocol Buffers - Google's data interchange format
2//
3// Copyright 2010 The Go Authors.  All rights reserved.
4// https://github.com/golang/protobuf
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10//     * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12//     * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16//     * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32// A feature-rich test file for the protocol compiler and libraries.
33
34syntax = "proto2";
35
36package testdata;
37
38enum FOO { FOO1 = 1; };
39
40message GoEnum {
41  required FOO foo = 1;
42}
43
44message GoTestField {
45  required string Label = 1;
46  required string Type = 2;
47}
48
49message GoTest {
50  // An enum, for completeness.
51  enum KIND {
52    VOID = 0;
53
54    // Basic types
55    BOOL = 1;
56    BYTES = 2;
57    FINGERPRINT = 3;
58    FLOAT = 4;
59    INT = 5;
60    STRING = 6;
61    TIME = 7;
62
63    // Groupings
64    TUPLE = 8;
65    ARRAY = 9;
66    MAP = 10;
67
68    // Table types
69    TABLE = 11;
70
71    // Functions
72    FUNCTION = 12;  // last tag
73  };
74
75  // Some typical parameters
76  required KIND Kind = 1;
77  optional string Table = 2;
78  optional int32 Param = 3;
79
80  // Required, repeated and optional foreign fields.
81  required GoTestField RequiredField = 4;
82  repeated GoTestField RepeatedField = 5;
83  optional GoTestField OptionalField = 6;
84
85  // Required fields of all basic types
86  required bool F_Bool_required = 10;
87  required int32 F_Int32_required = 11;
88  required int64 F_Int64_required = 12;
89  required fixed32 F_Fixed32_required = 13;
90  required fixed64 F_Fixed64_required = 14;
91  required uint32 F_Uint32_required = 15;
92  required uint64 F_Uint64_required = 16;
93  required float F_Float_required = 17;
94  required double F_Double_required = 18;
95  required string F_String_required = 19;
96  required bytes F_Bytes_required = 101;
97  required sint32 F_Sint32_required = 102;
98  required sint64 F_Sint64_required = 103;
99
100  // Repeated fields of all basic types
101  repeated bool F_Bool_repeated = 20;
102  repeated int32 F_Int32_repeated = 21;
103  repeated int64 F_Int64_repeated = 22;
104  repeated fixed32 F_Fixed32_repeated = 23;
105  repeated fixed64 F_Fixed64_repeated = 24;
106  repeated uint32 F_Uint32_repeated = 25;
107  repeated uint64 F_Uint64_repeated = 26;
108  repeated float F_Float_repeated = 27;
109  repeated double F_Double_repeated = 28;
110  repeated string F_String_repeated = 29;
111  repeated bytes F_Bytes_repeated = 201;
112  repeated sint32 F_Sint32_repeated = 202;
113  repeated sint64 F_Sint64_repeated = 203;
114
115  // Optional fields of all basic types
116  optional bool F_Bool_optional = 30;
117  optional int32 F_Int32_optional = 31;
118  optional int64 F_Int64_optional = 32;
119  optional fixed32 F_Fixed32_optional = 33;
120  optional fixed64 F_Fixed64_optional = 34;
121  optional uint32 F_Uint32_optional = 35;
122  optional uint64 F_Uint64_optional = 36;
123  optional float F_Float_optional = 37;
124  optional double F_Double_optional = 38;
125  optional string F_String_optional = 39;
126  optional bytes F_Bytes_optional = 301;
127  optional sint32 F_Sint32_optional = 302;
128  optional sint64 F_Sint64_optional = 303;
129
130  // Default-valued fields of all basic types
131  optional bool F_Bool_defaulted = 40 [default=true];
132  optional int32 F_Int32_defaulted = 41 [default=32];
133  optional int64 F_Int64_defaulted = 42 [default=64];
134  optional fixed32 F_Fixed32_defaulted = 43 [default=320];
135  optional fixed64 F_Fixed64_defaulted = 44 [default=640];
136  optional uint32 F_Uint32_defaulted = 45 [default=3200];
137  optional uint64 F_Uint64_defaulted = 46 [default=6400];
138  optional float F_Float_defaulted = 47 [default=314159.];
139  optional double F_Double_defaulted = 48 [default=271828.];
140  optional string F_String_defaulted = 49 [default="hello, \"world!\"\n"];
141  optional bytes F_Bytes_defaulted = 401 [default="Bignose"];
142  optional sint32 F_Sint32_defaulted = 402 [default = -32];
143  optional sint64 F_Sint64_defaulted = 403 [default = -64];
144
145  // Packed repeated fields (no string or bytes).
146  repeated bool F_Bool_repeated_packed = 50 [packed=true];
147  repeated int32 F_Int32_repeated_packed = 51 [packed=true];
148  repeated int64 F_Int64_repeated_packed = 52 [packed=true];
149  repeated fixed32 F_Fixed32_repeated_packed = 53 [packed=true];
150  repeated fixed64 F_Fixed64_repeated_packed = 54 [packed=true];
151  repeated uint32 F_Uint32_repeated_packed = 55 [packed=true];
152  repeated uint64 F_Uint64_repeated_packed = 56 [packed=true];
153  repeated float F_Float_repeated_packed = 57 [packed=true];
154  repeated double F_Double_repeated_packed = 58 [packed=true];
155  repeated sint32 F_Sint32_repeated_packed = 502 [packed=true];
156  repeated sint64 F_Sint64_repeated_packed = 503 [packed=true];
157
158  // Required, repeated, and optional groups.
159  required group RequiredGroup = 70 {
160    required string RequiredField = 71;
161  };
162
163  repeated group RepeatedGroup = 80 {
164    required string RequiredField = 81;
165  };
166
167  optional group OptionalGroup = 90 {
168    required string RequiredField = 91;
169  };
170}
171
172// For testing skipping of unrecognized fields.
173// Numbers are all big, larger than tag numbers in GoTestField,
174// the message used in the corresponding test.
175message GoSkipTest {
176  required int32 skip_int32 = 11;
177  required fixed32 skip_fixed32 = 12;
178  required fixed64 skip_fixed64 = 13;
179  required string skip_string = 14;
180  required group SkipGroup = 15 {
181    required int32 group_int32 = 16;
182    required string group_string = 17;
183  }
184}
185
186// For testing packed/non-packed decoder switching.
187// A serialized instance of one should be deserializable as the other.
188message NonPackedTest {
189  repeated int32 a = 1;
190}
191
192message PackedTest {
193  repeated int32 b = 1 [packed=true];
194}
195
196message MaxTag {
197  // Maximum possible tag number.
198  optional string last_field = 536870911;
199}
200
201message OldMessage {
202  message Nested {
203    optional string name = 1;
204  }
205  optional Nested nested = 1;
206
207  optional int32 num = 2;
208}
209
210// NewMessage is wire compatible with OldMessage;
211// imagine it as a future version.
212message NewMessage {
213  message Nested {
214    optional string name = 1;
215    optional string food_group = 2;
216  }
217  optional Nested nested = 1;
218
219  // This is an int32 in OldMessage.
220  optional int64 num = 2;
221}
222
223// Smaller tests for ASCII formatting.
224
225message InnerMessage {
226  required string host = 1;
227  optional int32 port = 2 [default=4000];
228  optional bool connected = 3;
229}
230
231message OtherMessage {
232  optional int64 key = 1;
233  optional bytes value = 2;
234  optional float weight = 3;
235  optional InnerMessage inner = 4;
236
237  extensions 100 to max;
238}
239
240message RequiredInnerMessage {
241  required InnerMessage leo_finally_won_an_oscar = 1;
242}
243
244message MyMessage {
245  required int32 count = 1;
246  optional string name = 2;
247  optional string quote = 3;
248  repeated string pet = 4;
249  optional InnerMessage inner = 5;
250  repeated OtherMessage others = 6;
251  optional RequiredInnerMessage we_must_go_deeper = 13;
252  repeated InnerMessage rep_inner = 12;
253
254  enum Color {
255    RED = 0;
256    GREEN = 1;
257    BLUE = 2;
258  };
259  optional Color bikeshed = 7;
260
261  optional group SomeGroup = 8 {
262    optional int32 group_field = 9;
263  }
264
265  // This field becomes [][]byte in the generated code.
266  repeated bytes rep_bytes = 10;
267
268  optional double bigfloat = 11;
269
270  extensions 100 to max;
271}
272
273message Ext {
274  extend MyMessage {
275    optional Ext more = 103;
276    optional string text = 104;
277    optional int32 number = 105;
278  }
279
280  optional string data = 1;
281}
282
283extend MyMessage {
284  repeated string greeting = 106;
285}
286
287message ComplexExtension {
288  optional int32 first = 1;
289  optional int32 second = 2;
290  repeated int32 third = 3;
291}
292
293extend OtherMessage {
294  optional ComplexExtension complex = 200;
295  repeated ComplexExtension r_complex = 201;
296}
297
298message DefaultsMessage {
299  enum DefaultsEnum {
300    ZERO = 0;
301    ONE = 1;
302    TWO = 2;
303  };
304  extensions 100 to max;
305}
306
307extend DefaultsMessage {
308  optional double no_default_double = 101;
309  optional float no_default_float = 102;
310  optional int32 no_default_int32 = 103;
311  optional int64 no_default_int64 = 104;
312  optional uint32 no_default_uint32 = 105;
313  optional uint64 no_default_uint64 = 106;
314  optional sint32 no_default_sint32 = 107;
315  optional sint64 no_default_sint64 = 108;
316  optional fixed32 no_default_fixed32 = 109;
317  optional fixed64 no_default_fixed64 = 110;
318  optional sfixed32 no_default_sfixed32 = 111;
319  optional sfixed64 no_default_sfixed64 = 112;
320  optional bool no_default_bool = 113;
321  optional string no_default_string = 114;
322  optional bytes no_default_bytes = 115;
323  optional DefaultsMessage.DefaultsEnum no_default_enum = 116;
324
325  optional double default_double = 201 [default = 3.1415];
326  optional float default_float = 202 [default = 3.14];
327  optional int32 default_int32 = 203 [default = 42];
328  optional int64 default_int64 = 204 [default = 43];
329  optional uint32 default_uint32 = 205 [default = 44];
330  optional uint64 default_uint64 = 206 [default = 45];
331  optional sint32 default_sint32 = 207 [default = 46];
332  optional sint64 default_sint64 = 208 [default = 47];
333  optional fixed32 default_fixed32 = 209 [default = 48];
334  optional fixed64 default_fixed64 = 210 [default = 49];
335  optional sfixed32 default_sfixed32 = 211 [default = 50];
336  optional sfixed64 default_sfixed64 = 212 [default = 51];
337  optional bool default_bool = 213 [default = true];
338  optional string default_string = 214 [default = "Hello, string"];
339  optional bytes default_bytes = 215 [default = "Hello, bytes"];
340  optional DefaultsMessage.DefaultsEnum default_enum = 216 [default = ONE];
341}
342
343message MyMessageSet {
344  option message_set_wire_format = true;
345  extensions 100 to max;
346}
347
348message Empty {
349}
350
351extend MyMessageSet {
352    optional Empty x201 = 201;
353    optional Empty x202 = 202;
354    optional Empty x203 = 203;
355    optional Empty x204 = 204;
356    optional Empty x205 = 205;
357    optional Empty x206 = 206;
358    optional Empty x207 = 207;
359    optional Empty x208 = 208;
360    optional Empty x209 = 209;
361    optional Empty x210 = 210;
362    optional Empty x211 = 211;
363    optional Empty x212 = 212;
364    optional Empty x213 = 213;
365    optional Empty x214 = 214;
366    optional Empty x215 = 215;
367    optional Empty x216 = 216;
368    optional Empty x217 = 217;
369    optional Empty x218 = 218;
370    optional Empty x219 = 219;
371    optional Empty x220 = 220;
372    optional Empty x221 = 221;
373    optional Empty x222 = 222;
374    optional Empty x223 = 223;
375    optional Empty x224 = 224;
376    optional Empty x225 = 225;
377    optional Empty x226 = 226;
378    optional Empty x227 = 227;
379    optional Empty x228 = 228;
380    optional Empty x229 = 229;
381    optional Empty x230 = 230;
382    optional Empty x231 = 231;
383    optional Empty x232 = 232;
384    optional Empty x233 = 233;
385    optional Empty x234 = 234;
386    optional Empty x235 = 235;
387    optional Empty x236 = 236;
388    optional Empty x237 = 237;
389    optional Empty x238 = 238;
390    optional Empty x239 = 239;
391    optional Empty x240 = 240;
392    optional Empty x241 = 241;
393    optional Empty x242 = 242;
394    optional Empty x243 = 243;
395    optional Empty x244 = 244;
396    optional Empty x245 = 245;
397    optional Empty x246 = 246;
398    optional Empty x247 = 247;
399    optional Empty x248 = 248;
400    optional Empty x249 = 249;
401    optional Empty x250 = 250;
402}
403
404message MessageList {
405  repeated group Message = 1 {
406    required string name = 2;
407    required int32 count = 3;
408  }
409}
410
411message Strings {
412  optional string string_field = 1;
413  optional bytes bytes_field = 2;
414}
415
416message Defaults {
417  enum Color {
418    RED = 0;
419    GREEN = 1;
420    BLUE = 2;
421  }
422
423  // Default-valued fields of all basic types.
424  // Same as GoTest, but copied here to make testing easier.
425  optional bool F_Bool = 1 [default=true];
426  optional int32 F_Int32 = 2 [default=32];
427  optional int64 F_Int64 = 3 [default=64];
428  optional fixed32 F_Fixed32 = 4 [default=320];
429  optional fixed64 F_Fixed64 = 5 [default=640];
430  optional uint32 F_Uint32 = 6 [default=3200];
431  optional uint64 F_Uint64 = 7 [default=6400];
432  optional float F_Float = 8 [default=314159.];
433  optional double F_Double = 9 [default=271828.];
434  optional string F_String = 10 [default="hello, \"world!\"\n"];
435  optional bytes F_Bytes = 11 [default="Bignose"];
436  optional sint32 F_Sint32 = 12 [default=-32];
437  optional sint64 F_Sint64 = 13 [default=-64];
438  optional Color F_Enum = 14 [default=GREEN];
439
440  // More fields with crazy defaults.
441  optional float F_Pinf = 15 [default=inf];
442  optional float F_Ninf = 16 [default=-inf];
443  optional float F_Nan = 17 [default=nan];
444
445  // Sub-message.
446  optional SubDefaults sub = 18;
447
448  // Redundant but explicit defaults.
449  optional string str_zero = 19 [default=""];
450}
451
452message SubDefaults {
453  optional int64 n = 1 [default=7];
454}
455
456message RepeatedEnum {
457  enum Color {
458    RED = 1;
459  }
460  repeated Color color = 1;
461}
462
463message MoreRepeated {
464  repeated bool bools = 1;
465  repeated bool bools_packed = 2 [packed=true];
466  repeated int32 ints = 3;
467  repeated int32 ints_packed = 4 [packed=true];
468  repeated int64 int64s_packed = 7 [packed=true];
469  repeated string strings = 5;
470  repeated fixed32 fixeds = 6;
471}
472
473// GroupOld and GroupNew have the same wire format.
474// GroupNew has a new field inside a group.
475
476message GroupOld {
477  optional group G = 101 {
478    optional int32 x = 2;
479  }
480}
481
482message GroupNew {
483  optional group G = 101 {
484    optional int32 x = 2;
485    optional int32 y = 3;
486  }
487}
488
489message FloatingPoint {
490  required double f = 1;
491}
492
493message MessageWithMap {
494  map<int32, string> name_mapping = 1;
495  map<sint64, FloatingPoint> msg_mapping = 2;
496  map<bool, bytes> byte_mapping = 3;
497  map<string, string> str_to_str = 4;
498}
499
500message Oneof {
501  oneof union {
502    bool F_Bool = 1;
503    int32 F_Int32 = 2;
504    int64 F_Int64 = 3;
505    fixed32 F_Fixed32 = 4;
506    fixed64 F_Fixed64 = 5;
507    uint32 F_Uint32 = 6;
508    uint64 F_Uint64 = 7;
509    float F_Float = 8;
510    double F_Double = 9;
511    string F_String = 10;
512    bytes F_Bytes = 11;
513    sint32 F_Sint32 = 12;
514    sint64 F_Sint64 = 13;
515    MyMessage.Color F_Enum = 14;
516    GoTestField F_Message = 15;
517    group F_Group = 16 {
518      optional int32 x = 17;
519    }
520    int32 F_Largest_Tag = 536870911;
521  }
522
523  oneof tormato {
524    int32 value = 100;
525  }
526}
527
528message Communique {
529  optional bool make_me_cry = 1;
530
531  // This is a oneof, called "union".
532  oneof union {
533    int32 number = 5;
534    string name = 6;
535    bytes data = 7;
536    double temp_c = 8;
537    MyMessage.Color col = 9;
538    Strings msg = 10;
539  }
540}
541