1// Protocol Buffers - Google's data interchange format 2// Copyright 2008 Google Inc. All rights reserved. 3// 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file or at 6// https://developers.google.com/open-source/licenses/bsd 7// 8// Test schema for proto2 messages. This test schema is used by: 9// 10// - conformance tests 11 12// LINT: ALLOW_GROUPS 13 14edition = "2023"; 15 16package protobuf_test_messages.editions.proto2; 17 18option features.enum_type = CLOSED; 19option features.repeated_field_encoding = EXPANDED; 20option features.utf8_validation = NONE; 21option java_package = "com.google.protobuf_test_messages.editions.proto2"; 22option objc_class_prefix = "EditionsProto2"; 23 24// This is the default, but we specify it here explicitly. 25option optimize_for = SPEED; 26option cc_enable_arenas = true; 27 28// This proto includes every type of field in both singular and repeated 29// forms. 30// 31// Also, crucially, all messages and enums in this file are eventually 32// submessages of this message. So for example, a fuzz test of TestAllTypes 33// could trigger bugs that occur in any message type in this file. We verify 34// this stays true in a unit test. 35message TestAllTypesProto2 { 36 message NestedMessage { 37 int32 a = 1; 38 TestAllTypesProto2 corecursive = 2; 39 } 40 41 enum NestedEnum { 42 FOO = 0; 43 BAR = 1; 44 BAZ = 2; 45 NEG = -1; // Intentionally negative. 46 } 47 48 // Singular 49 int32 optional_int32 = 1; 50 int64 optional_int64 = 2; 51 uint32 optional_uint32 = 3; 52 uint64 optional_uint64 = 4; 53 sint32 optional_sint32 = 5; 54 sint64 optional_sint64 = 6; 55 fixed32 optional_fixed32 = 7; 56 fixed64 optional_fixed64 = 8; 57 sfixed32 optional_sfixed32 = 9; 58 sfixed64 optional_sfixed64 = 10; 59 float optional_float = 11; 60 double optional_double = 12; 61 bool optional_bool = 13; 62 string optional_string = 14; 63 bytes optional_bytes = 15; 64 NestedMessage optional_nested_message = 18; 65 ForeignMessageProto2 optional_foreign_message = 19; 66 NestedEnum optional_nested_enum = 21; 67 ForeignEnumProto2 optional_foreign_enum = 22; 68 string optional_string_piece = 24 [ 69 ctype = STRING_PIECE 70 ]; 71 72 string optional_cord = 25 [ 73 ctype = CORD 74 ]; 75 76 TestAllTypesProto2 recursive_message = 27; 77 78 // Repeated 79 repeated int32 repeated_int32 = 31; 80 repeated int64 repeated_int64 = 32; 81 repeated uint32 repeated_uint32 = 33; 82 repeated uint64 repeated_uint64 = 34; 83 repeated sint32 repeated_sint32 = 35; 84 repeated sint64 repeated_sint64 = 36; 85 repeated fixed32 repeated_fixed32 = 37; 86 repeated fixed64 repeated_fixed64 = 38; 87 repeated sfixed32 repeated_sfixed32 = 39; 88 repeated sfixed64 repeated_sfixed64 = 40; 89 repeated float repeated_float = 41; 90 repeated double repeated_double = 42; 91 repeated bool repeated_bool = 43; 92 repeated string repeated_string = 44; 93 repeated bytes repeated_bytes = 45; 94 repeated NestedMessage repeated_nested_message = 48; 95 repeated ForeignMessageProto2 repeated_foreign_message = 49; 96 repeated NestedEnum repeated_nested_enum = 51; 97 repeated ForeignEnumProto2 repeated_foreign_enum = 52; 98 repeated string repeated_string_piece = 54 [ 99 ctype = STRING_PIECE 100 ]; 101 102 repeated string repeated_cord = 55 [ 103 ctype = CORD 104 ]; 105 106 // Packed 107 repeated int32 packed_int32 = 75 [ 108 features.repeated_field_encoding = PACKED 109 ]; 110 111 repeated int64 packed_int64 = 76 [ 112 features.repeated_field_encoding = PACKED 113 ]; 114 115 repeated uint32 packed_uint32 = 77 [ 116 features.repeated_field_encoding = PACKED 117 ]; 118 119 repeated uint64 packed_uint64 = 78 [ 120 features.repeated_field_encoding = PACKED 121 ]; 122 123 repeated sint32 packed_sint32 = 79 [ 124 features.repeated_field_encoding = PACKED 125 ]; 126 127 repeated sint64 packed_sint64 = 80 [ 128 features.repeated_field_encoding = PACKED 129 ]; 130 131 repeated fixed32 packed_fixed32 = 81 [ 132 features.repeated_field_encoding = PACKED 133 ]; 134 135 repeated fixed64 packed_fixed64 = 82 [ 136 features.repeated_field_encoding = PACKED 137 ]; 138 139 repeated sfixed32 packed_sfixed32 = 83 [ 140 features.repeated_field_encoding = PACKED 141 ]; 142 143 repeated sfixed64 packed_sfixed64 = 84 [ 144 features.repeated_field_encoding = PACKED 145 ]; 146 147 repeated float packed_float = 85 [ 148 features.repeated_field_encoding = PACKED 149 ]; 150 151 repeated double packed_double = 86 [ 152 features.repeated_field_encoding = PACKED 153 ]; 154 155 repeated bool packed_bool = 87 [ 156 features.repeated_field_encoding = PACKED 157 ]; 158 159 repeated NestedEnum packed_nested_enum = 88 [ 160 features.repeated_field_encoding = PACKED 161 ]; 162 163 // Unpacked 164 repeated int32 unpacked_int32 = 89; 165 repeated int64 unpacked_int64 = 90; 166 repeated uint32 unpacked_uint32 = 91; 167 repeated uint64 unpacked_uint64 = 92; 168 repeated sint32 unpacked_sint32 = 93; 169 repeated sint64 unpacked_sint64 = 94; 170 repeated fixed32 unpacked_fixed32 = 95; 171 repeated fixed64 unpacked_fixed64 = 96; 172 repeated sfixed32 unpacked_sfixed32 = 97; 173 repeated sfixed64 unpacked_sfixed64 = 98; 174 repeated float unpacked_float = 99; 175 repeated double unpacked_double = 100; 176 repeated bool unpacked_bool = 101; 177 repeated NestedEnum unpacked_nested_enum = 102; 178 179 // Map 180 map<int32, int32> map_int32_int32 = 56; 181 map<int64, int64> map_int64_int64 = 57; 182 map<uint32, uint32> map_uint32_uint32 = 58; 183 map<uint64, uint64> map_uint64_uint64 = 59; 184 map<sint32, sint32> map_sint32_sint32 = 60; 185 map<sint64, sint64> map_sint64_sint64 = 61; 186 map<fixed32, fixed32> map_fixed32_fixed32 = 62; 187 map<fixed64, fixed64> map_fixed64_fixed64 = 63; 188 map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 64; 189 map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 65; 190 map<int32, float> map_int32_float = 66; 191 map<int32, double> map_int32_double = 67; 192 map<bool, bool> map_bool_bool = 68; 193 map<string, string> map_string_string = 69; 194 map<string, bytes> map_string_bytes = 70; 195 map<string, NestedMessage> map_string_nested_message = 71; 196 map<string, ForeignMessageProto2> map_string_foreign_message = 72; 197 map<string, NestedEnum> map_string_nested_enum = 73; 198 map<string, ForeignEnumProto2> map_string_foreign_enum = 74; 199 200 oneof oneof_field { 201 uint32 oneof_uint32 = 111; 202 NestedMessage oneof_nested_message = 112; 203 string oneof_string = 113; 204 bytes oneof_bytes = 114; 205 bool oneof_bool = 115; 206 uint64 oneof_uint64 = 116; 207 float oneof_float = 117; 208 double oneof_double = 118; 209 NestedEnum oneof_enum = 119; 210 } 211 212 // extensions 213 extensions 120 to 200; 214 215 // groups 216 message Data { 217 int32 group_int32 = 202; 218 uint32 group_uint32 = 203; 219 } 220 221 Data data = 201 [ 222 features.message_encoding = DELIMITED 223 ]; 224 225 message MultiWordGroupField { 226 int32 group_int32 = 205; 227 uint32 group_uint32 = 206; 228 } 229 230 MultiWordGroupField multiwordgroupfield = 204 [ 231 features.message_encoding = DELIMITED 232 ]; 233 234 // default values 235 int32 default_int32 = 241 [ 236 default = -123456789 237 ]; 238 239 int64 default_int64 = 242 [ 240 default = -9123456789123456789 241 ]; 242 243 uint32 default_uint32 = 243 [ 244 default = 2123456789 245 ]; 246 247 uint64 default_uint64 = 244 [ 248 default = 10123456789123456789 249 ]; 250 251 sint32 default_sint32 = 245 [ 252 default = -123456789 253 ]; 254 255 sint64 default_sint64 = 246 [ 256 default = -9123456789123456789 257 ]; 258 259 fixed32 default_fixed32 = 247 [ 260 default = 2123456789 261 ]; 262 263 fixed64 default_fixed64 = 248 [ 264 default = 10123456789123456789 265 ]; 266 267 sfixed32 default_sfixed32 = 249 [ 268 default = -123456789 269 ]; 270 271 sfixed64 default_sfixed64 = 250 [ 272 default = -9123456789123456789 273 ]; 274 275 float default_float = 251 [ 276 default = 9e9 277 ]; 278 279 double default_double = 252 [ 280 default = 7e22 281 ]; 282 283 bool default_bool = 253 [ 284 default = true 285 ]; 286 287 string default_string = 254 [ 288 default = "Rosebud" 289 ]; 290 291 bytes default_bytes = 255 [ 292 default = "joshua" 293 ]; 294 295 // Test field-name-to-JSON-name convention. 296 // (protobuf says names can be any valid C/C++ identifier.) 297 int32 fieldname1 = 401; 298 int32 field_name2 = 402; 299 int32 _field_name3 = 403; 300 int32 field__name4_ = 404; 301 int32 field0name5 = 405; 302 int32 field_0_name6 = 406; 303 int32 fieldName7 = 407; 304 int32 FieldName8 = 408; 305 int32 field_Name9 = 409; 306 int32 Field_Name10 = 410; 307 int32 FIELD_NAME11 = 411; 308 int32 FIELD_name12 = 412; 309 int32 __field_name13 = 413; 310 int32 __Field_name14 = 414; 311 int32 field__name15 = 415; 312 int32 field__Name16 = 416; 313 int32 field_name17__ = 417; 314 int32 Field_name18__ = 418; 315 316 // Reserved for unknown fields test. 317 reserved 1000 to 9999; 318 319 // message_set test case. 320 message MessageSetCorrect { 321 option message_set_wire_format = true; 322 323 extensions 4 to max; 324 } 325 326 message MessageSetCorrectExtension1 { 327 extend MessageSetCorrect { 328 MessageSetCorrectExtension1 message_set_extension = 1547769; 329 } 330 331 string str = 25; 332 } 333 334 message MessageSetCorrectExtension2 { 335 extend MessageSetCorrect { 336 MessageSetCorrectExtension2 message_set_extension = 4135312; 337 } 338 339 int32 i = 9; 340 } 341} 342 343message ForeignMessageProto2 { 344 int32 c = 1; 345} 346 347enum ForeignEnumProto2 { 348 FOREIGN_FOO = 0; 349 FOREIGN_BAR = 1; 350 FOREIGN_BAZ = 2; 351} 352 353extend TestAllTypesProto2 { 354 int32 extension_int32 = 120; 355} 356 357extend TestAllTypesProto2 { 358 GroupField groupfield = 121 [ 359 features.message_encoding = DELIMITED 360 ]; 361} 362 363message GroupField { 364 int32 group_int32 = 122; 365 uint32 group_uint32 = 123; 366} 367 368message UnknownToTestAllTypes { 369 int32 optional_int32 = 1001; 370 string optional_string = 1002; 371 ForeignMessageProto2 nested_message = 1003; 372 373 message OptionalGroup { 374 int32 a = 1; 375 } 376 377 OptionalGroup optionalgroup = 1004 [ 378 features.message_encoding = DELIMITED 379 ]; 380 381 bool optional_bool = 1006; 382 repeated int32 repeated_int32 = 1011; 383} 384 385message NullHypothesisProto2 { 386} 387 388message EnumOnlyProto2 { 389 enum Bool { 390 kFalse = 0; 391 kTrue = 1; 392 } 393} 394 395message OneStringProto2 { 396 string data = 1; 397} 398 399message ProtoWithKeywords { 400 int32 inline = 1; 401 string concept = 2; 402 repeated string requires = 3; 403} 404 405message TestAllRequiredTypesProto2 { 406 message NestedMessage { 407 int32 a = 1 [ 408 features.field_presence = LEGACY_REQUIRED 409 ]; 410 411 TestAllRequiredTypesProto2 corecursive = 2 [ 412 features.field_presence = LEGACY_REQUIRED 413 ]; 414 415 TestAllRequiredTypesProto2 optional_corecursive = 3; 416 } 417 418 enum NestedEnum { 419 FOO = 0; 420 BAR = 1; 421 BAZ = 2; 422 NEG = -1; // Intentionally negative. 423 } 424 425 // Singular 426 int32 required_int32 = 1 [ 427 features.field_presence = LEGACY_REQUIRED 428 ]; 429 430 int64 required_int64 = 2 [ 431 features.field_presence = LEGACY_REQUIRED 432 ]; 433 434 uint32 required_uint32 = 3 [ 435 features.field_presence = LEGACY_REQUIRED 436 ]; 437 438 uint64 required_uint64 = 4 [ 439 features.field_presence = LEGACY_REQUIRED 440 ]; 441 442 sint32 required_sint32 = 5 [ 443 features.field_presence = LEGACY_REQUIRED 444 ]; 445 446 sint64 required_sint64 = 6 [ 447 features.field_presence = LEGACY_REQUIRED 448 ]; 449 450 fixed32 required_fixed32 = 7 [ 451 features.field_presence = LEGACY_REQUIRED 452 ]; 453 454 fixed64 required_fixed64 = 8 [ 455 features.field_presence = LEGACY_REQUIRED 456 ]; 457 458 sfixed32 required_sfixed32 = 9 [ 459 features.field_presence = LEGACY_REQUIRED 460 ]; 461 462 sfixed64 required_sfixed64 = 10 [ 463 features.field_presence = LEGACY_REQUIRED 464 ]; 465 466 float required_float = 11 [ 467 features.field_presence = LEGACY_REQUIRED 468 ]; 469 470 double required_double = 12 [ 471 features.field_presence = LEGACY_REQUIRED 472 ]; 473 474 bool required_bool = 13 [ 475 features.field_presence = LEGACY_REQUIRED 476 ]; 477 478 string required_string = 14 [ 479 features.field_presence = LEGACY_REQUIRED 480 ]; 481 482 bytes required_bytes = 15 [ 483 features.field_presence = LEGACY_REQUIRED 484 ]; 485 486 NestedMessage required_nested_message = 18 [ 487 features.field_presence = LEGACY_REQUIRED 488 ]; 489 490 ForeignMessageProto2 required_foreign_message = 19 [ 491 features.field_presence = LEGACY_REQUIRED 492 ]; 493 494 NestedEnum required_nested_enum = 21 [ 495 features.field_presence = LEGACY_REQUIRED 496 ]; 497 498 ForeignEnumProto2 required_foreign_enum = 22 [ 499 features.field_presence = LEGACY_REQUIRED 500 ]; 501 502 string required_string_piece = 24 [ 503 features.field_presence = LEGACY_REQUIRED, 504 ctype = STRING_PIECE 505 ]; 506 507 string required_cord = 25 [ 508 features.field_presence = LEGACY_REQUIRED, 509 ctype = CORD 510 ]; 511 512 TestAllRequiredTypesProto2 recursive_message = 27 [ 513 features.field_presence = LEGACY_REQUIRED 514 ]; 515 516 TestAllRequiredTypesProto2 optional_recursive_message = 28; 517 518 // extensions 519 extensions 120 to 200; 520 521 // groups 522 message Data { 523 int32 group_int32 = 202 [ 524 features.field_presence = LEGACY_REQUIRED 525 ]; 526 527 uint32 group_uint32 = 203 [ 528 features.field_presence = LEGACY_REQUIRED 529 ]; 530 } 531 532 Data data = 201 [ 533 features.field_presence = LEGACY_REQUIRED, 534 features.message_encoding = DELIMITED 535 ]; 536 537 // default values 538 int32 default_int32 = 241 [ 539 features.field_presence = LEGACY_REQUIRED, 540 default = -123456789 541 ]; 542 543 int64 default_int64 = 242 [ 544 features.field_presence = LEGACY_REQUIRED, 545 default = -9123456789123456789 546 ]; 547 548 uint32 default_uint32 = 243 [ 549 features.field_presence = LEGACY_REQUIRED, 550 default = 2123456789 551 ]; 552 553 uint64 default_uint64 = 244 [ 554 features.field_presence = LEGACY_REQUIRED, 555 default = 10123456789123456789 556 ]; 557 558 sint32 default_sint32 = 245 [ 559 features.field_presence = LEGACY_REQUIRED, 560 default = -123456789 561 ]; 562 563 sint64 default_sint64 = 246 [ 564 features.field_presence = LEGACY_REQUIRED, 565 default = -9123456789123456789 566 ]; 567 568 fixed32 default_fixed32 = 247 [ 569 features.field_presence = LEGACY_REQUIRED, 570 default = 2123456789 571 ]; 572 573 fixed64 default_fixed64 = 248 [ 574 features.field_presence = LEGACY_REQUIRED, 575 default = 10123456789123456789 576 ]; 577 578 sfixed32 default_sfixed32 = 249 [ 579 features.field_presence = LEGACY_REQUIRED, 580 default = -123456789 581 ]; 582 583 sfixed64 default_sfixed64 = 250 [ 584 features.field_presence = LEGACY_REQUIRED, 585 default = -9123456789123456789 586 ]; 587 588 float default_float = 251 [ 589 features.field_presence = LEGACY_REQUIRED, 590 default = 9e9 591 ]; 592 593 double default_double = 252 [ 594 features.field_presence = LEGACY_REQUIRED, 595 default = 7e22 596 ]; 597 598 bool default_bool = 253 [ 599 features.field_presence = LEGACY_REQUIRED, 600 default = true 601 ]; 602 603 string default_string = 254 [ 604 features.field_presence = LEGACY_REQUIRED, 605 default = "Rosebud" 606 ]; 607 608 bytes default_bytes = 255 [ 609 features.field_presence = LEGACY_REQUIRED, 610 default = "joshua" 611 ]; 612 613 // Reserved for unknown fields test. 614 reserved 1000 to 9999; 615 616 // message_set test case. 617 message MessageSetCorrect { 618 option message_set_wire_format = true; 619 620 extensions 4 to max; 621 } 622 623 message MessageSetCorrectExtension1 { 624 extend MessageSetCorrect { 625 MessageSetCorrectExtension1 message_set_extension = 1547769; 626 } 627 628 string str = 25 [ 629 features.field_presence = LEGACY_REQUIRED 630 ]; 631 } 632 633 message MessageSetCorrectExtension2 { 634 extend MessageSetCorrect { 635 MessageSetCorrectExtension2 message_set_extension = 4135312; 636 } 637 638 int32 i = 9 [ 639 features.field_presence = LEGACY_REQUIRED 640 ]; 641 } 642} 643