From f36fda203565430086e23ab6a231fdc5ec3d4b48 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Mon, 24 Feb 2014 22:57:52 +0100 Subject: [PATCH] THRIFT-2305 TFramedTransport empty constructor should probably be private Patch: Alex Ausch & Jens Geyer --- 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(-) diff --git a/lib/csharp/src/Transport/TFramedTransport.cs b/lib/csharp/src/Transport/TFramedTransport.cs index 3d431120..aefbc097 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 + } } diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs index 1d50968d..7717cfb7 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) { } diff --git a/lib/csharp/src/Transport/TStreamTransport.cs b/lib/csharp/src/Transport/TStreamTransport.cs index 901b6096..eb1d2ccf 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() { } -- 2.17.1