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 8syntax = "proto3"; 9 10package proto3_unittest; 11 12import "google/protobuf/unittest_import.proto"; 13 14option optimize_for = SPEED; 15 16// This proto includes every type of field in both singular and repeated 17// forms. 18message TestAllTypes { 19 message NestedMessage { 20 // The field name "b" fails to compile in proto1 because it conflicts with 21 // a local variable named "b" in one of the generated methods. Doh. 22 // This file needs to compile in proto1 to test backwards-compatibility. 23 int32 bb = 1; 24 } 25 26 enum NestedEnum { 27 ZERO = 0; 28 FOO = 1; 29 BAR = 2; 30 BAZ = 3; 31 NEG = -1; // Intentionally negative. 32 } 33 34 // Singular 35 int32 optional_int32 = 1; 36 int64 optional_int64 = 2; 37 uint32 optional_uint32 = 3; 38 uint64 optional_uint64 = 4; 39 sint32 optional_sint32 = 5; 40 sint64 optional_sint64 = 6; 41 fixed32 optional_fixed32 = 7; 42 fixed64 optional_fixed64 = 8; 43 sfixed32 optional_sfixed32 = 9; 44 sfixed64 optional_sfixed64 = 10; 45 float optional_float = 11; 46 double optional_double = 12; 47 bool optional_bool = 13; 48 string optional_string = 14; 49 bytes optional_bytes = 15; 50 51 // Groups are not allowed in proto3. 52 // optional group OptionalGroup = 16 { 53 // optional int32 a = 17; 54 // } 55 56 optional NestedMessage optional_nested_message = 18; 57 ForeignMessage optional_foreign_message = 19; 58 protobuf_unittest_import.ImportMessage optional_import_message = 20; 59 60 NestedEnum optional_nested_enum = 21; 61 ForeignEnum optional_foreign_enum = 22; 62 63 // Omitted (compared to unittest.proto) because proto2 enums are not allowed 64 // inside proto2 messages. 65 // 66 // optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; 67 68 string optional_string_piece = 24 [ctype = STRING_PIECE]; 69 string optional_cord = 25 [ctype = CORD]; 70 71 // Defined in unittest_import_public.proto 72 protobuf_unittest_import.PublicImportMessage optional_public_import_message = 73 26; 74 75 NestedMessage optional_lazy_message = 27 [lazy = true]; 76 NestedMessage optional_unverified_lazy_message = 28 [unverified_lazy = true]; 77 protobuf_unittest_import.ImportMessage optional_lazy_import_message = 115 78 [lazy = true]; 79 80 // Repeated 81 repeated int32 repeated_int32 = 31; 82 repeated int64 repeated_int64 = 32; 83 repeated uint32 repeated_uint32 = 33; 84 repeated uint64 repeated_uint64 = 34; 85 repeated sint32 repeated_sint32 = 35; 86 repeated sint64 repeated_sint64 = 36; 87 repeated fixed32 repeated_fixed32 = 37; 88 repeated fixed64 repeated_fixed64 = 38; 89 repeated sfixed32 repeated_sfixed32 = 39; 90 repeated sfixed64 repeated_sfixed64 = 40; 91 repeated float repeated_float = 41; 92 repeated double repeated_double = 42; 93 repeated bool repeated_bool = 43; 94 repeated string repeated_string = 44; 95 repeated bytes repeated_bytes = 45; 96 97 // Groups are not allowed in proto3. 98 // repeated group RepeatedGroup = 46 { 99 // optional int32 a = 47; 100 // } 101 102 repeated NestedMessage repeated_nested_message = 48; 103 repeated ForeignMessage repeated_foreign_message = 49; 104 repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; 105 106 repeated NestedEnum repeated_nested_enum = 51; 107 repeated ForeignEnum repeated_foreign_enum = 52; 108 109 // Omitted (compared to unittest.proto) because proto2 enums are not allowed 110 // inside proto2 messages. 111 // 112 // repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; 113 114 repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; 115 repeated string repeated_cord = 55 [ctype = CORD]; 116 117 repeated NestedMessage repeated_lazy_message = 57; 118 119 oneof oneof_field { 120 uint32 oneof_uint32 = 111; 121 NestedMessage oneof_nested_message = 112; 122 string oneof_string = 113; 123 bytes oneof_bytes = 114; 124 } 125} 126 127// Test messages for packed fields 128 129message TestPackedTypes { 130 repeated int32 packed_int32 = 90 [packed = true]; 131 repeated int64 packed_int64 = 91 [packed = true]; 132 repeated uint32 packed_uint32 = 92 [packed = true]; 133 repeated uint64 packed_uint64 = 93 [packed = true]; 134 repeated sint32 packed_sint32 = 94 [packed = true]; 135 repeated sint64 packed_sint64 = 95 [packed = true]; 136 repeated fixed32 packed_fixed32 = 96 [packed = true]; 137 repeated fixed64 packed_fixed64 = 97 [packed = true]; 138 repeated sfixed32 packed_sfixed32 = 98 [packed = true]; 139 repeated sfixed64 packed_sfixed64 = 99 [packed = true]; 140 repeated float packed_float = 100 [packed = true]; 141 repeated double packed_double = 101 [packed = true]; 142 repeated bool packed_bool = 102 [packed = true]; 143 repeated ForeignEnum packed_enum = 103 [packed = true]; 144} 145 146// Explicitly set packed to false 147message TestUnpackedTypes { 148 repeated int32 repeated_int32 = 1 [packed = false]; 149 repeated int64 repeated_int64 = 2 [packed = false]; 150 repeated uint32 repeated_uint32 = 3 [packed = false]; 151 repeated uint64 repeated_uint64 = 4 [packed = false]; 152 repeated sint32 repeated_sint32 = 5 [packed = false]; 153 repeated sint64 repeated_sint64 = 6 [packed = false]; 154 repeated fixed32 repeated_fixed32 = 7 [packed = false]; 155 repeated fixed64 repeated_fixed64 = 8 [packed = false]; 156 repeated sfixed32 repeated_sfixed32 = 9 [packed = false]; 157 repeated sfixed64 repeated_sfixed64 = 10 [packed = false]; 158 repeated float repeated_float = 11 [packed = false]; 159 repeated double repeated_double = 12 [packed = false]; 160 repeated bool repeated_bool = 13 [packed = false]; 161 repeated TestAllTypes.NestedEnum repeated_nested_enum = 14 [packed = false]; 162} 163 164// This proto includes a recursively nested message. 165message NestedTestAllTypes { 166 NestedTestAllTypes child = 1; 167 TestAllTypes payload = 2; 168} 169 170// Define these after TestAllTypes to make sure the compiler can handle 171// that. 172message ForeignMessage { 173 int32 c = 1; 174} 175 176enum ForeignEnum { 177 FOREIGN_ZERO = 0; 178 FOREIGN_FOO = 4; 179 FOREIGN_BAR = 5; 180 FOREIGN_BAZ = 6; 181 FOREIGN_LARGE = 123456; // Large enough to escape the Boxed Integer cache. 182} 183 184// TestEmptyMessage is used to test behavior of unknown fields. 185message TestEmptyMessage {} 186 187// TestMessageWithDummy is also used to test behavior of unknown fields. 188message TestMessageWithDummy { 189 // This field is only here for triggering copy-on-write; it's not intended to 190 // be serialized. 191 bool dummy = 536870911; 192} 193 194// Same layout as TestOneof2 in unittest.proto to test unknown enum value 195// parsing behavior in oneof. 196message TestOneof2 { 197 oneof foo { 198 NestedEnum foo_enum = 6; 199 } 200 201 enum NestedEnum { 202 UNKNOWN = 0; 203 FOO = 1; 204 BAR = 2; 205 BAZ = 3; 206 } 207} 208 209// If bool fields are incorrectly assumed to have hasbits, InternalSwap would 210// result in swapping N more 32bit hasbits incorrectly. Considering padding, we 211// need many bool fields to stress this. 212message TestHasbits { 213 bool b1 = 1; 214 bool b2 = 2; 215 bool b3 = 3; 216 bool b4 = 4; 217 bool b5 = 5; 218 bool b6 = 6; 219 bool b7 = 7; 220 bool b8 = 8; 221 bool b9 = 9; 222 bool b10 = 10; 223 bool b11 = 11; 224 bool b12 = 12; 225 bool b13 = 13; 226 bool b14 = 14; 227 bool b15 = 15; 228 bool b16 = 16; 229 bool b17 = 17; 230 bool b18 = 18; 231 bool b19 = 19; 232 bool b20 = 20; 233 bool b21 = 21; 234 bool b22 = 22; 235 bool b23 = 23; 236 bool b24 = 24; 237 bool b25 = 25; 238 bool b26 = 26; 239 bool b27 = 27; 240 bool b28 = 28; 241 bool b29 = 29; 242 bool b30 = 30; 243 bool b31 = 31; 244 bool b32 = 32; 245 bool b33 = 33; 246 bool b34 = 34; 247 bool b35 = 35; 248 bool b36 = 36; 249 bool b37 = 37; 250 bool b38 = 38; 251 bool b39 = 39; 252 bool b40 = 40; 253 bool b41 = 41; 254 bool b42 = 42; 255 bool b43 = 43; 256 bool b44 = 44; 257 bool b45 = 45; 258 bool b46 = 46; 259 bool b47 = 47; 260 bool b48 = 48; 261 bool b49 = 49; 262 bool b50 = 50; 263 bool b51 = 51; 264 bool b52 = 52; 265 bool b53 = 53; 266 bool b54 = 54; 267 bool b55 = 55; 268 bool b56 = 56; 269 bool b57 = 57; 270 bool b58 = 58; 271 bool b59 = 59; 272 bool b60 = 60; 273 bool b61 = 61; 274 bool b62 = 62; 275 bool b63 = 63; 276 bool b64 = 64; 277 bool b65 = 65; 278 bool b66 = 66; 279 bool b67 = 67; 280 bool b68 = 68; 281 bool b69 = 69; 282 TestAllTypes child = 100; 283} 284