unittest_proto3_optional.proto 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. syntax = "proto3";
  8. package protobuf_unittest;
  9. import "google/protobuf/descriptor.proto";
  10. option csharp_namespace = "ProtobufUnittest";
  11. option java_multiple_files = true;
  12. option java_package = "com.google.protobuf.testing.proto";
  13. message TestProto3Optional {
  14. message NestedMessage {
  15. // The field name "b" fails to compile in proto1 because it conflicts with
  16. // a local variable named "b" in one of the generated methods. Doh.
  17. // This file needs to compile in proto1 to test backwards-compatibility.
  18. optional int32 bb = 1;
  19. }
  20. enum NestedEnum {
  21. UNSPECIFIED = 0;
  22. FOO = 1;
  23. BAR = 2;
  24. BAZ = 3;
  25. NEG = -1; // Intentionally negative.
  26. }
  27. // Singular
  28. optional int32 optional_int32 = 1;
  29. optional int64 optional_int64 = 2;
  30. optional uint32 optional_uint32 = 3;
  31. optional uint64 optional_uint64 = 4;
  32. optional sint32 optional_sint32 = 5;
  33. optional sint64 optional_sint64 = 6;
  34. optional fixed32 optional_fixed32 = 7;
  35. optional fixed64 optional_fixed64 = 8;
  36. optional sfixed32 optional_sfixed32 = 9;
  37. optional sfixed64 optional_sfixed64 = 10;
  38. optional float optional_float = 11;
  39. optional double optional_double = 12;
  40. optional bool optional_bool = 13;
  41. optional string optional_string = 14;
  42. optional bytes optional_bytes = 15;
  43. optional string optional_cord = 16 [ctype = CORD];
  44. optional NestedMessage optional_nested_message = 18;
  45. optional NestedMessage lazy_nested_message = 19 [lazy = true];
  46. optional NestedEnum optional_nested_enum = 21;
  47. // Add some non-optional fields to verify we can mix them.
  48. int32 singular_int32 = 22;
  49. int64 singular_int64 = 23;
  50. }
  51. message TestProto3OptionalMessage {
  52. message NestedMessage {
  53. string s = 1;
  54. }
  55. NestedMessage nested_message = 1;
  56. optional NestedMessage optional_nested_message = 2;
  57. }
  58. message Proto3OptionalExtensions {
  59. option (protobuf_unittest.Proto3OptionalExtensions.ext_no_optional) = 8;
  60. option (protobuf_unittest.Proto3OptionalExtensions.ext_with_optional) = 16;
  61. extend google.protobuf.MessageOptions {
  62. int32 ext_no_optional = 355886728;
  63. optional int32 ext_with_optional = 355886729;
  64. }
  65. }