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