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 "thrift/lib/cpp2/frozen/test/Helper.thrift" 18 19namespace cpp2 apache.thrift.test 20 21cpp_include "<unordered_set>" 22cpp_include "thrift/lib/cpp2/frozen/VectorAssociative.h" 23cpp_include "thrift/lib/cpp2/frozen/HintTypes.h" 24 25enum Gender { 26 Male = 0, 27 Female = 1, 28 Other = 2, 29} 30 31struct Nesting { 32 1: Helper.Ratio a; 33 2: Helper.Ratio b; 34} 35 36struct Pet1 { 37 1: string name; 38 2: optional i32 age; 39 3: optional bool vegan; 40} 41 42struct Person1 { 43 5: optional i32 age; 44 2: float height; // different 45 1: string name; 46 4: list<Pet1> pets; 47 6: Gender gender = Male; 48} 49 50struct Pet2 { 51 3: optional float weight; 52 1: string name; 53} 54 55struct Person2 { 56 1: string name; 57 3: float weight; // different 58 4: list<Pet2> pets; 59 5: optional i32 age; 60} 61 62struct Tiny { 63 1: required string a; 64 2: string b; 65 3: string c; 66 4: string d; 67} 68 69struct Place { 70 1: string name; 71 2: map<i32, i32> popularityByHour; 72} 73 74struct PlaceTest { 75 1: map<i64, Place> places; 76} 77 78struct EveryLayout { 79 1: bool aBool; 80 2: i32 aInt; 81 3: list<i32> aList; 82 4: set<i32> aSet; 83 5: set<i32> (cpp.template = "std::unordered_set") aHashSet; 84 6: map<i32, i32> aMap; 85 7: map<i32, i32> (cpp.template = 'std::unordered_map') aHashMap; 86 8: optional i32 optInt; // optional layout 87 9: float aFloat; // trivial layout 88 10: optional map<i32, i32> optMap; 89} 90 91struct VectorTest { 92 1: list<i32> aList; 93 2: set<i32> (cpp.template = "apache::thrift::frozen::VectorAsSet") aSet; 94 3: map<i32, i32> (cpp.template = "apache::thrift::frozen::VectorAsMap") aMap; 95 4: set<i32> ( 96 cpp.template = "apache::thrift::frozen::VectorAsHashSet", 97 ) aHashSet; 98 5: map<i32, i32> ( 99 cpp.template = "apache::thrift::frozen::VectorAsHashMap", 100 ) aHashMap; 101 6: list<i32> (cpp.template = "folly::fbvector") fbVector; 102} 103 104struct EnumAsKeyTest { 105 1: set<Gender> (cpp.template = 'std::unordered_set') enumSet; 106 2: map<Gender, i32> (cpp.template = 'std::unordered_map') enumMap; 107 3: set<Helper.Animal> (cpp.template = 'std::unordered_set') outsideEnumSet; 108 4: map<Helper.Animal, i32> ( 109 cpp.template = 'std::unordered_map', 110 ) outsideEnumMap; 111} 112 113union TestUnion { 114 1: i32 aInt; 115 2: string aString; 116 3: list<i64> aList; 117 4: map<i32, i64> aMap; 118 5: set<string> aSet; 119 6: Member aStruct; 120 7: Pet1 aPet1 (cpp.ref_type = "shared"); 121 8: Tiny aTiny (cpp2.ref_type = "unique"); 122 9: Place aPlace (cpp2.ref = "true"); 123} 124 125union TestUnion2 { 126 2: string aString; 127 3: list<i64> aList; 128 4: map<i32, i64> aMap; 129 5: set<string> aSet; 130 6: Member aStruct; 131 7: Pet1 aPet1 (cpp.ref_type = "shared"); 132 8: Tiny aTiny (cpp2.ref_type = "unique"); 133 9: Place aPlace (cpp2.ref = "true"); 134 10: i32 anotherInt; 135} 136 137struct Member { 138 1: i64 adId; 139 2: string name; 140 3: optional list<i64> creativeIds; 141} 142 143struct Big { 144 1: optional string anOptionalString; 145 2: i64 anId; 146 3: optional list<i64> anOptionalList; 147 4: TestUnion aTestUnion; 148 5: string aString; 149} 150 151struct User { 152 1: i64 uid; 153 2: string name; 154} (cpp.declare_hash, cpp.declare_equal_to) 155 156struct TriviallyCopyableStruct { 157 1: required i32 field; 158} 159 160typedef string Fixed2 (cpp.type = "apache::thrift::frozen::FixedSizeString<2>") 161typedef string Fixed8 (cpp.type = "apache::thrift::frozen::FixedSizeString<8>") 162 163struct TestFixedSizeString { 164 1: Fixed8 bytes8; 165 2: optional string ( 166 cpp.type = "apache::thrift::frozen::FixedSizeString<4>", 167 ) bytes4; 168 3: map<Fixed8, Fixed2> ( 169 cpp.template = "apache::thrift::frozen::VectorAsHashMap", 170 ) aMapToFreeze; 171 4: map<Fixed8, Fixed2> (cpp.template = "std::unordered_map") aMap; 172} 173 174struct Empty {} 175 176struct Excluded {} (cpp.frozen2_exclude) 177 178struct ContainsExcluded { 179 1: optional Excluded excluded; 180} 181