/* * 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/annotation/cpp.thrift" include "thrift/annotation/python.thrift" cpp_include "" cpp_include "folly/container/F14Map.h" cpp_include "folly/FBString.h" cpp_include "folly/io/IOBuf.h" package "facebook.com/testing" namespace py3 "" namespace cpp2 cpp2 const list int_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const map> LocationMap = {1: {1: 1}}; typedef list I32List typedef list> StrList2D typedef list StringList typedef map StrIntMap typedef map StrStrMap typedef map StrI32ListMap typedef map StrStrIntListMapMap typedef set SetI32Lists typedef set SetSetI32Lists typedef set SetI32 typedef bool Bool typedef i64 TimeStamp typedef byte Byte typedef float Float typedef double Double typedef list EasyList typedef set EasySet typedef map StrEasyMap // @lint-ignore THRIFTFORMAT (for autodeps) typedef map ( cpp.type = "folly::F14FastMap", ) F14MapFollyString typedef list (cpp2.type = "std::vector") Uint32List exception UnusedError { 1: string message; } (message = "message") exception HardError { 1: string errortext; 2: i32 code; } (message = "errortext") exception UnfriendlyError { 1: string errortext; 2: i32 code; } enum Color { red = 0, blue = 1, green = 2, } exception SimpleError { 1: Color color; } @python.Flags{} enum Perm { read = 4, write = 2, execute = 1, } enum Kind { None = 0, REGULAR = 8, LINK = 10, DIR = 4, FIFO = 1, CHAR = 2, BLOCK = 6, SOCK = 12 (cpp.name = "SOCKET"), } (cpp.name = "Kind_") enum BadMembers { name = 1 (py3.name = "name_"), value = 2 (py3.name = "value_"), } enum EmptyEnum { } union EmptyUnion {} struct StringBucket { 1: string one; 2: optional string two; 3: optional string three; 4: optional string four; 5: optional string five; 6: optional string six; 7: optional string seven; 8: optional string eight; 9: optional string nine; 10: optional string ten; } struct File { 1: string name; 2: Perm permissions; 3: Kind type = Kind.REGULAR; } struct OptionalFile { 1: optional string name; 3: optional i32 type; } struct Digits { 1: optional list data; } union Integers { 1: byte tiny; 2: i16 small; 3: i32 medium; 4: i64 large; 5: string unbounded; 6: string name (py3.name = "name_"); 7: Digits digits (cpp.ref = "True"); } union ValueOrError { 1: File value (py3.name = "value_"); 3: HardError error; } struct easy { 3: optional string name; 1: i32 val; 2: I32List val_list; 4: Integers an_int; @python.Py3Hidden{} 5: i64 py3_hidden; } (anno1 = "foo", bar) struct PrivateCppRefField { # (cpp.experimental.lazy) field is always private 1: optional easy field1 (cpp.ref, cpp.experimental.lazy); 2: optional easy field2 (cpp.ref_type = "shared", cpp.experimental.lazy); 3: optional easy field3 ( cpp.ref_type = "shared_const", cpp.experimental.lazy, ); } struct Nested3 { 1: easy c; } struct Nested2 { 1: Nested3 b; } struct Nested1 { 1: Nested2 a; } struct Optionals { 1: optional list values; } union ComplexUnion { 1: Color color; 2: easy easy_struct; 3: Integers union_val; 4: float float_val; 5: double double_val; 6: i16 tiny; 7: i64 large; 9: string text; 10: binary raw; 11: bool truthy; } union IOBufUnion { @cpp.Type{name = "folly::IOBuf"} 1: binary buf; } (cpp.noncomparable) struct hard { 1: i32 val; 2: I32List val_list; 3: string name; 4: Integers an_int; 5: string other = "some default"; } struct Runtime { 1: bool bool_val; 2: Color enum_val; 3: list int_list_val; } struct mixed { 1: optional string opt_field = "optional"; 3: string unq_field = "unqualified"; 4: optional easy opt_easy_ref (cpp.ref = "True"); 6: list const_container_ref (cpp.ref_type = "shared_const"); @python.Name{name = "some_field_"} 7: optional string some_field; } struct numerical { 1: i32 int_val; 2: double float_val; 5: I32List int_list; 6: list float_list; 7: i64 i64_val; } struct ColorGroups { 1: list color_list; 2: set color_set; 3: map color_map; } struct OptionalColorGroups { 1: optional list color_list; 2: optional set color_set; 3: optional map color_map; } typedef list (cpp.type = "std::deque") list_typedef typedef set (cpp.type = "std::unordered_set") set_typedef typedef map ( cpp.type = "std::unordered_map", ) map_typedef typedef string (cpp.type = "folly::fbstring") string_typedef struct customized { 1: list_i32_2242 list_template; 2: set_i32_3833 set_template; 3: map_i32_i32_907 map_template; 4: list_typedef list_type; 5: set_typedef set_type; 6: map_typedef map_type; 7: string_typedef string_type; 8: i32 foo (cpp.name = "bar"); 9: list list_of_uint32; } struct Reserved { 1: string from (py3.name = "from_"); // named with a python keyword (which is not a C++ keyword) 2: i32 nonlocal (py3.name = "nonlocal_"); // ditto 3: string ok; // not a keyword 4: bool cpdef (py3.name = 'is_cpdef'); 5: string move; // not a keyword 6: string inst; // not a keyword 7: string changes; // not a keyword 8: string __mangled_str; 9: i64 __mangled_int; } struct __Reserved { 1: string __mangled_str; 2: i64 __mangled_int; } union ReservedUnion { @python.Name{name = "from_"} 1: string from; 2: i32 nonlocal (py3.name = "nonlocal_"); 3: string ok; } struct EdgeCaseStruct { 1: map> reservedValues; } struct SlowCompare { 1: string field1; 2: i32 field2; 3: Color field3; } (cpp.noncomparable) struct NonCopyable { 1: i64 num; } (cpp.noncopyable) struct Messy { 1: optional string opt_field (some = "annotation", a.b.c = "d.e.f"); 3: string unq_field = "xyzzy"; 4: Runtime struct_field = { "bool_val": true, "enum_val": Color.blue, "int_list_val": [10, 20, 30], }; } struct ComplexRef { 1: string name; 2: optional ComplexRef ref (cpp2.ref = "true"); 3: optional list list_basetype_ref (cpp2.ref = "true"); 4: optional list list_recursive_ref (cpp2.ref = "true"); 5: optional set set_basetype_ref (cpp2.ref = "true"); 6: optional set set_recursive_ref (cpp2.ref = "true"); 7: optional map map_basetype_ref (cpp2.ref = "true"); 8: optional map map_recursive_ref (cpp2.ref = "true"); 9: optional list list_shared_ref (cpp2.ref_type = "shared"); 10: optional set set_const_shared_ref ( cpp2.ref_type = "shared_const", ); 11: optional ComplexRef recursive (thrift.box); } struct Complex { 1: bool val_bool; 2: i32 val_i32; 3: i64 val_i64; 4: string val_string; 5: binary val_binary; @cpp.Type{name = "folly::IOBuf"} 6: binary val_iobuf; 7: Color val_enum; 8: ComplexUnion val_union; 9: list val_list; // @lint-ignore THRIFTCHECKS 10: optional set val_set; 11: map val_map; // @lint-ignore THRIFTCHECKS 12: optional map>> val_complex_map; 13: ColorGroups val_struct_with_containers; } struct ListTypes { 1: list first; 2: list second; 3: list> third; 4: list> fourth; 5: list> fifth; } struct SetTypes { 1: set first; 2: set second; } struct StructuredAnnotation { 2: map first; 3: i64 second; 4: list third; 5: StructuredAnnotation recurse (cpp.ref = "True"); } @StructuredAnnotation{ first = {1.1: 2}, second = 3, third = ["a", "Multi 'line' "], recurse = StructuredAnnotation{third = ["3", "4"]}, } @Messy service TestingService { readonly string getName(); string getMethodName(); string getRequestId(); float getRequestTimeout(); oneway void shutdown(); idempotent bool invert(1: bool value); i32 complex_action( 1: string first, 2: string second, @StructuredAnnotation{second = 42} 3: i64 third, 4: string fourth (iv = "4"), ); void takes_a_list(1: I32List ints) throws (1: SimpleError e); void take_it_easy(1: i32 how, 2: easy what) (a = "b.c.d"); void pick_a_color(1: Color color); void int_sizes(1: byte one, 2: i16 two, 3: i32 three, 4: i64 four); void hard_error(1: bool valid) throws (1: HardError e); bool renamed_func(1: bool ret) (cpp.name = "renamed_func_in_cpp"); i32 getPriority(); } (fun_times = "yes", single_quote = "'", double_quotes = '"""') service TestingServiceChild extends TestingService { stream stream_func(); } (cpp.name = "TestingServiceChildRenamed") struct ListNode { 1: i32 value; @cpp.Ref{type = cpp.RefType.Unique} 2: optional ListNode next; } @cpp.Type{name = "folly::IOBuf"} typedef binary IOBuf @python.Py3Hidden struct IOBufListStruct { 1: list iobufs; } (cpp.noncomparable) service ClientMetadataTestingService { string getAgent(); string getHostname(); string getMetadaField(1: string key); } // The following were automatically generated and may benefit from renaming. typedef i32 (cpp.type = "uint32_t") i32_2395 struct EmptyStruct {} exception EmptyError {} // The following were automatically generated and may benefit from renaming. typedef list (cpp.template = "std::deque") list_i32_2242 typedef map (cpp.template = "std::unordered_map") map_i32_i32_907 typedef set (cpp.template = "std::unordered_set") set_i32_3833