You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ca...@apache.org on 2013/06/06 13:53:28 UTC

git commit: THRIFT-1959: Add Union TMemoryBuffer support Client: csharp Patch: carl

Updated Branches:
  refs/heads/master b6dfc9036 -> 548244f04


THRIFT-1959: Add Union TMemoryBuffer support
Client: csharp
Patch: carl


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

Branch: refs/heads/master
Commit: 548244f0495898492616f520fec7b08c267574d9
Parents: b6dfc90
Author: Carl Yeksigian <ca...@apache.org>
Authored: Thu Jun 6 07:52:42 2013 -0400
Committer: Carl Yeksigian <ca...@apache.org>
Committed: Thu Jun 6 07:52:42 2013 -0400

----------------------------------------------------------------------
 lib/csharp/src/Transport/TMemoryBuffer.cs |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/548244f0/lib/csharp/src/Transport/TMemoryBuffer.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TMemoryBuffer.cs b/lib/csharp/src/Transport/TMemoryBuffer.cs
index c6e72f1..ca31fee 100644
--- a/lib/csharp/src/Transport/TMemoryBuffer.cs
+++ b/lib/csharp/src/Transport/TMemoryBuffer.cs
@@ -17,6 +17,7 @@
  * under the License.
  */
 
+using System;
 using System.IO;
 using System.Reflection;
 using Thrift.Protocol;
@@ -59,7 +60,7 @@ namespace Thrift.Transport {
 			get { return true; }
 		}
 
-		public static byte[] Serialize(TBase s) {
+		public static byte[] Serialize(TAbstractBase s) {
 			var t = new TMemoryBuffer();
 			var p = new TBinaryProtocol(t);
 
@@ -68,12 +69,18 @@ namespace Thrift.Transport {
 			return t.GetBuffer();
 		}
 
-		public static T DeSerialize<T>(byte[] buf) where T : TBase, new() {
-		       var t = new T();
-		       var trans = new TMemoryBuffer(buf);
-		       var p = new TBinaryProtocol(trans);
-		       t.Read(p);
-		       return t;
+		public static T DeSerialize<T>(byte[] buf) where T : TAbstractBase {
+			var trans = new TMemoryBuffer(buf);
+			var p = new TBinaryProtocol(trans);
+			if (typeof (TBase).IsAssignableFrom(typeof (T))) {
+				var method = typeof (T).GetMethod("Read", BindingFlags.Instance | BindingFlags.Public);
+				var t = Activator.CreateInstance<T>();
+				method.Invoke(t, new object[] {p});
+				return t;
+			 } else {
+			       var method = typeof (T).GetMethod("Read", BindingFlags.Static | BindingFlags.Public);
+				return (T) method.Invoke(null, new object[] {p});
+			}
 		}
 
 		private bool _IsDisposed;