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// Author: kenton@google.com (Kenton Varda) 9// Based on original Protocol Buffers design by 10// Sanjay Ghemawat, Jeff Dean, and others. 11// 12// A proto file we will use for unit testing. 13 14syntax = "proto3"; 15 16option csharp_namespace = "Google.Protobuf.TestProtos"; 17 18// Only present so we can test that we can read it (as an example 19// of a non-C# option) 20option java_outer_classname = "UnittestProto"; 21 22import "csharp/protos/unittest_import_proto3.proto"; 23 24package protobuf_unittest3; 25 26// This proto includes every type of field in both singular and repeated 27// forms. 28message TestAllTypes { 29 message NestedMessage { 30 // The field name "b" fails to compile in proto1 because it conflicts with 31 // a local variable named "b" in one of the generated methods. Doh. 32 // This file needs to compile in proto1 to test backwards-compatibility. 33 int32 bb = 1; 34 } 35 36 enum NestedEnum { 37 NESTED_ENUM_UNSPECIFIED = 0; 38 FOO = 1; 39 BAR = 2; 40 BAZ = 3; 41 NEG = -1; // Intentionally negative. 42 } 43 44 // Singular 45 int32 single_int32 = 1; 46 int64 single_int64 = 2; 47 uint32 single_uint32 = 3; 48 uint64 single_uint64 = 4; 49 sint32 single_sint32 = 5; 50 sint64 single_sint64 = 6; 51 fixed32 single_fixed32 = 7; 52 fixed64 single_fixed64 = 8; 53 sfixed32 single_sfixed32 = 9; 54 sfixed64 single_sfixed64 = 10; 55 float single_float = 11; 56 double single_double = 12; 57 bool single_bool = 13; 58 string single_string = 14; 59 bytes single_bytes = 15; 60 61 NestedMessage single_nested_message = 18; 62 ForeignMessage single_foreign_message = 19; 63 protobuf_unittest_import.ImportMessage single_import_message = 20; 64 65 NestedEnum single_nested_enum = 21; 66 ForeignEnum single_foreign_enum = 22; 67 protobuf_unittest_import.ImportEnum single_import_enum = 23; 68 69 // Defined in unittest_import_public.proto 70 protobuf_unittest_import.PublicImportMessage single_public_import_message = 71 26; 72 73 // Repeated 74 repeated int32 repeated_int32 = 31; 75 repeated int64 repeated_int64 = 32; 76 repeated uint32 repeated_uint32 = 33; 77 repeated uint64 repeated_uint64 = 34; 78 repeated sint32 repeated_sint32 = 35; 79 repeated sint64 repeated_sint64 = 36; 80 repeated fixed32 repeated_fixed32 = 37; 81 repeated fixed64 repeated_fixed64 = 38; 82 repeated sfixed32 repeated_sfixed32 = 39; 83 repeated sfixed64 repeated_sfixed64 = 40; 84 repeated float repeated_float = 41; 85 repeated double repeated_double = 42; 86 repeated bool repeated_bool = 43; 87 repeated string repeated_string = 44; 88 repeated bytes repeated_bytes = 45; 89 90 repeated NestedMessage repeated_nested_message = 48; 91 repeated ForeignMessage repeated_foreign_message = 49; 92 repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; 93 94 repeated NestedEnum repeated_nested_enum = 51; 95 repeated ForeignEnum repeated_foreign_enum = 52; 96 repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; 97 // Defined in unittest_import_public.proto 98 repeated protobuf_unittest_import.PublicImportMessage 99 repeated_public_import_message = 54; 100 101 // For oneof test 102 oneof oneof_field { 103 uint32 oneof_uint32 = 111; 104 NestedMessage oneof_nested_message = 112; 105 string oneof_string = 113; 106 bytes oneof_bytes = 114; 107 } 108} 109 110// This proto includes a recursively nested message. 111message NestedTestAllTypes { 112 NestedTestAllTypes child = 1; 113 TestAllTypes payload = 2; 114 repeated NestedTestAllTypes repeated_child = 3; 115} 116 117message TestDeprecatedFields { 118 int32 deprecated_int32 = 1 [deprecated = true]; 119} 120 121// Define these after TestAllTypes to make sure the compiler can handle 122// that. 123message ForeignMessage { 124 int32 c = 1; 125} 126 127enum ForeignEnum { 128 FOREIGN_UNSPECIFIED = 0; 129 FOREIGN_FOO = 4; 130 FOREIGN_BAR = 5; 131 FOREIGN_BAZ = 6; 132} 133 134message TestReservedFields { 135 reserved 2, 15, 9 to 11; 136 reserved "bar", "baz"; 137} 138 139// Test that we can use NestedMessage from outside TestAllTypes. 140message TestForeignNested { 141 TestAllTypes.NestedMessage foreign_nested = 1; 142} 143 144// Test that really large tag numbers don't break anything. 145message TestReallyLargeTagNumber { 146 // The largest possible tag number is 2^28 - 1, since the wire format uses 147 // three bits to communicate wire type. 148 int32 a = 1; 149 int32 bb = 268435455; 150} 151 152message TestRecursiveMessage { 153 TestRecursiveMessage a = 1; 154 int32 i = 2; 155} 156 157// Test that mutual recursion works. 158message TestMutualRecursionA { 159 TestMutualRecursionB bb = 1; 160} 161 162message TestMutualRecursionB { 163 TestMutualRecursionA a = 1; 164 int32 optional_int32 = 2; 165} 166 167message TestEnumAllowAlias { 168 TestEnumWithDupValue value = 1; 169} 170 171// Test an enum that has multiple values with the same number. 172enum TestEnumWithDupValue { 173 option allow_alias = true; 174 175 TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0; 176 177 FOO1 = 1; 178 BAR1 = 2; 179 BAZ = 3; 180 FOO2 = 1; 181 BAR2 = 2; 182} 183 184// Test an enum with large, unordered values. 185enum TestSparseEnum { 186 TEST_SPARSE_ENUM_UNSPECIFIED = 0; 187 SPARSE_A = 123; 188 SPARSE_B = 62374; 189 SPARSE_C = 12589234; 190 SPARSE_D = -15; 191 SPARSE_E = -53452; 192 // In proto3, value 0 must be the first one specified 193 // SPARSE_F = 0; 194 SPARSE_G = 2; 195} 196 197// Test message with CamelCase field names. This violates Protocol Buffer 198// standard style. 199message TestCamelCaseFieldNames { 200 int32 PrimitiveField = 1; 201 string StringField = 2; 202 ForeignEnum EnumField = 3; 203 ForeignMessage MessageField = 4; 204 205 repeated int32 RepeatedPrimitiveField = 7; 206 repeated string RepeatedStringField = 8; 207 repeated ForeignEnum RepeatedEnumField = 9; 208 repeated ForeignMessage RepeatedMessageField = 10; 209} 210 211// We list fields out of order, to ensure that we're using field number and not 212// field index to determine serialization order. 213message TestFieldOrderings { 214 string my_string = 11; 215 int64 my_int = 1; 216 float my_float = 101; 217 message NestedMessage { 218 int64 oo = 2; 219 // The field name "b" fails to compile in proto1 because it conflicts with 220 // a local variable named "b" in one of the generated methods. Doh. 221 // This file needs to compile in proto1 to test backwards-compatibility. 222 int32 bb = 1; 223 } 224 225 NestedMessage single_nested_message = 200; 226} 227 228message SparseEnumMessage { 229 TestSparseEnum sparse_enum = 1; 230} 231 232// Test String and Bytes: string is for valid UTF-8 strings 233message OneString { 234 string data = 1; 235} 236 237message MoreString { 238 repeated string data = 1; 239} 240 241message OneBytes { 242 bytes data = 1; 243} 244 245message MoreBytes { 246 bytes data = 1; 247} 248 249// Test int32, uint32, int64, uint64, and bool are all compatible 250message Int32Message { 251 int32 data = 1; 252} 253 254message Uint32Message { 255 uint32 data = 1; 256} 257 258message Int64Message { 259 int64 data = 1; 260} 261 262message Uint64Message { 263 uint64 data = 1; 264} 265 266message BoolMessage { 267 bool data = 1; 268} 269 270// Test oneofs. 271message TestOneof { 272 oneof foo { 273 int32 foo_int = 1; 274 string foo_string = 2; 275 TestAllTypes foo_message = 3; 276 } 277} 278 279// Test messages for packed fields 280 281message TestPackedTypes { 282 repeated int32 packed_int32 = 90 [packed = true]; 283 repeated int64 packed_int64 = 91 [packed = true]; 284 repeated uint32 packed_uint32 = 92 [packed = true]; 285 repeated uint64 packed_uint64 = 93 [packed = true]; 286 repeated sint32 packed_sint32 = 94 [packed = true]; 287 repeated sint64 packed_sint64 = 95 [packed = true]; 288 repeated fixed32 packed_fixed32 = 96 [packed = true]; 289 repeated fixed64 packed_fixed64 = 97 [packed = true]; 290 repeated sfixed32 packed_sfixed32 = 98 [packed = true]; 291 repeated sfixed64 packed_sfixed64 = 99 [packed = true]; 292 repeated float packed_float = 100 [packed = true]; 293 repeated double packed_double = 101 [packed = true]; 294 repeated bool packed_bool = 102 [packed = true]; 295 repeated ForeignEnum packed_enum = 103 [packed = true]; 296} 297 298// A message with the same fields as TestPackedTypes, but without packing. Used 299// to test packed <-> unpacked wire compatibility. 300message TestUnpackedTypes { 301 repeated int32 unpacked_int32 = 90 [packed = false]; 302 repeated int64 unpacked_int64 = 91 [packed = false]; 303 repeated uint32 unpacked_uint32 = 92 [packed = false]; 304 repeated uint64 unpacked_uint64 = 93 [packed = false]; 305 repeated sint32 unpacked_sint32 = 94 [packed = false]; 306 repeated sint64 unpacked_sint64 = 95 [packed = false]; 307 repeated fixed32 unpacked_fixed32 = 96 [packed = false]; 308 repeated fixed64 unpacked_fixed64 = 97 [packed = false]; 309 repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; 310 repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; 311 repeated float unpacked_float = 100 [packed = false]; 312 repeated double unpacked_double = 101 [packed = false]; 313 repeated bool unpacked_bool = 102 [packed = false]; 314 repeated ForeignEnum unpacked_enum = 103 [packed = false]; 315} 316 317message TestRepeatedScalarDifferentTagSizes { 318 // Parsing repeated fixed size values used to fail. This message needs to be 319 // used in order to get a tag of the right size; all of the repeated fields 320 // in TestAllTypes didn't trigger the check. 321 repeated fixed32 repeated_fixed32 = 12; 322 // Check for a varint type, just for good measure. 323 repeated int32 repeated_int32 = 13; 324 325 // These have two-byte tags. 326 repeated fixed64 repeated_fixed64 = 2046; 327 repeated int64 repeated_int64 = 2047; 328 329 // Three byte tags. 330 repeated float repeated_float = 262142; 331 repeated uint64 repeated_uint64 = 262143; 332} 333 334message TestCommentInjectionMessage { 335 // */ <- This should not close the generated doc comment 336 string a = 1; 337} 338 339// Test that RPC services work. 340message FooRequest {} 341message FooResponse {} 342 343message FooClientMessage {} 344message FooServerMessage {} 345 346// This is a test service 347service TestService { 348 // This is a test method 349 rpc Foo(FooRequest) returns (FooResponse); 350 rpc Bar(BarRequest) returns (BarResponse); 351} 352 353message BarRequest {} 354message BarResponse {} 355 356message TestEmptyMessage {} 357 358// This is leading detached comment 1 359 360// This is leading detached comment 2 361 362// This is a leading comment 363message CommentMessage { 364 // Leading nested message comment 365 message NestedCommentMessage { 366 // Leading nested message field comment 367 string nested_text = 1; 368 } 369 370 // Leading nested enum comment 371 enum NestedCommentEnum { 372 // Zero value comment 373 ZERO_VALUE = 0; 374 } 375 376 // Leading field comment 377 string text = 1; // Trailing field comment 378} 379 380// Leading enum comment 381enum CommentEnum { 382 // Zero value comment 383 ZERO_VALUE = 0; 384} 385