| 1 |
// Copyright 2024 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 |
// Test Protobuf definitions with proto2 syntax. |
| 6 |
edition = "2023"; |
| 7 |
|
| 8 |
package opaque.pbeditions; |
| 9 |
|
| 10 |
import "google/protobuf/any.proto"; |
| 11 |
import "google/protobuf/duration.proto"; |
| 12 |
import "google/protobuf/empty.proto"; |
| 13 |
import "google/protobuf/field_mask.proto"; |
| 14 |
import "google/protobuf/struct.proto"; |
| 15 |
import "google/protobuf/timestamp.proto"; |
| 16 |
import "google/protobuf/wrappers.proto"; |
| 17 |
|
| 18 |
option go_package = "google.golang.org/protobuf/internal/testprotos/textpbeditions/textpbeditions_opaque"; |
| 19 |
import "google/protobuf/go_features.proto"; |
| 20 |
option features.(pb.go).api_level = API_OPAQUE; |
| 21 |
option features.enum_type = CLOSED; |
| 22 |
option features.utf8_validation = NONE; |
| 23 |
|
| 24 |
// Scalars contains scalar fields. |
| 25 |
message Scalars { |
| 26 |
bool opt_bool = 1; |
| 27 |
int32 opt_int32 = 2; |
| 28 |
int64 opt_int64 = 3; |
| 29 |
uint32 opt_uint32 = 4; |
| 30 |
uint64 opt_uint64 = 5; |
| 31 |
sint32 opt_sint32 = 6; |
| 32 |
sint64 opt_sint64 = 7; |
| 33 |
fixed32 opt_fixed32 = 8; |
| 34 |
fixed64 opt_fixed64 = 9; |
| 35 |
sfixed32 opt_sfixed32 = 10; |
| 36 |
sfixed64 opt_sfixed64 = 11; |
| 37 |
|
| 38 |
// Textproto marshal outputs fields in the same order as this proto |
| 39 |
// definition regardless of field number. Following fields are intended to |
| 40 |
// test that assumption. |
| 41 |
|
| 42 |
float opt_float = 20; |
| 43 |
double opt_double = 21; |
| 44 |
|
| 45 |
bytes opt_bytes = 14; |
| 46 |
string opt_string = 13; |
| 47 |
} |
| 48 |
|
| 49 |
// ImplicitScalars contains scalar field types with implicit field_presence |
| 50 |
message ImplicitScalars { |
| 51 |
bool s_bool = 1 [features.field_presence = IMPLICIT]; |
| 52 |
int32 s_int32 = 2 [features.field_presence = IMPLICIT]; |
| 53 |
int64 s_int64 = 3 [features.field_presence = IMPLICIT]; |
| 54 |
uint32 s_uint32 = 4 [features.field_presence = IMPLICIT]; |
| 55 |
uint64 s_uint64 = 5 [features.field_presence = IMPLICIT]; |
| 56 |
sint32 s_sint32 = 6 [features.field_presence = IMPLICIT]; |
| 57 |
sint64 s_sint64 = 7 [features.field_presence = IMPLICIT]; |
| 58 |
fixed32 s_fixed32 = 8 [features.field_presence = IMPLICIT]; |
| 59 |
fixed64 s_fixed64 = 9 [features.field_presence = IMPLICIT]; |
| 60 |
sfixed32 s_sfixed32 = 10 [features.field_presence = IMPLICIT]; |
| 61 |
sfixed64 s_sfixed64 = 11 [features.field_presence = IMPLICIT]; |
| 62 |
|
| 63 |
// Textproto marshal outputs fields in the same order as this proto |
| 64 |
// definition regardless of field number. Following fields are intended to |
| 65 |
// test that assumption. |
| 66 |
|
| 67 |
float s_float = 20 [features.field_presence = IMPLICIT]; |
| 68 |
double s_double = 21 [features.field_presence = IMPLICIT]; |
| 69 |
|
| 70 |
bytes s_bytes = 14 [features.field_presence = IMPLICIT]; |
| 71 |
string s_string = 13 [features.field_presence = IMPLICIT]; |
| 72 |
} |
| 73 |
|
| 74 |
enum Enum { |
| 75 |
ONE = 1; |
| 76 |
TWO = 2; |
| 77 |
TEN = 10; |
| 78 |
} |
| 79 |
|
| 80 |
enum OpenEnum { |
| 81 |
option features.enum_type = OPEN; |
| 82 |
|
| 83 |
UNKNOWN = 0; |
| 84 |
EINS = 1; |
| 85 |
ZWEI = 2; |
| 86 |
ZEHN = 10; |
| 87 |
} |
| 88 |
|
| 89 |
message UTF8Validated { |
| 90 |
string validated_string = 1 |
| 91 |
[features.utf8_validation = VERIFY, features.field_presence = IMPLICIT]; |
| 92 |
} |
| 93 |
|
| 94 |
message NestsUTF8Validated { |
| 95 |
UTF8Validated validated_message = 1; |
| 96 |
} |
| 97 |
|
| 98 |
// Message contains enum fields. |
| 99 |
message Enums { |
| 100 |
Enum opt_enum = 1; |
| 101 |
repeated Enum rpt_enum = 2; |
| 102 |
OpenEnum implicit_enum = 5 [features.field_presence = IMPLICIT]; |
| 103 |
|
| 104 |
enum NestedEnum { |
| 105 |
UNO = 1; |
| 106 |
DOS = 2; |
| 107 |
DIEZ = 10; |
| 108 |
} |
| 109 |
enum NestedOpenEnum { |
| 110 |
option features.enum_type = OPEN; |
| 111 |
|
| 112 |
UNKNOWN = 0; |
| 113 |
EINS = 1; |
| 114 |
ZWEI = 2; |
| 115 |
ZEHN = 10; |
| 116 |
} |
| 117 |
NestedEnum opt_nested_enum = 3; |
| 118 |
repeated NestedEnum rpt_nested_enum = 4; |
| 119 |
NestedOpenEnum implicit_nested_enum = 6 [features.field_presence = IMPLICIT]; |
| 120 |
} |
| 121 |
|
| 122 |
// Message contains repeated fields. |
| 123 |
message Repeats { |
| 124 |
repeated bool rpt_bool = 1; |
| 125 |
repeated int32 rpt_int32 = 2; |
| 126 |
repeated int64 rpt_int64 = 3; |
| 127 |
repeated uint32 rpt_uint32 = 4; |
| 128 |
repeated uint64 rpt_uint64 = 5; |
| 129 |
repeated float rpt_float = 6; |
| 130 |
repeated double rpt_double = 7; |
| 131 |
repeated string rpt_string = 8; |
| 132 |
repeated bytes rpt_bytes = 9; |
| 133 |
} |
| 134 |
|
| 135 |
// Message contains map fields. |
| 136 |
message Maps { |
| 137 |
map<int32, string> int32_to_str = 1; |
| 138 |
map<string, Nested> str_to_nested = 4; |
| 139 |
} |
| 140 |
|
| 141 |
// Message type used as submessage. |
| 142 |
message Nested { |
| 143 |
string opt_string = 1; |
| 144 |
Nested opt_nested = 2; |
| 145 |
} |
| 146 |
|
| 147 |
// Message contains message and group fields. |
| 148 |
message Nests { |
| 149 |
Nested opt_nested = 1; |
| 150 |
message OptGroup { |
| 151 |
string opt_string = 1; |
| 152 |
Nested opt_nested = 2; |
| 153 |
|
| 154 |
message OptNestedGroup { |
| 155 |
fixed32 opt_fixed32 = 1; |
| 156 |
} |
| 157 |
OptNestedGroup optnestedgroup = 3 [features.message_encoding = DELIMITED]; |
| 158 |
OptNestedGroup nested_delimited_field = 4 |
| 159 |
[features.message_encoding = DELIMITED]; |
| 160 |
} |
| 161 |
OptGroup optgroup = 2 [features.message_encoding = DELIMITED]; |
| 162 |
OptGroup delimited_field = 3 [features.message_encoding = DELIMITED]; |
| 163 |
|
| 164 |
repeated Nested rpt_nested = 4; |
| 165 |
message RptGroup { |
| 166 |
repeated string rpt_string = 1; |
| 167 |
} |
| 168 |
|
| 169 |
repeated RptGroup rptgroup = 5 [ |
| 170 |
features.message_encoding = DELIMITED, |
| 171 |
features.repeated_field_encoding = EXPANDED |
| 172 |
]; |
| 173 |
|
| 174 |
reserved reserved_field; |
| 175 |
} |
| 176 |
|
| 177 |
// Message contains required fields. |
| 178 |
message Requireds { |
| 179 |
bool req_bool = 1 [features.field_presence = LEGACY_REQUIRED]; |
| 180 |
sfixed64 req_sfixed64 = 2 [features.field_presence = LEGACY_REQUIRED]; |
| 181 |
double req_double = 3 [features.field_presence = LEGACY_REQUIRED]; |
| 182 |
string req_string = 4 [features.field_presence = LEGACY_REQUIRED]; |
| 183 |
Enum req_enum = 5 [features.field_presence = LEGACY_REQUIRED]; |
| 184 |
Nested req_nested = 6 [features.field_presence = LEGACY_REQUIRED]; |
| 185 |
} |
| 186 |
|
| 187 |
// Message contains both required and optional fields. |
| 188 |
message PartialRequired { |
| 189 |
string req_string = 1 [features.field_presence = LEGACY_REQUIRED]; |
| 190 |
string opt_string = 2; |
| 191 |
} |
| 192 |
|
| 193 |
// Following messages are for testing required field nested in optional, |
| 194 |
// repeated and map fields. |
| 195 |
|
| 196 |
message NestedWithRequired { |
| 197 |
string req_string = 1 [features.field_presence = LEGACY_REQUIRED]; |
| 198 |
} |
| 199 |
|
| 200 |
message IndirectRequired { |
| 201 |
NestedWithRequired opt_nested = 1; |
| 202 |
repeated NestedWithRequired rpt_nested = 2; |
| 203 |
map<string, NestedWithRequired> str_to_nested = 3; |
| 204 |
|
| 205 |
oneof union { |
| 206 |
NestedWithRequired oneof_nested = 4; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
// Following messages are for testing extensions. |
| 211 |
|
| 212 |
message Extensions { |
| 213 |
string opt_string = 1; |
| 214 |
extensions 20 to 100; |
| 215 |
bool opt_bool = 101; |
| 216 |
int32 opt_int32 = 2; |
| 217 |
} |
| 218 |
|
| 219 |
extend Extensions { |
| 220 |
bool opt_ext_bool = 21; |
| 221 |
string opt_ext_string = 22; |
| 222 |
Enum opt_ext_enum = 23; |
| 223 |
Nested opt_ext_nested = 24; |
| 224 |
PartialRequired opt_ext_partial = 25; |
| 225 |
|
| 226 |
repeated fixed32 rpt_ext_fixed32 = 31; |
| 227 |
repeated Enum rpt_ext_enum = 32; |
| 228 |
repeated Nested rpt_ext_nested = 33; |
| 229 |
} |
| 230 |
|
| 231 |
message ExtensionsContainer { |
| 232 |
extend Extensions { |
| 233 |
bool opt_ext_bool = 51; |
| 234 |
string opt_ext_string = 52; |
| 235 |
Enum opt_ext_enum = 53; |
| 236 |
Nested opt_ext_nested = 54; |
| 237 |
PartialRequired opt_ext_partial = 55; |
| 238 |
|
| 239 |
repeated string rpt_ext_string = 61; |
| 240 |
repeated Enum rpt_ext_enum = 62; |
| 241 |
repeated Nested rpt_ext_nested = 63; |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
// Following messages are for testing MessageSet. |
| 246 |
|
| 247 |
message MessageSet { |
| 248 |
option message_set_wire_format = true; |
| 249 |
|
| 250 |
extensions 4 to max; |
| 251 |
} |
| 252 |
|
| 253 |
message MessageSetExtension { |
| 254 |
string opt_string = 1; |
| 255 |
|
| 256 |
extend MessageSet { |
| 257 |
MessageSetExtension message_set_extension = 10; |
| 258 |
MessageSetExtension not_message_set_extension = 20; |
| 259 |
Nested ext_nested = 30; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
message FakeMessageSet { |
| 264 |
extensions 4 to max; |
| 265 |
} |
| 266 |
|
| 267 |
message FakeMessageSetExtension { |
| 268 |
string opt_string = 1; |
| 269 |
|
| 270 |
extend FakeMessageSet { |
| 271 |
FakeMessageSetExtension message_set_extension = 10; |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
extend MessageSet { |
| 276 |
FakeMessageSetExtension message_set_extension = 50; |
| 277 |
} |
| 278 |
|
| 279 |
// Message contains well-known type fields. |
| 280 |
message KnownTypes { |
| 281 |
google.protobuf.BoolValue opt_bool = 1; |
| 282 |
google.protobuf.Int32Value opt_int32 = 2; |
| 283 |
google.protobuf.Int64Value opt_int64 = 3; |
| 284 |
google.protobuf.UInt32Value opt_uint32 = 4; |
| 285 |
google.protobuf.UInt64Value opt_uint64 = 5; |
| 286 |
google.protobuf.FloatValue opt_float = 6; |
| 287 |
google.protobuf.DoubleValue opt_double = 7; |
| 288 |
google.protobuf.StringValue opt_string = 8; |
| 289 |
google.protobuf.BytesValue opt_bytes = 9; |
| 290 |
|
| 291 |
google.protobuf.Duration opt_duration = 20; |
| 292 |
google.protobuf.Timestamp opt_timestamp = 21; |
| 293 |
|
| 294 |
google.protobuf.Struct opt_struct = 25; |
| 295 |
google.protobuf.ListValue opt_list = 26; |
| 296 |
google.protobuf.Value opt_value = 27; |
| 297 |
google.protobuf.NullValue opt_null = 28; |
| 298 |
|
| 299 |
google.protobuf.Empty opt_empty = 30; |
| 300 |
google.protobuf.Any opt_any = 32; |
| 301 |
|
| 302 |
google.protobuf.FieldMask opt_fieldmask = 40; |
| 303 |
} |