1 // Go support for Protocol Buffers - Google's data interchange format
3 // Copyright 2010 Google Inc. All rights reserved.
4 // http://code.google.com/p/goprotobuf/
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
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
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.
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.
32 // A feature-rich test file for the protocol compiler and libraries.
38 enum FOO { FOO1 = 1; };
45 required string Label = 1;
46 required string Type = 2;
50 // An enum, for completeness.
72 FUNCTION = 12; // last tag
75 // Some typical parameters
76 required KIND Kind = 1;
77 optional string Table = 2;
78 optional int32 Param = 3;
80 // Required, repeated and optional foreign fields.
81 required GoTestField RequiredField = 4;
82 repeated GoTestField RepeatedField = 5;
83 optional GoTestField OptionalField = 6;
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;
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;
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;
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];
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];
158 // Required, repeated, and optional groups.
159 required group RequiredGroup = 70 {
160 required string RequiredField = 71;
163 repeated group RepeatedGroup = 80 {
164 required string RequiredField = 81;
167 optional group OptionalGroup = 90 {
168 required string RequiredField = 91;
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.
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;
186 // For testing packed/non-packed decoder switching.
187 // A serialized instance of one should be deserializable as the other.
188 message NonPackedTest {
189 repeated int32 a = 1;
193 repeated int32 b = 1 [packed=true];
197 // Maximum possible tag number.
198 optional string last_field = 536870911;
201 // Smaller tests for ASCII formatting.
203 message InnerMessage {
204 required string host = 1;
205 optional int32 port = 2 [default=4000];
206 optional bool connected = 3;
209 message OtherMessage {
210 optional int64 key = 1;
211 optional bytes value = 2;
212 optional float weight = 3;
213 optional InnerMessage inner = 4;
217 required int32 count = 1;
218 optional string name = 2;
219 optional string quote = 3;
220 repeated string pet = 4;
221 optional InnerMessage inner = 5;
222 repeated OtherMessage others = 6;
229 optional Color bikeshed = 7;
231 optional group SomeGroup = 8 {
232 optional int32 group_field = 9;
235 // This field becomes [][]byte in the generated code.
236 repeated bytes rep_bytes = 10;
238 extensions 100 to max;
243 optional Ext more = 103;
246 optional string data = 1;
249 message MessageList {
250 repeated group Message = 1 {
251 required string name = 2;
252 required int32 count = 3;
257 optional string string_field = 1;
258 optional bytes bytes_field = 2;
268 // Default-valued fields of all basic types.
269 // Same as GoTest, but copied here to make testing easier.
270 optional bool F_Bool = 1 [default=true];
271 optional int32 F_Int32 = 2 [default=32];
272 optional int64 F_Int64 = 3 [default=64];
273 optional fixed32 F_Fixed32 = 4 [default=320];
274 optional fixed64 F_Fixed64 = 5 [default=640];
275 optional uint32 F_Uint32 = 6 [default=3200];
276 optional uint64 F_Uint64 = 7 [default=6400];
277 optional float F_Float = 8 [default=314159.];
278 optional double F_Double = 9 [default=271828.];
279 optional string F_String = 10 [default="hello, \"world!\"\n"];
280 optional bytes F_Bytes = 11 [default="Bignose"];
281 optional sint32 F_Sint32 = 12 [default=-32];
282 optional sint64 F_Sint64 = 13 [default=-64];
283 optional Color F_Enum = 14 [default=GREEN];
285 // More fields with crazy defaults.
286 optional float F_Pinf = 15 [default=inf];
287 optional float F_Ninf = 16 [default=-inf];
288 optional float F_Nan = 17 [default=nan];