Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 1 | // Copyright 2019 The Go Authors. All rights reserved. |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Test Protobuf definitions with proto2 syntax. |
| 6 | syntax = "proto2"; |
| 7 | |
| 8 | package pb2; |
Joe Tsai | 94e730b | 2020-01-10 23:31:25 -0800 | [diff] [blame] | 9 | option go_package = "google.golang.org/protobuf/internal/testprotos/textpb2"; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 10 | |
| 11 | import "google/protobuf/any.proto"; |
| 12 | import "google/protobuf/empty.proto"; |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 13 | import "google/protobuf/field_mask.proto"; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 14 | import "google/protobuf/duration.proto"; |
| 15 | import "google/protobuf/struct.proto"; |
| 16 | import "google/protobuf/timestamp.proto"; |
| 17 | import "google/protobuf/wrappers.proto"; |
| 18 | |
| 19 | // Scalars contains optional scalar fields. |
| 20 | message Scalars { |
| 21 | optional bool opt_bool = 1; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 22 | optional int32 opt_int32 = 2; |
| 23 | optional int64 opt_int64 = 3; |
| 24 | optional uint32 opt_uint32 = 4; |
| 25 | optional uint64 opt_uint64 = 5; |
| 26 | optional sint32 opt_sint32 = 6; |
| 27 | optional sint64 opt_sint64 = 7; |
| 28 | optional fixed32 opt_fixed32 = 8; |
| 29 | optional fixed64 opt_fixed64 = 9; |
| 30 | optional sfixed32 opt_sfixed32 = 10; |
| 31 | optional sfixed64 opt_sfixed64 = 11; |
| 32 | |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 33 | // Textproto marshal outputs fields in the same order as this proto |
| 34 | // definition regardless of field number. Following fields are intended to |
| 35 | // test that assumption. |
| 36 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 37 | optional float opt_float = 20; |
| 38 | optional double opt_double = 21; |
| 39 | |
| 40 | optional bytes opt_bytes = 14; |
| 41 | optional string opt_string = 13; |
| 42 | } |
| 43 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 44 | enum Enum { |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 45 | ONE = 1; |
| 46 | TWO = 2; |
| 47 | TEN = 10; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | // Message contains enum fields. |
| 51 | message Enums { |
| 52 | optional Enum opt_enum = 1; |
| 53 | repeated Enum rpt_enum = 2; |
| 54 | |
| 55 | enum NestedEnum { |
| 56 | UNO = 1; |
| 57 | DOS = 2; |
| 58 | DIEZ = 10; |
| 59 | } |
| 60 | optional NestedEnum opt_nested_enum = 3; |
| 61 | repeated NestedEnum rpt_nested_enum = 4; |
| 62 | } |
| 63 | |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 64 | // Message contains repeated fields. |
| 65 | message Repeats { |
| 66 | repeated bool rpt_bool = 1; |
| 67 | repeated int32 rpt_int32 = 2; |
| 68 | repeated int64 rpt_int64 = 3; |
| 69 | repeated uint32 rpt_uint32 = 4; |
| 70 | repeated uint64 rpt_uint64 = 5; |
| 71 | repeated float rpt_float = 6; |
| 72 | repeated double rpt_double = 7; |
| 73 | repeated string rpt_string = 8; |
| 74 | repeated bytes rpt_bytes = 9; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | // Message type used as submessage. |
| 78 | message Nested { |
| 79 | optional string opt_string = 1; |
| 80 | optional Nested opt_nested = 2; |
| 81 | } |
| 82 | |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 83 | // Message contains message and group fields. |
| 84 | message Nests { |
| 85 | optional Nested opt_nested = 1; |
| 86 | optional group OptGroup = 2 { |
| 87 | optional string opt_string = 1; |
| 88 | optional Nested opt_nested = 2; |
| 89 | |
| 90 | optional group OptNestedGroup = 3 { |
| 91 | optional fixed32 opt_fixed32 = 1; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | repeated Nested rpt_nested = 4; |
| 96 | repeated group RptGroup = 5 { |
| 97 | repeated string rpt_string = 1; |
| 98 | } |
| 99 | |
| 100 | reserved "reserved_field"; |
| 101 | } |
| 102 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 103 | // Message contains required fields. |
| 104 | message Requireds { |
| 105 | required bool req_bool = 1; |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 106 | required sfixed64 req_sfixed64 = 2; |
| 107 | required double req_double = 3; |
| 108 | required string req_string = 4; |
| 109 | required Enum req_enum = 5; |
| 110 | required Nested req_nested = 6; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 113 | // Message contains both required and optional fields. |
| 114 | message PartialRequired { |
| 115 | required string req_string = 1; |
| 116 | optional string opt_string = 2; |
| 117 | } |
| 118 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 119 | // Following messages are for testing required field nested in optional, repeated and map fields. |
Herbie Ong | cf25308 | 2018-12-17 17:13:07 -0800 | [diff] [blame] | 120 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 121 | message NestedWithRequired { |
| 122 | required string req_string = 1; |
| 123 | } |
| 124 | |
| 125 | message IndirectRequired { |
| 126 | optional NestedWithRequired opt_nested = 1; |
| 127 | repeated NestedWithRequired rpt_nested = 2; |
| 128 | map<string, NestedWithRequired> str_to_nested = 3; |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 129 | |
| 130 | oneof union { |
| 131 | NestedWithRequired oneof_nested = 4; |
| 132 | } |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Herbie Ong | cf25308 | 2018-12-17 17:13:07 -0800 | [diff] [blame] | 135 | // Following messages are for testing extensions. |
| 136 | |
| 137 | message Extensions { |
| 138 | optional string opt_string = 1; |
| 139 | extensions 20 to 100; |
| 140 | optional bool opt_bool = 101; |
| 141 | optional int32 opt_int32 = 2; |
| 142 | } |
| 143 | |
| 144 | extend Extensions { |
| 145 | optional bool opt_ext_bool = 21; |
| 146 | optional string opt_ext_string = 22; |
| 147 | optional Enum opt_ext_enum = 23; |
| 148 | optional Nested opt_ext_nested = 24; |
Herbie Ong | 09b28a9 | 2019-04-03 15:42:41 -0700 | [diff] [blame] | 149 | optional PartialRequired opt_ext_partial = 25; |
Herbie Ong | cf25308 | 2018-12-17 17:13:07 -0800 | [diff] [blame] | 150 | |
| 151 | repeated fixed32 rpt_ext_fixed32 = 31; |
| 152 | repeated Enum rpt_ext_enum = 32; |
| 153 | repeated Nested rpt_ext_nested = 33; |
| 154 | } |
| 155 | |
| 156 | message ExtensionsContainer { |
| 157 | extend Extensions { |
| 158 | optional bool opt_ext_bool = 51; |
| 159 | optional string opt_ext_string = 52; |
| 160 | optional Enum opt_ext_enum = 53; |
| 161 | optional Nested opt_ext_nested = 54; |
Herbie Ong | 09b28a9 | 2019-04-03 15:42:41 -0700 | [diff] [blame] | 162 | optional PartialRequired opt_ext_partial = 55; |
Herbie Ong | cf25308 | 2018-12-17 17:13:07 -0800 | [diff] [blame] | 163 | |
| 164 | repeated string rpt_ext_string = 61; |
| 165 | repeated Enum rpt_ext_enum = 62; |
| 166 | repeated Nested rpt_ext_nested = 63; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // Following messages are for testing MessageSet. |
| 171 | |
| 172 | message MessageSet { |
| 173 | option message_set_wire_format = true; |
| 174 | |
| 175 | extensions 4 to max; |
| 176 | } |
| 177 | |
| 178 | message MessageSetExtension { |
| 179 | optional string opt_string = 1; |
| 180 | |
| 181 | extend MessageSet { |
| 182 | optional MessageSetExtension message_set_extension = 10; |
| 183 | optional MessageSetExtension not_message_set_extension = 20; |
| 184 | optional Nested ext_nested = 30; |
| 185 | } |
| 186 | } |
| 187 | |
Herbie Ong | 6470ea6 | 2019-01-07 18:56:57 -0800 | [diff] [blame] | 188 | message FakeMessageSet { |
| 189 | extensions 4 to max; |
| 190 | } |
| 191 | |
| 192 | message FakeMessageSetExtension { |
| 193 | optional string opt_string = 1; |
| 194 | |
| 195 | extend FakeMessageSet { |
| 196 | optional FakeMessageSetExtension message_set_extension = 10; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | extend MessageSet { |
| 201 | optional FakeMessageSetExtension message_set_extension = 50; |
| 202 | } |
| 203 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 204 | // Message contains well-known type fields. |
| 205 | message KnownTypes { |
| 206 | optional google.protobuf.BoolValue opt_bool = 1; |
| 207 | optional google.protobuf.Int32Value opt_int32 = 2; |
| 208 | optional google.protobuf.Int64Value opt_int64 = 3; |
| 209 | optional google.protobuf.UInt32Value opt_uint32 = 4; |
| 210 | optional google.protobuf.UInt64Value opt_uint64 = 5; |
| 211 | optional google.protobuf.FloatValue opt_float = 6; |
| 212 | optional google.protobuf.DoubleValue opt_double = 7; |
| 213 | optional google.protobuf.StringValue opt_string = 8; |
| 214 | optional google.protobuf.BytesValue opt_bytes = 9; |
| 215 | |
| 216 | optional google.protobuf.Duration opt_duration = 20; |
| 217 | optional google.protobuf.Timestamp opt_timestamp = 21; |
Herbie Ong | 300b9fe | 2019-03-29 15:42:20 -0700 | [diff] [blame] | 218 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 219 | optional google.protobuf.Struct opt_struct = 25; |
| 220 | optional google.protobuf.ListValue opt_list = 26; |
| 221 | optional google.protobuf.Value opt_value = 27; |
Herbie Ong | 300b9fe | 2019-03-29 15:42:20 -0700 | [diff] [blame] | 222 | optional google.protobuf.NullValue opt_null = 28; |
| 223 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 224 | optional google.protobuf.Empty opt_empty = 30; |
| 225 | optional google.protobuf.Any opt_any = 32; |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 226 | |
| 227 | optional google.protobuf.FieldMask opt_fieldmask = 40; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 228 | } |