You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2016/01/28 23:05:46 UTC

[1/5] thrift git commit: THRIFT-3501 Forward slash in comment causes compiler error Client: Compiler (general) Patch: Jens Geyer

Repository: thrift
Updated Branches:
  refs/heads/master 45c8e4935 -> a9346a308


THRIFT-3501 Forward slash in comment causes compiler error
Client: Compiler (general)
Patch: Jens Geyer


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/108fab82
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/108fab82
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/108fab82

Branch: refs/heads/master
Commit: 108fab82424b094f63f6eee2138f07e96ea117c5
Parents: 45c8e49
Author: Jens Geyer <je...@apache.org>
Authored: Thu Jan 28 21:30:08 2016 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Thu Jan 28 23:03:24 2016 +0100

----------------------------------------------------------------------
 compiler/cpp/src/thriftl.ll | 4 ++--
 test/DocTest.thrift         | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/108fab82/compiler/cpp/src/thriftl.ll
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll
index e3cf3e0..93ebc8e 100644
--- a/compiler/cpp/src/thriftl.ll
+++ b/compiler/cpp/src/thriftl.ll
@@ -111,8 +111,8 @@ dubconstant   ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?)
 identifier    ([a-zA-Z_](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*)
 whitespace    ([ \t\r\n]*)
 sillycomm     ("/*""*"*"*/")
-multicomm     ("/*"[^*]"/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
-doctext       ("/**"([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
+multicomm     ("/*"[^*]([^*]|"*"[^/])*"*/")
+doctext       ("/**"([^*]|"*"[^/])*"*/")
 comment       ("//"[^\n]*)
 unixcomment   ("#"[^\n]*)
 symbol        ([:;\,\{\}\(\)\=<>\[\]])

http://git-wip-us.apache.org/repos/asf/thrift/blob/108fab82/test/DocTest.thrift
----------------------------------------------------------------------
diff --git a/test/DocTest.thrift b/test/DocTest.thrift
index 9d19855..5d205b7 100644
--- a/test/DocTest.thrift
+++ b/test/DocTest.thrift
@@ -246,4 +246,12 @@ typedef i32 TotallyDegenerate
 
 /**no room for newline here*/
 
+/* * / */
+typedef i32 TestFor3501a
+
+/**
+ * /
+ */
+typedef i32 TestFor3501b
+
 /* THE END */


[5/5] thrift git commit: THRIFT-3377 Deep copy is actually shallow when using typedef members Client: Java Patch: Roshan George

Posted by je...@apache.org.
THRIFT-3377 Deep copy is actually shallow when using typedef members
Client: Java
Patch: Roshan George <ro...@arjie.com>

This closes #823


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/a9346a30
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/a9346a30
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/a9346a30

Branch: refs/heads/master
Commit: a9346a308f1e8736447693d1dd8ecba54516e942
Parents: c1fda24
Author: Roshan George <ro...@arjie.com>
Authored: Wed Jan 27 23:53:34 2016 -0800
Committer: Jens Geyer <je...@apache.org>
Committed: Thu Jan 28 23:05:06 2016 +0100

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_java_generator.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/a9346a30/compiler/cpp/src/generate/t_java_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index f711f2d..7c610fb 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -1532,7 +1532,7 @@ void t_java_generator::generate_java_struct_definition(ofstream& out,
   for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
     t_field* field = (*m_iter);
     std::string field_name = field->get_name();
-    t_type* type = field->get_type();
+    t_type* type = field->get_type()->get_true_type();
     bool can_be_null = type_can_be_null(type);
 
     if (can_be_null) {


[2/5] thrift git commit: THRIFT-3251 Add http transport for server to Go lib Client: Go Patch: claudemiro

Posted by je...@apache.org.
THRIFT-3251 Add http transport for server to Go lib
Client: Go
Patch: claudemiro <di...@gmail.com>

This closes #785


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/f8ca0552
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/f8ca0552
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/f8ca0552

Branch: refs/heads/master
Commit: f8ca05528e04a24b9f843c82c6600e4de5e42291
Parents: 108fab8
Author: claudemiro <di...@gmail.com>
Authored: Sun Jan 10 23:31:30 2016 -0200
Committer: Jens Geyer <je...@apache.org>
Committed: Thu Jan 28 23:05:02 2016 +0100

----------------------------------------------------------------------
 lib/go/thrift/http_transport.go         | 34 ++++++++++++++++++++++++++++
 test/go/src/bin/testserver/main.go      | 33 ++++++++++++++++++++++++---
 test/go/src/common/client.go            | 14 +++++++++++-
 test/go/src/common/clientserver_test.go | 15 +++++++++---
 test/go/src/common/server.go            | 28 +++++++++--------------
 test/tests.json                         |  3 ++-
 6 files changed, 102 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/f8ca0552/lib/go/thrift/http_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/http_transport.go b/lib/go/thrift/http_transport.go
new file mode 100644
index 0000000..f6d7458
--- /dev/null
+++ b/lib/go/thrift/http_transport.go
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package thrift
+
+import "net/http"
+
+// NewThriftHandlerFunc is a function that create a ready to use Apache Thrift Handler function
+func NewThriftHandlerFunc(processor TProcessor,
+	inPfactory, outPfactory TProtocolFactory) func(w http.ResponseWriter, r *http.Request) {
+
+	return func(w http.ResponseWriter, r *http.Request) {
+		w.Header().Add("Content-Type", "application/x-thrift")
+
+		transport := NewStreamTransport(r.Body, w)
+		processor.Process(inPfactory.GetProtocol(transport), outPfactory.GetProtocol(transport))
+	}
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/f8ca0552/test/go/src/bin/testserver/main.go
----------------------------------------------------------------------
diff --git a/test/go/src/bin/testserver/main.go b/test/go/src/bin/testserver/main.go
index 291dff5..0bf833d 100644
--- a/test/go/src/bin/testserver/main.go
+++ b/test/go/src/bin/testserver/main.go
@@ -22,7 +22,10 @@ package main
 import (
 	"common"
 	"flag"
+	"fmt"
 	"log"
+	"net/http"
+	"thrift"
 )
 
 var host = flag.String("host", "localhost", "Host to connect")
@@ -35,9 +38,33 @@ var certPath = flag.String("certPath", "keys", "Directory that contains SSL cert
 
 func main() {
 	flag.Parse()
-	server, err := common.StartServer(*host, *port, *domain_socket, *transport, *protocol, *ssl, *certPath, common.PrintingHandler)
+
+	processor, serverTransport, transportFactory, protocolFactory, err := common.GetServerParams(*host, *port, *domain_socket, *transport, *protocol, *ssl, *certPath, common.PrintingHandler)
+
 	if err != nil {
-		log.Fatalf("Unable to start server: ", err)
+		log.Fatalf("Unable to process server params: ", err)
+	}
+
+	if *transport == "http" {
+		http.HandleFunc("/", thrift.NewThriftHandlerFunc(processor, protocolFactory, protocolFactory))
+
+		if *ssl {
+			err := http.ListenAndServeTLS(fmt.Sprintf(":%d", *port),
+				*certPath+"/server.pem", *certPath+"/server.key", nil)
+
+			if err != nil {
+				fmt.Println(err)
+				return
+			}
+		} else {
+			http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
+		}
+	} else {
+		server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
+		if err = server.Listen(); err != nil {
+			return
+		}
+		go server.AcceptLoop()
+		server.Serve()
 	}
-	server.Serve()
 }

http://git-wip-us.apache.org/repos/asf/thrift/blob/f8ca0552/test/go/src/common/client.go
----------------------------------------------------------------------
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index e55dc6d..4251d91 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -25,6 +25,7 @@ import (
 	"flag"
 	"fmt"
 	"gen/thrifttest"
+	"net/http"
 	"thrift"
 )
 
@@ -75,10 +76,21 @@ func StartClient(
 	}
 	switch transport {
 	case "http":
-		trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/service", hostPort))
+		if ssl {
+			tr := &http.Transport{
+				TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+			}
+			client := &http.Client{Transport: tr}
+			trans, err = thrift.NewTHttpPostClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
+			fmt.Println(hostPort)
+		} else {
+			trans, err = thrift.NewTHttpPostClient(fmt.Sprintf("http://%s/", hostPort))
+		}
+
 		if err != nil {
 			return nil, err
 		}
+
 	case "framed":
 		trans = thrift.NewTFramedTransport(trans)
 	case "buffered":

http://git-wip-us.apache.org/repos/asf/thrift/blob/f8ca0552/test/go/src/common/clientserver_test.go
----------------------------------------------------------------------
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index 5c8915a..26fa7af 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -20,12 +20,13 @@
 package common
 
 import (
-	"github.com/golang/mock/gomock"
 	"errors"
 	"gen/thrifttest"
 	"reflect"
 	"testing"
 	"thrift"
+
+	"github.com/golang/mock/gomock"
 )
 
 type test_unit struct {
@@ -56,7 +57,15 @@ func doUnit(t *testing.T, unit *test_unit) {
 	ctrl := gomock.NewController(t)
 	defer ctrl.Finish()
 	handler := NewMockThriftTest(ctrl)
-	server, err := StartServer(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
+
+	processor, serverTransport, transportFactory, protocolFactory, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
+
+	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
+	if err = server.Listen(); err != nil {
+		return
+	}
+	go server.AcceptLoop()
+	server.Serve()
 	if err != nil {
 		t.Errorf("Unable to start server", err)
 		t.FailNow()
@@ -175,7 +184,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
 	}
 
 	// TODO: add TestBinary() call
-	
+
 	xs := thrifttest.NewXtruct()
 	xs.StringThing = "thing"
 	xs.ByteThing = 42

http://git-wip-us.apache.org/repos/asf/thrift/blob/f8ca0552/test/go/src/common/server.go
----------------------------------------------------------------------
diff --git a/test/go/src/common/server.go b/test/go/src/common/server.go
index dc380b2..5ac4400 100644
--- a/test/go/src/common/server.go
+++ b/test/go/src/common/server.go
@@ -37,7 +37,7 @@ func init() {
 	flag.BoolVar(&debugServerProtocol, "debug_server_protocol", false, "turn server protocol trace on")
 }
 
-func StartServer(
+func GetServerParams(
 	host string,
 	port int64,
 	domain_socket string,
@@ -45,8 +45,9 @@ func StartServer(
 	protocol string,
 	ssl bool,
 	certPath string,
-	handler thrifttest.ThriftTest) (srv *thrift.TSimpleServer, err error) {
+	handler thrifttest.ThriftTest) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
 
+	var err error
 	hostPort := fmt.Sprintf("%s:%d", host, port)
 
 	var protocolFactory thrift.TProtocolFactory
@@ -60,7 +61,7 @@ func StartServer(
 	case "binary":
 		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
 	default:
-		return nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+		return nil, nil, nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
 	}
 	if debugServerProtocol {
 		protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "server:")
@@ -70,7 +71,7 @@ func StartServer(
 	if ssl {
 		cfg := new(tls.Config)
 		if cert, err := tls.LoadX509KeyPair(certPath+"/server.crt", certPath+"/server.key"); err != nil {
-			return nil, err
+			return nil, nil, nil, nil, err
 		} else {
 			cfg.Certificates = append(cfg.Certificates, cert)
 		}
@@ -83,18 +84,15 @@ func StartServer(
 		}
 	}
 	if err != nil {
-		return nil, err
+		return nil, nil, nil, nil, err
 	}
 
 	var transportFactory thrift.TTransportFactory
 
 	switch transport {
 	case "http":
-		return nil, fmt.Errorf("Http server transport is not supported")
-		// trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/service", hostPort))
-		// if err != nil {
-		// 	return nil, err
-		// }
+		// there is no such factory, and we don't need any
+		transportFactory = nil
 	case "framed":
 		transportFactory = thrift.NewTTransportFactory()
 		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
@@ -105,13 +103,9 @@ func StartServer(
 	case "":
 		transportFactory = thrift.NewTTransportFactory()
 	default:
-		return nil, fmt.Errorf("Invalid transport specified %s", transport)
+		return nil, nil, nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
 	}
 	processor := thrifttest.NewThriftTestProcessor(handler)
-	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
-	if err = server.Listen(); err != nil {
-		return
-	}
-	go server.AcceptLoop()
-	return server, nil
+
+	return processor, serverTransport, transportFactory, protocolFactory, nil
 }

http://git-wip-us.apache.org/repos/asf/thrift/blob/f8ca0552/test/tests.json
----------------------------------------------------------------------
diff --git a/test/tests.json b/test/tests.json
index 8ba6186..6df5d41 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -45,7 +45,8 @@
     },
     "transports": [
       "buffered",
-      "framed"
+      "framed",
+      "http"
     ],
     "sockets": [
       "ip",


[3/5] thrift git commit: THRIFT-2157 generated code would cause ClassCastException Client: Java Patch: Marc Breslow

Posted by je...@apache.org.
THRIFT-2157 generated code would cause ClassCastException
Client: Java
Patch: Marc Breslow <ma...@devfactory.com>

This closes #822


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/3bf3ebfe
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/3bf3ebfe
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/3bf3ebfe

Branch: refs/heads/master
Commit: 3bf3ebfec390e45c1c5d42a654085360a76504b9
Parents: f8ca055
Author: Marc Breslow <ma...@devfactory.com>
Authored: Mon Jan 25 22:17:16 2016 -0500
Committer: Jens Geyer <je...@apache.org>
Committed: Thu Jan 28 23:05:03 2016 +0100

----------------------------------------------------------------------
 .../apache/thrift/TApplicationException.java    | 63 +++++++++++++-------
 lib/java/src/org/apache/thrift/TBase.java       | 18 +-----
 .../src/org/apache/thrift/TSerializable.java    | 44 ++++++++++++++
 .../src/org/apache/thrift/TServiceClient.java   |  3 +-
 4 files changed, 91 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/3bf3ebfe/lib/java/src/org/apache/thrift/TApplicationException.java
----------------------------------------------------------------------
diff --git a/lib/java/src/org/apache/thrift/TApplicationException.java b/lib/java/src/org/apache/thrift/TApplicationException.java
index b54a5ce..4d693d9 100644
--- a/lib/java/src/org/apache/thrift/TApplicationException.java
+++ b/lib/java/src/org/apache/thrift/TApplicationException.java
@@ -29,7 +29,7 @@ import org.apache.thrift.protocol.TType;
  * Application level exception
  *
  */
-public class TApplicationException extends TException {
+public class TApplicationException extends TException implements TSerializable {
 
   private static final TStruct TAPPLICATION_EXCEPTION_STRUCT = new TStruct("TApplicationException");
   private static final TField MESSAGE_FIELD = new TField("message", TType.STRING, (short)1);
@@ -50,6 +50,7 @@ public class TApplicationException extends TException {
   public static final int UNSUPPORTED_CLIENT_TYPE = 10;
 
   protected int type_ = UNKNOWN;
+  private String message_ = null;
 
   public TApplicationException() {
     super();
@@ -73,7 +74,18 @@ public class TApplicationException extends TException {
     return type_;
   }
 
-  public static TApplicationException read(TProtocol iprot) throws TException {
+  @Override
+  public String getMessage() {
+    if (message_ == null) {
+      return super.getMessage();
+    }
+    else {
+      return message_;
+    }
+  }
+
+  public void read(TProtocol iprot) throws TException
+  {
     TField field;
     iprot.readStructBegin();
 
@@ -86,32 +98,43 @@ public class TApplicationException extends TException {
         break;
       }
       switch (field.id) {
-      case 1:
-        if (field.type == TType.STRING) {
-          message = iprot.readString();
-        } else {
-          TProtocolUtil.skip(iprot, field.type);
-        }
-        break;
-      case 2:
-        if (field.type == TType.I32) {
-          type = iprot.readI32();
-        } else {
+        case 1:
+          if (field.type == TType.STRING) {
+            message = iprot.readString();
+          } else {
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        case 2:
+          if (field.type == TType.I32) {
+            type = iprot.readI32();
+          } else {
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        default:
           TProtocolUtil.skip(iprot, field.type);
-        }
-        break;
-      default:
-        TProtocolUtil.skip(iprot, field.type);
-        break;
+          break;
       }
       iprot.readFieldEnd();
     }
     iprot.readStructEnd();
+    type_ = type;
+    message_ = message;
+  }
 
-    return new TApplicationException(type, message);
+  /**
+   * Convenience factory method for constructing a TApplicationException given a TProtocol input
+   */
+  public static TApplicationException readFrom(TProtocol iprot) throws TException
+  {
+    TApplicationException result = new TApplicationException();
+    result.read(iprot);
+    return result;
   }
 
-  public void write(TProtocol oprot) throws TException {
+  public void write(TProtocol oprot) throws TException
+  {
     oprot.writeStructBegin(TAPPLICATION_EXCEPTION_STRUCT);
     if (getMessage() != null) {
       oprot.writeFieldBegin(MESSAGE_FIELD);

http://git-wip-us.apache.org/repos/asf/thrift/blob/3bf3ebfe/lib/java/src/org/apache/thrift/TBase.java
----------------------------------------------------------------------
diff --git a/lib/java/src/org/apache/thrift/TBase.java b/lib/java/src/org/apache/thrift/TBase.java
index ef70e5b..e1489d5 100644
--- a/lib/java/src/org/apache/thrift/TBase.java
+++ b/lib/java/src/org/apache/thrift/TBase.java
@@ -27,21 +27,7 @@ import org.apache.thrift.protocol.TProtocol;
  * Generic base interface for generated Thrift objects.
  *
  */
-public interface TBase<T extends TBase<T,F>, F extends TFieldIdEnum> extends Comparable<T>,  Serializable {
-
-  /**
-   * Reads the TObject from the given input protocol.
-   *
-   * @param iprot Input protocol
-   */
-  public void read(TProtocol iprot) throws TException;
-
-  /**
-   * Writes the objects out to the protocol
-   *
-   * @param oprot Output protocol
-   */
-  public void write(TProtocol oprot) throws TException;
+public interface TBase<T extends TBase<T,F>, F extends TFieldIdEnum> extends Comparable<T>,  TSerializable, Serializable {
 
   /**
    * Get the F instance that corresponds to fieldId.
@@ -56,7 +42,7 @@ public interface TBase<T extends TBase<T,F>, F extends TFieldIdEnum> extends Com
   public boolean isSet(F field);
 
   /**
-   * Get a field's value by field variable. Primitive types will be wrapped in 
+   * Get a field's value by field variable. Primitive types will be wrapped in
    * the appropriate "boxed" types.
    *
    * @param field

http://git-wip-us.apache.org/repos/asf/thrift/blob/3bf3ebfe/lib/java/src/org/apache/thrift/TSerializable.java
----------------------------------------------------------------------
diff --git a/lib/java/src/org/apache/thrift/TSerializable.java b/lib/java/src/org/apache/thrift/TSerializable.java
new file mode 100644
index 0000000..80002c7
--- /dev/null
+++ b/lib/java/src/org/apache/thrift/TSerializable.java
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+package org.apache.thrift;
+
+import org.apache.thrift.protocol.TProtocol;
+
+/**
+ * Generic base interface for generated Thrift objects.
+ *
+ */
+public interface TSerializable {
+
+  /**
+   * Reads the TObject from the given input protocol.
+   *
+   * @param iprot Input protocol
+   */
+  public void read(TProtocol iprot) throws TException;
+
+  /**
+   * Writes the objects out to the protocol
+   *
+   * @param oprot Output protocol
+   */
+  public void write(TProtocol oprot) throws TException;
+
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/3bf3ebfe/lib/java/src/org/apache/thrift/TServiceClient.java
----------------------------------------------------------------------
diff --git a/lib/java/src/org/apache/thrift/TServiceClient.java b/lib/java/src/org/apache/thrift/TServiceClient.java
index 259a507..31153ec 100644
--- a/lib/java/src/org/apache/thrift/TServiceClient.java
+++ b/lib/java/src/org/apache/thrift/TServiceClient.java
@@ -76,7 +76,8 @@ public abstract class TServiceClient {
   protected void receiveBase(TBase<?,?> result, String methodName) throws TException {
     TMessage msg = iprot_.readMessageBegin();
     if (msg.type == TMessageType.EXCEPTION) {
-      TApplicationException x = TApplicationException.read(iprot_);
+      TApplicationException x = new TApplicationException();
+      x.read(iprot_);
       iprot_.readMessageEnd();
       throw x;
     }


[4/5] thrift git commit: THRIFT-3582 Erlang libraries should have service metadata Client: Erlang Patch: Steve Cohen

Posted by je...@apache.org.
THRIFT-3582 Erlang libraries should have service metadata
Client: Erlang
Patch: Steve Cohen <st...@pinterest.com>


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/c1fda249
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/c1fda249
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/c1fda249

Branch: refs/heads/master
Commit: c1fda249f8ec125658392f9642f7773c582cbe20
Parents: 3bf3ebf
Author: Jens Geyer <je...@apache.org>
Authored: Thu Jan 28 22:41:36 2016 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Thu Jan 28 23:05:05 2016 +0100

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_erl_generator.cc | 102 ++++++++++++++++++++++
 1 file changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/c1fda249/compiler/cpp/src/generate/t_erl_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_erl_generator.cc b/compiler/cpp/src/generate/t_erl_generator.cc
index 60fecd4..78d757e 100644
--- a/compiler/cpp/src/generate/t_erl_generator.cc
+++ b/compiler/cpp/src/generate/t_erl_generator.cc
@@ -101,12 +101,16 @@ public:
   void generate_erl_struct_info(std::ostream& out, t_struct* tstruct);
   void generate_erl_extended_struct_info(std::ostream& out, t_struct* tstruct);
   void generate_erl_function_helpers(t_function* tfunction);
+  void generate_type_metadata(std::string function_name, vector<string> names);
+  void generate_enum_info(t_enum* tenum);
+  void generate_enum_metadata();
 
   /**
    * Service-level generation functions
    */
 
   void generate_service_helpers(t_service* tservice);
+  void generate_service_metadata(t_service* tservice);
   void generate_service_interface(t_service* tservice);
   void generate_function_info(t_service* tservice, t_function* tfunction);
 
@@ -204,6 +208,13 @@ private:
   std::ostringstream f_service_;
   std::ofstream f_service_file_;
   std::ofstream f_service_hrl_;
+
+  /**
+   * Metadata containers
+   */
+  std::vector<std::string> v_struct_names_;
+  std::vector<std::string> v_enum_names_;
+  std::vector<t_enum*> v_enums_;
 };
 
 /**
@@ -312,6 +323,10 @@ void t_erl_generator::close_generator() {
 
   export_types_string("struct_info", 1);
   export_types_string("struct_info_ext", 1);
+  export_types_string("enum_info", 1);
+  export_types_string("enum_names", 0);
+  export_types_string("struct_names", 0);
+
   f_types_file_ << "-export([" << export_types_lines_.str() << "])." << endl << endl;
 
   f_types_file_ << f_info_.str();
@@ -320,6 +335,10 @@ void t_erl_generator::close_generator() {
   f_types_file_ << f_info_ext_.str();
   f_types_file_ << "struct_info_ext(_) -> erlang:error(function_clause)." << endl << endl;
 
+  generate_type_metadata("struct_names", v_struct_names_);
+  generate_enum_metadata();
+  generate_type_metadata("enum_names", v_enum_names_);
+
   hrl_footer(f_types_hrl_file_, string("BOGUS"));
 
   f_types_file_.close();
@@ -327,6 +346,27 @@ void t_erl_generator::close_generator() {
   f_consts_.close();
 }
 
+void t_erl_generator::generate_type_metadata(std::string function_name, vector<string> names) {
+  vector<string>::iterator s_iter;
+  size_t num_structs = names.size();
+
+  indent(f_types_file_) << function_name << "() ->\n";
+  indent_up();
+  indent(f_types_file_) << "[";
+
+
+  for(size_t i=0; i < num_structs; i++) {
+    f_types_file_ << atomify(names.at(i));
+
+    if (i < num_structs - 1) {
+      f_types_file_ << ", ";
+    }
+  }
+
+  f_types_file_ << "].\n\n";
+  indent_down();
+}
+
 /**
  * Generates a typedef. no op
  *
@@ -346,6 +386,9 @@ void t_erl_generator::generate_enum(t_enum* tenum) {
   vector<t_enum_value*> constants = tenum->get_constants();
   vector<t_enum_value*>::iterator c_iter;
 
+  v_enums_.push_back(tenum);
+  v_enum_names_.push_back(tenum->get_name());
+
   for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
     int value = (*c_iter)->get_value();
     string name = (*c_iter)->get_name();
@@ -357,6 +400,40 @@ void t_erl_generator::generate_enum(t_enum* tenum) {
   f_types_hrl_file_ << endl;
 }
 
+void t_erl_generator::generate_enum_info(t_enum* tenum){
+  vector<t_enum_value*> constants = tenum->get_constants();
+  size_t num_constants = constants.size();
+
+  indent(f_types_file_) << "enum_info(" << atomify(tenum->get_name()) << ") ->\n";
+  indent_up();
+  indent(f_types_file_) << "[\n";
+
+  for(size_t i=0; i < num_constants; i++) {
+    indent_up();
+    t_enum_value* value = constants.at(i);
+    indent(f_types_file_) << "{" << atomify(value->get_name()) << ", " << value->get_value() << "}";
+
+    if (i < num_constants - 1) {
+      f_types_file_ << ",\n";
+    }
+    indent_down();
+  }
+  f_types_file_ << "\n";
+  indent(f_types_file_) << "];\n\n";
+  indent_down();
+}
+
+void t_erl_generator::generate_enum_metadata() {
+  size_t enum_count = v_enums_.size();
+
+  for(size_t i=0; i < enum_count; i++) {
+    t_enum* tenum = v_enums_.at(i);
+    generate_enum_info(tenum);
+  }
+
+  indent(f_types_file_) << "enum_info(_) -> erlang:error(function_clause).\n\n";
+}
+
 /**
  * Generate a constant value
  */
@@ -567,6 +644,7 @@ string t_erl_generator::render_member_requiredness(t_field* field) {
  * Generates a struct
  */
 void t_erl_generator::generate_struct(t_struct* tstruct) {
+  v_struct_names_.push_back(tstruct->get_name());
   generate_erl_struct(tstruct, false);
 }
 
@@ -705,6 +783,8 @@ void t_erl_generator::generate_service(t_service* tservice) {
 
   generate_service_interface(tservice);
 
+  generate_service_metadata(tservice);
+
   // indent_down();
 
   f_service_file_ << erl_autogen_comment() << endl << "-module(" << service_name_ << "_thrift)."
@@ -724,6 +804,28 @@ void t_erl_generator::generate_service(t_service* tservice) {
   f_service_hrl_.close();
 }
 
+void t_erl_generator::generate_service_metadata(t_service* tservice) {
+  export_string("function_names", 0);
+  vector<t_function*> functions = tservice->get_functions();
+  vector<t_function*>::iterator f_iter;
+  size_t num_functions = functions.size();
+
+  indent(f_service_) << "function_names() -> " << endl;
+  indent_up();
+  indent(f_service_) << "[";
+
+  for (size_t i=0; i < num_functions; i++) {
+    t_function* current = functions.at(i);
+    f_service_ << atomify(current->get_name());
+    if (i < num_functions - 1) {
+      f_service_ << ", ";
+    }
+  }
+
+  f_service_ << "].\n\n";
+  indent_down();
+}
+
 /**
  * Generates helper functions for a service.
  *