1/* 2 * Copyright (c) Facebook, Inc. and its affiliates. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17include "includes.thrift" 18cpp_include "<folly/small_vector.h>" 19 20namespace cpp2 some.valid.ns 21 22typedef includes.AStruct AStruct 23 24typedef binary ( 25 cpp.type = "::folly::IOBuf", 26 cpp.adapter = "CustomProtocolAdapter", 27) CustomProtocolType 28 29// Generate base consts 30const bool aBool = true; 31const byte aByte = 1; 32const i16 a16BitInt = 12; 33const i32 a32BitInt = 123; 34const i64 a64BitInt = 1234; 35const float aFloat = 0.1; 36const double aDouble = 0.12; 37const string aString = "Joe Doe"; 38const list<bool> aList = [true, false]; 39const map<string, i32> anEmptyMap = {}; 40const map<i32, string> aMap = {1: "foo", 2: "bar"}; 41const set<string> aSet = ["foo", "bar"]; 42const list<list<i32>> aListOfLists = [[1, 3, 5, 7, 9], [2, 4, 8, 10, 12]]; 43const list<map<string, i32>> states = [ 44 {"San Diego": 3211000, "Sacramento": 479600, "SF": 837400}, 45 {"New York": 8406000, "Albany": 98400}, 46]; 47 48enum MyEnumA { 49 fieldA = 1, 50 fieldB = 2, 51 fieldC = 4, 52} 53 54const list<MyEnumA> AConstList = [1, 2, 3]; 55 56const i32 AnIntegerEnum2 = MyEnumA.fieldB; 57 58const list<i32> AnIntegerEnum2 = [MyEnumA.fieldB, MyEnumA.fieldA]; 59 60enum AnnotatedEnum { 61 FIELDA = 2, 62 FIELDB = 4, 63 FIELDC = 9, 64} (cpp2.declare_bitwise_ops, cpp.enum_type = "std::uint32_t") 65 66enum AnnotatedEnum2 { 67 FIELDA = 2, 68 FIELDB = 4, 69 FIELDC = 9, 70} (cpp2.enum_type = "short", cpp.declare_bitwise_ops) 71 72const MyEnumA constEnumA = MyEnumA.fieldB; 73 74const MyEnumA constEnumB = 3; 75 76struct Empty {} 77 78struct ASimpleStruct { 79 1: i64 boolField; 80} (no_default_comparators) 81 82struct ASimpleStructNoexcept { 83 1: i64 boolField; 84} 85 86struct MyStruct { 87 1: bool MyBoolField; 88 2: i64 MyIntField = 12; 89 3: string MyStringField = "test"; 90 4: string MyStringField2; 91 5: binary MyBinaryField; 92 6: optional binary MyBinaryField2; 93 7: required binary MyBinaryField3; 94 8: list<binary> MyBinaryListField4; 95 9: map<MyEnumA, string> MyMapEnumAndInt = { 96 1: "fieldA", 97 4: "fieldC", 98 9: "nothing", 99 }; 100 10: CustomProtocolType MyCustomField; 101 11: optional CustomProtocolType MyOptCustomField; 102} 103 104union SimpleUnion { 105 7: i64 intValue; 106 2: string stringValue; 107} (cpp.virtual) 108 109typedef i32 simpleTypeDef 110typedef map<i16, string> containerTypeDef 111typedef list<map<i16, string>> complexContainerTypeDef 112typedef set<SimpleUnion> unionTypeDef 113typedef list<MyStruct> structTypeDef 114typedef list<map<Empty, MyStruct>> complexStructTypeDef 115typedef list<complexStructTypeDef> mostComplexTypeDef 116 117union ComplexUnion { 118 1: i64 intValue; 119 201: i64 opt_intValue; 120 3: string stringValue; 121 203: string opt_stringValue; 122 4: i16 intValue2; 123 6: i32 intValue3; 124 7: double doubelValue; 125 8: bool boolValue; 126 9: list<i32> union_list; 127 10: set<i64> union_set; 128 11: map<string, i32> union_map; 129 211: map<string, i32> opt_union_map; 130 12: MyEnumA enum_field; 131 13: list<MyEnumA> enum_container; 132 14: MyStruct a_struct; 133 15: set<MyStruct> a_set_struct; 134 16: SimpleUnion a_union; 135 216: SimpleUnion opt_a_union; 136 17: list<SimpleUnion> a_union_list; 137 18: unionTypeDef a_union_typedef; 138 19: list<unionTypeDef> a_union_typedef_list; 139 20: binary MyBinaryField; 140 21: binary MyBinaryField2; 141 23: list<binary> MyBinaryListField4; 142 24: MyStruct ref_field (cpp.ref); 143 25: MyStruct ref_field2 (cpp.ref_type = "shared_const"); 144 26: AnException excp_field; 145 27: CustomProtocolType MyCustomField; 146} (cpp.methods = "void foo(const std::string& bar) {}") 147 148exception AnException { 149 1: i32 code; 150 101: required i32 req_code; 151 2: string message2; 152 102: required string req_message; 153 3: list<i32> exception_list = [1, 2, 3]; 154 4: set<i64> exception_set; 155 5: map<string, i32> exception_map; 156 105: required map<string, i32> req_exception_map; 157 6: MyEnumA enum_field; 158 7: list<MyEnumA> enum_container; 159 8: MyStruct a_struct; 160 9: set<MyStruct> a_set_struct; 161 10: list<SimpleUnion> a_union_list; 162 11: unionTypeDef union_typedef; 163 19: list<unionTypeDef> a_union_typedef_list; 164 20: CustomProtocolType MyCustomField; 165 21: optional CustomProtocolType MyOptCustomField; 166} (message = "message2") 167 168exception AnotherException { 169 1: i32 code; 170 101: required i32 req_code; 171 2: string message; 172} (cpp.virtual) 173 174typedef i64 (cpp.type = "Foo", cpp.indirection) IndirectionA 175typedef i32 (cpp.type = "Baz", cpp.indirection) IndirectionC 176typedef double (cpp.type = "Bar", cpp.indirection) IndirectionB 177typedef string (cpp.type = "FooBar", cpp.indirection) IndirectionD 178typedef map<MyEnumA, string> ( 179 cpp.declare_hash, 180 cpp.declare_equal_to, 181) HashedTypedef 182 183struct containerStruct { 184 1: bool fieldA; 185 101: required bool req_fieldA; 186 201: optional bool opt_fieldA; 187 2: map<string, bool> fieldB; 188 102: required map<string, bool> req_fieldB; 189 202: optional map<string, bool> opt_fieldB; 190 3: set<i32> fieldC = [1, 2, 3, 4]; 191 103: required set<i32> req_fieldC = [1, 2, 3, 4]; 192 203: optional set<i32> opt_fieldC = [1, 2, 3, 4]; 193 4: string fieldD; 194 5: string fieldE = "somestring"; 195 105: required string req_fieldE = "somestring"; 196 205: optional string opt_fieldE = "somestring"; 197 6: list<list<i32>> fieldF = aListOfLists; 198 7: map<string, map<string, map<string, i32>>> fieldG; 199 8: list<set<i32>> fieldH; 200 9: bool fieldI = true; 201 10: map<string, list<i32>> fieldJ = { 202 "subfieldA": [1, 4, 8, 12], 203 "subfieldB": [2, 5, 9, 13], 204 }; 205 11: list<list<list<list<i32>>>> fieldK; 206 12: set<set<set<bool>>> fieldL; 207 13: map<set<list<i32>>, map<list<set<string>>, string>> fieldM; 208 14: simpleTypeDef fieldN; 209 15: complexStructTypeDef fieldO; 210 16: list<mostComplexTypeDef> fieldP; 211 17: MyEnumA fieldQ; 212 18: MyEnumA fieldR = MyEnumA.fieldB; 213 118: required MyEnumA req_fieldR = MyEnumA.fieldB; 214 218: optional MyEnumA opt_fieldR = MyEnumA.fieldB; 215 19: MyEnumA fieldS = constEnumA; 216 21: list<MyEnumA> fieldT; 217 22: list<MyEnumA> fieldU = [MyEnumA.fieldC, MyEnumA.fieldB, MyEnumA.fieldA]; 218 23: MyStruct fieldV; 219 123: required MyStruct req_fieldV; 220 223: optional MyStruct opt_fieldV; 221 24: set<MyStruct> fieldW; 222 25: ComplexUnion fieldX; 223 125: required ComplexUnion req_fieldX; 224 225: optional ComplexUnion opt_fieldX; 225 26: list<ComplexUnion> fieldY; 226 27: unionTypeDef fieldZ; 227 28: list<unionTypeDef> fieldAA; 228 29: map<IndirectionB, IndirectionC> fieldAB; 229 30: MyEnumB fieldAC; 230 31: includes.AnEnum fieldAD; 231 32: map<string, i32> fieldAE = {}; 232 33: IndirectionD fieldSD; 233} (cpp.noncopyable, cpp.methods = "void foo(const std::string& bar) {}") 234 235enum MyEnumB { 236 AField = 0, 237} 238 239struct MyIncludedStruct { 240 1: includes.IncludedInt64 MyIncludedInt = includes.IncludedConstant; 241 2: AStruct MyIncludedStruct; 242 3: AStruct ARefField (cpp.ref = "true"); 243 4: required AStruct ARequiredField; 244} (cpp2.declare_hash = 1, cpp2.declare_equal_to) 245 246typedef i32 (cpp.type = "CppFakeI32") CppFakeI32 247typedef list<i64> ( 248 cpp.type = "folly::small_vector<int64_t, 8 /* maxInline */>", 249) FollySmallVectorI64 250typedef set<string> ( 251 cpp.type = "folly::sorted_vector_set<std::string>", 252) SortedVectorSetString 253typedef map<i64, double> (cpp.type = "FakeMap") FakeMap 254typedef map<string, containerStruct> ( 255 cpp.type = "std::unordered_map<std::string, containerStruct>", 256) UnorderedMapStruct 257typedef list<i32> (cpp.template = "std::list") std_list 258typedef list<string> (cpp2.template = "std::deque") std_deque 259typedef set<string> (cpp.template = "folly::sorted_vector_set") folly_set 260typedef map<i64, string> (cpp2.template = "folly::sorted_vector_map") folly_map 261 262struct AnnotatedStruct { 263 1: containerStruct no_annotation; 264 2: containerStruct cpp_unique_ref (cpp.ref); 265 3: containerStruct cpp2_unique_ref (cpp2.ref); 266 4: map<i32, list<string>> container_with_ref (cpp2.ref); 267 5: required containerStruct req_cpp_unique_ref (cpp.ref); 268 6: required containerStruct req_cpp2_unique_ref (cpp2.ref); 269 7: required list<string> req_container_with_ref (cpp2.ref); 270 8: optional containerStruct opt_cpp_unique_ref (cpp.ref); 271 9: optional containerStruct opt_cpp2_unique_ref (cpp2.ref); 272 10: optional set<i32> opt_container_with_ref (cpp2.ref); 273 11: containerStruct ref_type_unique (cpp.ref_type = "unique"); 274 12: containerStruct ref_type_shared (cpp2.ref_type = "shared"); 275 13: map<i32, list<string>> ref_type_const (cpp2.ref_type = "shared_const"); 276 14: required containerStruct req_ref_type_shared (cpp.ref_type = "shared"); 277 15: required containerStruct req_ref_type_const ( 278 cpp2.ref_type = "shared_const", 279 ); 280 16: required list<string> req_ref_type_unique (cpp2.ref_type = "unique"); 281 17: optional containerStruct opt_ref_type_const ( 282 cpp.ref_type = "shared_const", 283 ); 284 18: optional containerStruct opt_ref_type_unique (cpp2.ref_type = "unique"); 285 19: optional set<i32> opt_ref_type_shared (cpp2.ref_type = "shared"); 286 20: CppFakeI32 base_type; 287 21: FollySmallVectorI64 list_type; 288 22: SortedVectorSetString set_type; 289 23: FakeMap map_type; 290 24: UnorderedMapStruct map_struct_type; 291 25: IOBuf iobuf_type; 292 26: IOBufPtr iobuf_ptr; 293 27: list<i32> (cpp.template = "std::list") list_i32_template; 294 28: list<string> (cpp2.template = "std::deque") list_string_template; 295 29: set<string> (cpp.template = "folly::sorted_vector_set") set_template; 296 30: map<i64, string> ( 297 cpp2.template = "folly::sorted_vector_map", 298 ) map_template; 299 31: std_list typedef_list_template; 300 32: std_deque typedef_deque_template; 301 33: folly_set typedef_set_template; 302 34: folly_map typedef_map_template; 303 35: IndirectionA indirection_a; 304 36: list<IndirectionB> indirection_b; 305 37: set<IndirectionC> indirection_c; 306 38: IOBuf iobuf_type_val = "value"; 307 39: IOBufPtr iobuf_ptr_val = "value2"; 308 40: containerStruct struct_struct = { 309 "fieldD": "some string", 310 "fieldI": false, 311 }; 312} ( 313 cpp.virtual, 314 cpp.noncopyable, 315 cpp.declare_hash, 316 cpp.declare_equal_to = 1, 317 cpp2.methods = "void foo(const std::string& bar) {}", 318) 319 320struct ComplexContainerStruct { 321 1: map<string, IOBuf> map_of_iobufs; 322 2: map<string, IOBufPtr> map_of_iobuf_ptrs; 323} 324 325service EmptyService { 326} 327 328service ReturnService { 329 void noReturn() (thread = "eb"); 330 bool boolReturn(); 331 i16 i16Return(); 332 i32 i32Return(); 333 i64 i64Return(); 334 float floatReturn(); 335 double doubleReturn(); 336 string stringReturn() (thread = "eb"); 337 binary binaryReturn(); 338 map<string, i64> mapReturn(); 339 simpleTypeDef simpleTypedefReturn(); 340 complexStructTypeDef complexTypedefReturn(); 341 list<mostComplexTypeDef> list_mostComplexTypedefReturn(); 342 MyEnumA enumReturn() (thread = "eb"); 343 list<MyEnumA> list_EnumReturn() (thread = "eb"); 344 MyStruct structReturn(); 345 set<MyStruct> set_StructReturn(); 346 ComplexUnion unionReturn() (thread = "eb"); 347 list<ComplexUnion> list_UnionReturn(); 348 IOBuf readDataEb(1: i64 size) (thread = "eb"); 349 IOBufPtr readData(1: i64 size); 350} 351 352service ParamService { 353 void void_ret_i16_param(1: i16 param1) (thread = "eb"); 354 void void_ret_byte_i16_param(1: byte param1, 2: i16 param2); 355 void void_ret_map_param(1: map<string, i64> param1); 356 void void_ret_map_setlist_param( 357 1: map<string, i64> param1, 358 3: set<list<string>> param2, 359 ); 360 void void_ret_map_typedef_param(1: simpleTypeDef param1); 361 void void_ret_enum_param(1: MyEnumA param1); 362 void void_ret_struct_param(1: MyStruct param1); 363 void void_ret_listunion_param(1: list<ComplexUnion> param1); 364 bool bool_ret_i32_i64_param(1: i32 param1, 3: i64 param2); 365 bool bool_ret_map_param(1: map<string, i64> param1); 366 bool bool_ret_union_param(1: ComplexUnion param1); 367 i64 i64_ret_float_double_param(1: float param1, 3: double param2); 368 i64 i64_ret_string_typedef_param( 369 1: string param1, 370 3: set<mostComplexTypeDef> param2, 371 ); 372 i64 i64_ret_i32_i32_i32_i32_i32_param( 373 1: i32 param1, 374 2: i32 param2, 375 3: i32 param3, 376 4: i32 param4, 377 5: i32 param5, 378 ) (thread = "eb"); 379 double double_ret_setstruct_param(4: set<MyStruct> param1); 380 string string_ret_string_param(1: string param1); 381 binary binary_ret_binary_param(1: binary param1); 382 map<string, i64> map_ret_bool_param(1: bool param1); 383 list<bool> list_ret_map_setlist_param( 384 1: map<i32, list<string>> param1, 385 2: list<string> param2, 386 ); 387 map< 388 set<list<i32>>, 389 map<list<set<string>>, string> 390 > mapsetlistmapliststring_ret_listlistlist_param( 391 1: list<list<list<list<i32>>>> param1, 392 ); 393 simpleTypeDef typedef_ret_i32_param(1: i32 param1); 394 list<simpleTypeDef> listtypedef_ret_typedef_param( 395 1: complexStructTypeDef param1, 396 ) (thread = "eb"); 397 MyEnumA enum_ret_double_param(3: double param1); 398 MyEnumA enum_ret_double_enum_param(3: double param1, 5: MyEnumA param2); 399 list<MyEnumA> listenum_ret_map_param(1: map<string, i64> param1); 400 MyStruct struct_ret_i16_param(1: i16 param1) (thread = "eb"); 401 set<MyStruct> setstruct_ret_set_param(8: set<string> param1); 402 ComplexUnion union_ret_i32_i32_param(4: i32 param1, 2: i32 param2); 403 list<ComplexUnion> listunion_string_param(1: string param1); 404} 405 406typedef binary (cpp2.type = "folly::IOBuf") IOBuf 407typedef binary (cpp2.type = "std::unique_ptr<folly::IOBuf>") IOBufPtr 408 409struct FloatStruct { 410 1: float floatField; 411 2: double doubleField; 412} 413 414union FloatUnion { 415 1: float floatSide; 416 2: double doubleSide; 417} 418 419struct AllRequiredNoExceptMoveCtrStruct { 420 1: required i64 intField; 421} 422