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