/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ include "thrift/lib/cpp2/frozen/test/Helper.thrift" include "thrift/annotation/cpp.thrift" namespace cpp2 apache.thrift.test cpp_include "" cpp_include "thrift/lib/cpp2/frozen/VectorAssociative.h" cpp_include "thrift/lib/cpp2/frozen/HintTypes.h" enum Gender { Male = 0, Female = 1, Other = 2, } struct Nesting { 1: Helper.Ratio a; 2: Helper.Ratio b; } struct Pet1 { 1: string name; 2: optional i32 age; 3: optional bool vegan; } struct Person1 { 5: optional i32 age; 2: float height; // different 1: string name; 4: list pets; 6: Gender gender = Male; } struct Pet2 { 3: optional float weight; 1: string name; } struct Person2 { 1: string name; 3: float weight; // different 4: list pets; 5: optional i32 age; } struct Tiny { 1: required string a; 2: string b; 3: string c; 4: string d; } struct Place { 1: string name; 2: map popularityByHour; } struct PlaceTest { 1: map places; } struct EveryLayout { 1: bool aBool; 2: i32 aInt; 3: list aList; 4: set aSet; @cpp.Type{template = "std::unordered_set"} 5: set aHashSet; 6: map aMap; @cpp.Type{template = "std::unordered_map"} 7: map aHashMap; 8: optional i32 optInt; // optional layout 9: float aFloat; // trivial layout 10: optional map optMap; } struct VectorTest { 1: list aList; @cpp.Type{template = "apache::thrift::frozen::VectorAsSet"} 2: set aSet; @cpp.Type{template = "apache::thrift::frozen::VectorAsMap"} 3: map aMap; @cpp.Type{template = "apache::thrift::frozen::VectorAsHashSet"} 4: set aHashSet; @cpp.Type{template = "apache::thrift::frozen::VectorAsHashMap"} 5: map aHashMap; @cpp.Type{template = "folly::fbvector"} 6: list fbVector; } struct EnumAsKeyTest { @cpp.Type{template = "std::unordered_set"} 1: set enumSet; @cpp.Type{template = "std::unordered_map"} 2: map enumMap; @cpp.Type{template = "std::unordered_set"} 3: set outsideEnumSet; @cpp.Type{template = "std::unordered_map"} 4: map outsideEnumMap; } union TestUnion { 1: i32 aInt; 2: string aString; 3: list aList; 4: map aMap; 5: set aSet; 6: Member aStruct; @cpp.Ref{type = cpp.RefType.SharedMutable} 7: Pet1 aPet1; @cpp.Ref{type = cpp.RefType.Unique} 8: Tiny aTiny; @cpp.Ref{type = cpp.RefType.Unique} 9: Place aPlace; } union TestUnion2 { 2: string aString; 3: list aList; 4: map aMap; 5: set aSet; 6: Member aStruct; @cpp.Ref{type = cpp.RefType.SharedMutable} 7: Pet1 aPet1; @cpp.Ref{type = cpp.RefType.Unique} 8: Tiny aTiny; @cpp.Ref{type = cpp.RefType.Unique} 9: Place aPlace; 10: i32 anotherInt; } struct Member { 1: i64 adId; 2: string name; 3: optional list creativeIds; } struct Big { 1: optional string anOptionalString; 2: i64 anId; 3: optional list anOptionalList; 4: TestUnion aTestUnion; 5: string aString; } struct User { 1: i64 uid; 2: string name; } (cpp.declare_hash, cpp.declare_equal_to) struct TriviallyCopyableStruct { 1: required i32 field; } @cpp.Type{name = "apache::thrift::frozen::FixedSizeString<2>"} typedef string Fixed2 @cpp.Type{name = "apache::thrift::frozen::FixedSizeString<8>"} typedef string Fixed8 struct TestFixedSizeString { 1: Fixed8 bytes8; @cpp.Type{name = "apache::thrift::frozen::FixedSizeString<4>"} 2: optional string bytes4; @cpp.Type{template = "apache::thrift::frozen::VectorAsHashMap"} 3: map aMapToFreeze; @cpp.Type{template = "std::unordered_map"} 4: map aMap; } struct Empty {} struct Excluded {} (cpp.frozen2_exclude) struct ContainsExcluded { 1: optional Excluded excluded; }