summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjfarrell <jfarrell@apache.org>2014-04-08 22:45:01 -0400
committerjfarrell <jfarrell@apache.org>2014-04-08 22:45:01 -0400
commite0e831683897ea4b786eebabd0cea77659d77150 (patch)
treef0a7e4bbd410047e6022657d568abc593013b6d0 /test
parentbea3144a456a635c7a2e84c92277c5ad27f892d6 (diff)
downloadthrift-e0e831683897ea4b786eebabd0cea77659d77150.tar.gz
THRIFT-2421: Tree/Recursive struct support in thrift
Client: cpp Patch: Dave Watson Github Pull Request: This closes #84 ---- commit b6134cedf292845e5ed01052919894df6b561bf2 Date: 2014-03-20T18:12:04Z Recursive structs support in parser A common complaint is that you can't express trees or other recursive structures in thrift easily - unlike protobufs. This diff loosens up the parser to allow using structs before they are defined (and uses typedef as a forward declaration). This diff is actually enough to make recursive types work for some dyamic languages (I tried php, works out of the box!) Other languages will need forward declarations, or ways to box types, to make this work (i.e. C++ needs both forward decls and a way to express structs as pointers)
Diffstat (limited to 'test')
-rw-r--r--test/Recursive.thrift47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/Recursive.thrift b/test/Recursive.thrift
new file mode 100644
index 000000000..c55541be0
--- /dev/null
+++ b/test/Recursive.thrift
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+struct RecTree {
+ 1: list<RecTree> children
+ 2: i16 item
+}
+
+struct RecList {
+ 1: RecList nextitem (cpp.ref = "true")
+ 3: i16 item
+}
+
+struct CoRec {
+ 1: CoRec2 other (cpp.ref = "true")
+}
+
+struct CoRec2 {
+ 1: CoRec other
+}
+
+struct VectorTest {
+ 1: list<RecList> lister;
+}
+
+service TestService
+{
+ RecTree echoTree(1:RecTree tree)
+ RecList echoList(1:RecList lst)
+ CoRec echoCoRec(1:CoRec item)
+}