unittest_no_field_presence.proto 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // A proto file used to test a message type with no explicit field presence.
  8. edition = "2023";
  9. // Treat all fields as implicit present by default (proto3 behavior).
  10. option features.field_presence = IMPLICIT;
  11. // We want to test embedded proto2 messages, so include some proto2 types.
  12. package proto2_nofieldpresence_unittest;
  13. import "google/protobuf/unittest.proto";
  14. // This proto includes every type of field in both singular and repeated
  15. // forms.
  16. message TestAllTypes {
  17. message NestedMessage {
  18. int32 bb = 1;
  19. }
  20. enum NestedEnum {
  21. FOO = 0;
  22. BAR = 1;
  23. BAZ = 2;
  24. }
  25. // Singular
  26. // TODO: remove 'optional' labels as soon as CL 69188077 is LGTM'd to make
  27. // 'optional' optional.
  28. int32 optional_int32 = 1;
  29. int64 optional_int64 = 2;
  30. uint32 optional_uint32 = 3;
  31. uint64 optional_uint64 = 4;
  32. sint32 optional_sint32 = 5;
  33. sint64 optional_sint64 = 6;
  34. fixed32 optional_fixed32 = 7;
  35. fixed64 optional_fixed64 = 8;
  36. sfixed32 optional_sfixed32 = 9;
  37. sfixed64 optional_sfixed64 = 10;
  38. float optional_float = 11;
  39. double optional_double = 12;
  40. bool optional_bool = 13;
  41. string optional_string = 14;
  42. bytes optional_bytes = 15;
  43. NestedMessage optional_nested_message = 18;
  44. ForeignMessage optional_foreign_message = 19;
  45. protobuf_unittest.TestAllTypes optional_proto2_message = 20;
  46. NestedEnum optional_nested_enum = 21;
  47. ForeignEnum optional_foreign_enum = 22;
  48. // N.B.: proto2-enum-type fields not allowed, because their default values
  49. // might not be zero.
  50. // optional protobuf_unittest.ForeignEnum optional_proto2_enum =
  51. // 23;
  52. string optional_string_piece = 24 [ctype = STRING_PIECE];
  53. string optional_cord = 25 [ctype = CORD];
  54. NestedMessage optional_lazy_message = 30 [lazy = true];
  55. // Repeated
  56. repeated int32 repeated_int32 = 31;
  57. repeated int64 repeated_int64 = 32;
  58. repeated uint32 repeated_uint32 = 33;
  59. repeated uint64 repeated_uint64 = 34;
  60. repeated sint32 repeated_sint32 = 35;
  61. repeated sint64 repeated_sint64 = 36;
  62. repeated fixed32 repeated_fixed32 = 37;
  63. repeated fixed64 repeated_fixed64 = 38;
  64. repeated sfixed32 repeated_sfixed32 = 39;
  65. repeated sfixed64 repeated_sfixed64 = 40;
  66. repeated float repeated_float = 41;
  67. repeated double repeated_double = 42;
  68. repeated bool repeated_bool = 43;
  69. repeated string repeated_string = 44;
  70. repeated bytes repeated_bytes = 45;
  71. repeated NestedMessage repeated_nested_message = 48;
  72. repeated ForeignMessage repeated_foreign_message = 49;
  73. repeated protobuf_unittest.TestAllTypes repeated_proto2_message = 50;
  74. repeated NestedEnum repeated_nested_enum = 51;
  75. repeated ForeignEnum repeated_foreign_enum = 52;
  76. repeated string repeated_string_piece = 54 [ctype = STRING_PIECE];
  77. repeated string repeated_cord = 55 [ctype = CORD];
  78. repeated NestedMessage repeated_lazy_message = 57;
  79. oneof oneof_field {
  80. uint32 oneof_uint32 = 111;
  81. NestedMessage oneof_nested_message = 112;
  82. string oneof_string = 113;
  83. NestedEnum oneof_enum = 114;
  84. }
  85. }
  86. message TestAllMapTypes {
  87. map<int32, bytes> map_int32_bytes = 1;
  88. map<int32, ForeignEnum> map_int32_foreign_enum = 2;
  89. map<int32, ForeignMessage> map_int32_foreign_message = 3;
  90. map<int32, ExplicitForeignMessage> map_int32_explicit_foreign_message = 4;
  91. }
  92. message TestProto2Required {
  93. protobuf_unittest.TestRequired proto2 = 1;
  94. }
  95. // Define these after TestAllTypes to make sure the compiler can handle
  96. // that.
  97. message ForeignMessage {
  98. int32 c = 1;
  99. }
  100. // Same as ForeignMessage, but all fields have explicit presence.
  101. // It can be useful for testing explicit-implicit presence interop behaviour.
  102. message ExplicitForeignMessage {
  103. int32 c = 1 [features.field_presence = EXPLICIT];
  104. }
  105. enum ForeignEnum {
  106. FOREIGN_FOO = 0;
  107. FOREIGN_BAR = 1;
  108. FOREIGN_BAZ = 2;
  109. }