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 2014/02/24 22:58:26 UTC

git commit: THRIFT-2305 TFramedTransport empty constructor should probably be private

Repository: thrift
Updated Branches:
  refs/heads/master 98d9ef2bd -> f36fda203


THRIFT-2305 TFramedTransport empty constructor should probably be private

Patch: Alex Ausch  & Jens Geyer


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

Branch: refs/heads/master
Commit: f36fda203565430086e23ab6a231fdc5ec3d4b48
Parents: 98d9ef2
Author: Jens Geyer <je...@apache.org>
Authored: Mon Feb 24 22:57:52 2014 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Mon Feb 24 22:57:52 2014 +0100

----------------------------------------------------------------------
 lib/csharp/src/Transport/TFramedTransport.cs | 71 +++++++++++++----------
 lib/csharp/src/Transport/TSocket.cs          |  3 +-
 lib/csharp/src/Transport/TStreamTransport.cs |  2 +-
 3 files changed, 44 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/f36fda20/lib/csharp/src/Transport/TFramedTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TFramedTransport.cs b/lib/csharp/src/Transport/TFramedTransport.cs
index 3d43112..aefbc09 100644
--- a/lib/csharp/src/Transport/TFramedTransport.cs
+++ b/lib/csharp/src/Transport/TFramedTransport.cs
@@ -20,7 +20,7 @@ using System;
 using System.IO;
 
 namespace Thrift.Transport
-{
+{ 
   public class TFramedTransport : TTransport, IDisposable
 	{
 		protected TTransport transport = null;
@@ -38,7 +38,7 @@ namespace Thrift.Transport
 			}
 		}
 
-		public TFramedTransport()
+		protected TFramedTransport()
 		{
 			InitWriteBuffer();
 		}
@@ -87,12 +87,7 @@ namespace Thrift.Transport
 		{
 			byte[] i32rd = new byte[header_size];
 			transport.ReadAll(i32rd, 0, header_size);
-			int size =
-				((i32rd[0] & 0xff) << 24) |
-				((i32rd[1] & 0xff) << 16) |
-				((i32rd[2] & 0xff) <<  8) |
-				((i32rd[3] & 0xff));
-
+			int size = DecodeFrameSize(i32rd);
 
 			byte[] buff = new byte[size];
 			transport.ReadAll(buff, 0, size);
@@ -115,10 +110,7 @@ namespace Thrift.Transport
 			InitWriteBuffer();
 
 			// Inject message header into the reserved buffer space
-			buf[0] = (byte)(0xff & (data_len >> 24));
-			buf[1] = (byte)(0xff & (data_len >> 16));
-			buf[2] = (byte)(0xff & (data_len >> 8));
-			buf[3] = (byte)(0xff & (data_len));
+			EncodeFrameSize(data_len,ref buf);
 
 			// Send the entire message at once
 			transport.Write(buf, 0, len);
@@ -134,22 +126,41 @@ namespace Thrift.Transport
 			// Reserve space for message header to be put right before sending it out
 			writeBuffer.Write ( header_dummy, 0, header_size );
 		}
-    #region " IDisposable Support "
-    private bool _IsDisposed;
-
-    // IDisposable
-    protected override void Dispose(bool disposing)
-    {
-      if (!_IsDisposed)
-      {
-        if (disposing)
-        {
-          if (readBuffer != null)
-            readBuffer.Dispose();
-        }
-      }
-      _IsDisposed = true;
-    }
-    #endregion
-  }
+		
+		private static void EncodeFrameSize(int frameSize, ref byte[] buf) 
+		{
+			buf[0] = (byte)(0xff & (frameSize >> 24));
+			buf[1] = (byte)(0xff & (frameSize >> 16));
+			buf[2] = (byte)(0xff & (frameSize >> 8));
+			buf[3] = (byte)(0xff & (frameSize));
+		}
+		
+		private static int DecodeFrameSize(byte[] buf)
+		{
+			return 
+				((buf[0] & 0xff) << 24) |
+				((buf[1] & 0xff) << 16) |
+				((buf[2] & 0xff) <<  8) |
+				((buf[3] & 0xff));
+		}
+
+
+		#region " IDisposable Support "
+		private bool _IsDisposed;
+		
+		// IDisposable
+		protected override void Dispose(bool disposing)
+		{
+			if (!_IsDisposed)
+			{
+				if (disposing)
+				{
+					if (readBuffer != null)
+						readBuffer.Dispose();
+				}
+			}
+			_IsDisposed = true;
+		}
+		#endregion
+	}
 }

http://git-wip-us.apache.org/repos/asf/thrift/blob/f36fda20/lib/csharp/src/Transport/TSocket.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs
index 1d50968..7717cfb 100644
--- a/lib/csharp/src/Transport/TSocket.cs
+++ b/lib/csharp/src/Transport/TSocket.cs
@@ -44,7 +44,8 @@ namespace Thrift.Transport
 			}
 		}
 
-		public TSocket(string host, int port) : this(host, port, 0)
+		public TSocket(string host, int port) 
+		    : this(host, port, 0)
 		{
 		}
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/f36fda20/lib/csharp/src/Transport/TStreamTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TStreamTransport.cs b/lib/csharp/src/Transport/TStreamTransport.cs
index 901b609..eb1d2cc 100644
--- a/lib/csharp/src/Transport/TStreamTransport.cs
+++ b/lib/csharp/src/Transport/TStreamTransport.cs
@@ -31,7 +31,7 @@ namespace Thrift.Transport
 		protected Stream inputStream;
 		protected Stream outputStream;
 
-		public TStreamTransport()
+		protected TStreamTransport()
 		{
 		}