THRIFT-2768: Whitespace Fixup
Client: C#, Delphi
Patch: Jens Geyer
diff --git a/lib/csharp/src/Collections/TCollections.cs b/lib/csharp/src/Collections/TCollections.cs
index 23fd8da..f0bb1de 100644
--- a/lib/csharp/src/Collections/TCollections.cs
+++ b/lib/csharp/src/Collections/TCollections.cs
@@ -21,74 +21,74 @@
namespace Thrift.Collections
{
- public class TCollections
- {
- /// <summary>
- /// This will return true if the two collections are value-wise the same.
- /// If the collection contains a collection, the collections will be compared using this method.
- /// </summary>
- public static bool Equals (IEnumerable first, IEnumerable second)
- {
- if (first == null && second == null)
- {
- return true;
- }
- if (first == null || second == null)
- {
- return false;
- }
- IEnumerator fiter = first.GetEnumerator ();
- IEnumerator siter = second.GetEnumerator ();
+ public class TCollections
+ {
+ /// <summary>
+ /// This will return true if the two collections are value-wise the same.
+ /// If the collection contains a collection, the collections will be compared using this method.
+ /// </summary>
+ public static bool Equals (IEnumerable first, IEnumerable second)
+ {
+ if (first == null && second == null)
+ {
+ return true;
+ }
+ if (first == null || second == null)
+ {
+ return false;
+ }
+ IEnumerator fiter = first.GetEnumerator ();
+ IEnumerator siter = second.GetEnumerator ();
- bool fnext = fiter.MoveNext ();
- bool snext = siter.MoveNext ();
- while (fnext && snext)
- {
- IEnumerable fenum = fiter.Current as IEnumerable;
- IEnumerable senum = siter.Current as IEnumerable;
- if (fenum != null && senum != null)
- {
- if (!Equals(fenum, senum))
- {
- return false;
- }
- }
- else if (fenum == null ^ senum == null)
- {
- return false;
- }
- else if (!Equals(fiter.Current, siter.Current))
- {
- return false;
- }
- fnext = fiter.MoveNext();
- snext = siter.MoveNext();
- }
+ bool fnext = fiter.MoveNext ();
+ bool snext = siter.MoveNext ();
+ while (fnext && snext)
+ {
+ IEnumerable fenum = fiter.Current as IEnumerable;
+ IEnumerable senum = siter.Current as IEnumerable;
+ if (fenum != null && senum != null)
+ {
+ if (!Equals(fenum, senum))
+ {
+ return false;
+ }
+ }
+ else if (fenum == null ^ senum == null)
+ {
+ return false;
+ }
+ else if (!Equals(fiter.Current, siter.Current))
+ {
+ return false;
+ }
+ fnext = fiter.MoveNext();
+ snext = siter.MoveNext();
+ }
- return fnext == snext;
- }
+ return fnext == snext;
+ }
- /// <summary>
- /// This returns a hashcode based on the value of the enumerable.
- /// </summary>
- public static int GetHashCode (IEnumerable enumerable)
- {
- if (enumerable == null)
- {
- return 0;
- }
+ /// <summary>
+ /// This returns a hashcode based on the value of the enumerable.
+ /// </summary>
+ public static int GetHashCode (IEnumerable enumerable)
+ {
+ if (enumerable == null)
+ {
+ return 0;
+ }
- int hashcode = 0;
- foreach (Object obj in enumerable)
- {
- IEnumerable enum2 = obj as IEnumerable;
- int objHash = enum2 == null ? obj.GetHashCode () : GetHashCode (enum2);
- unchecked
- {
- hashcode = (hashcode * 397) ^ (objHash);
- }
- }
- return hashcode;
- }
- }
+ int hashcode = 0;
+ foreach (Object obj in enumerable)
+ {
+ IEnumerable enum2 = obj as IEnumerable;
+ int objHash = enum2 == null ? obj.GetHashCode () : GetHashCode (enum2);
+ unchecked
+ {
+ hashcode = (hashcode * 397) ^ (objHash);
+ }
+ }
+ return hashcode;
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/csharp/src/Collections/THashSet.cs b/lib/csharp/src/Collections/THashSet.cs
index b71a8d2..e29271a 100644
--- a/lib/csharp/src/Collections/THashSet.cs
+++ b/lib/csharp/src/Collections/THashSet.cs
@@ -30,131 +30,131 @@
#if SILVERLIGHT
[DataContract]
#else
- [Serializable]
+ [Serializable]
#endif
- public class THashSet<T> : ICollection<T>
- {
+ public class THashSet<T> : ICollection<T>
+ {
#if NET_2_0 || SILVERLIGHT
#if SILVERLIGHT
[DataMember]
#endif
TDictSet<T> set = new TDictSet<T>();
#else
- HashSet<T> set = new HashSet<T>();
+ HashSet<T> set = new HashSet<T>();
#endif
- public int Count
- {
- get { return set.Count; }
- }
+ public int Count
+ {
+ get { return set.Count; }
+ }
- public bool IsReadOnly
- {
- get { return false; }
- }
+ public bool IsReadOnly
+ {
+ get { return false; }
+ }
- public void Add(T item)
- {
- set.Add(item);
- }
+ public void Add(T item)
+ {
+ set.Add(item);
+ }
- public void Clear()
- {
- set.Clear();
- }
+ public void Clear()
+ {
+ set.Clear();
+ }
- public bool Contains(T item)
- {
- return set.Contains(item);
- }
+ public bool Contains(T item)
+ {
+ return set.Contains(item);
+ }
- public void CopyTo(T[] array, int arrayIndex)
- {
- set.CopyTo(array, arrayIndex);
- }
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ set.CopyTo(array, arrayIndex);
+ }
- public IEnumerator GetEnumerator()
- {
- return set.GetEnumerator();
- }
+ public IEnumerator GetEnumerator()
+ {
+ return set.GetEnumerator();
+ }
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return ((IEnumerable<T>)set).GetEnumerator();
- }
+ IEnumerator<T> IEnumerable<T>.GetEnumerator()
+ {
+ return ((IEnumerable<T>)set).GetEnumerator();
+ }
- public bool Remove(T item)
- {
- return set.Remove(item);
- }
+ public bool Remove(T item)
+ {
+ return set.Remove(item);
+ }
#if NET_2_0 || SILVERLIGHT
#if SILVERLIGHT
[DataContract]
#endif
private class TDictSet<V> : ICollection<V>
- {
+ {
#if SILVERLIGHT
[DataMember]
#endif
- Dictionary<V, TDictSet<V>> dict = new Dictionary<V, TDictSet<V>>();
+ Dictionary<V, TDictSet<V>> dict = new Dictionary<V, TDictSet<V>>();
- public int Count
- {
- get { return dict.Count; }
- }
+ public int Count
+ {
+ get { return dict.Count; }
+ }
- public bool IsReadOnly
- {
- get { return false; }
- }
+ public bool IsReadOnly
+ {
+ get { return false; }
+ }
- public IEnumerator GetEnumerator()
- {
- return ((IEnumerable)dict.Keys).GetEnumerator();
- }
+ public IEnumerator GetEnumerator()
+ {
+ return ((IEnumerable)dict.Keys).GetEnumerator();
+ }
- IEnumerator<V> IEnumerable<V>.GetEnumerator()
- {
- return dict.Keys.GetEnumerator();
- }
+ IEnumerator<V> IEnumerable<V>.GetEnumerator()
+ {
+ return dict.Keys.GetEnumerator();
+ }
- public bool Add(V item)
- {
- if (!dict.ContainsKey(item))
- {
- dict[item] = this;
- return true;
- }
+ public bool Add(V item)
+ {
+ if (!dict.ContainsKey(item))
+ {
+ dict[item] = this;
+ return true;
+ }
- return false;
- }
+ return false;
+ }
- void ICollection<V>.Add(V item)
- {
- Add(item);
- }
+ void ICollection<V>.Add(V item)
+ {
+ Add(item);
+ }
- public void Clear()
- {
- dict.Clear();
- }
+ public void Clear()
+ {
+ dict.Clear();
+ }
- public bool Contains(V item)
- {
- return dict.ContainsKey(item);
- }
+ public bool Contains(V item)
+ {
+ return dict.ContainsKey(item);
+ }
- public void CopyTo(V[] array, int arrayIndex)
- {
- dict.Keys.CopyTo(array, arrayIndex);
- }
+ public void CopyTo(V[] array, int arrayIndex)
+ {
+ dict.Keys.CopyTo(array, arrayIndex);
+ }
- public bool Remove(V item)
- {
- return dict.Remove(item);
- }
- }
+ public bool Remove(V item)
+ {
+ return dict.Remove(item);
+ }
+ }
#endif
- }
+ }
}
diff --git a/lib/csharp/src/Protocol/TAbstractBase.cs b/lib/csharp/src/Protocol/TAbstractBase.cs
index de2e3db..c0d5abe 100644
--- a/lib/csharp/src/Protocol/TAbstractBase.cs
+++ b/lib/csharp/src/Protocol/TAbstractBase.cs
@@ -19,11 +19,11 @@
namespace Thrift.Protocol
{
- public interface TAbstractBase
- {
- ///
- /// Writes the objects out to the protocol
- ///
- void Write(TProtocol tProtocol);
- }
+ public interface TAbstractBase
+ {
+ ///
+ /// Writes the objects out to the protocol
+ ///
+ void Write(TProtocol tProtocol);
+ }
}
diff --git a/lib/csharp/src/Protocol/TBase.cs b/lib/csharp/src/Protocol/TBase.cs
index b8b36fb..350ff49 100644
--- a/lib/csharp/src/Protocol/TBase.cs
+++ b/lib/csharp/src/Protocol/TBase.cs
@@ -19,11 +19,11 @@
namespace Thrift.Protocol
{
- public interface TBase : TAbstractBase
- {
- ///
- /// Reads the TObject from the given input protocol.
- ///
- void Read(TProtocol tProtocol);
- }
+ public interface TBase : TAbstractBase
+ {
+ ///
+ /// Reads the TObject from the given input protocol.
+ ///
+ void Read(TProtocol tProtocol);
+ }
}
diff --git a/lib/csharp/src/Protocol/TBase64Utils.cs b/lib/csharp/src/Protocol/TBase64Utils.cs
index 78c3767..9eaaebd 100644
--- a/lib/csharp/src/Protocol/TBase64Utils.cs
+++ b/lib/csharp/src/Protocol/TBase64Utils.cs
@@ -21,80 +21,80 @@
namespace Thrift.Protocol
{
- internal static class TBase64Utils
- {
- internal const string ENCODE_TABLE =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ internal static class TBase64Utils
+ {
+ internal const string ENCODE_TABLE =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- internal static void encode(byte[] src, int srcOff, int len, byte[] dst,
- int dstOff)
- {
- dst[dstOff] = (byte)ENCODE_TABLE[(src[srcOff] >> 2) & 0x3F];
- if (len == 3)
- {
- dst[dstOff + 1] =
- (byte)ENCODE_TABLE[
- ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)];
- dst[dstOff + 2] =
- (byte)ENCODE_TABLE[
- ((src[srcOff + 1] << 2) & 0x3C) | ((src[srcOff + 2] >> 6) & 0x03)];
- dst[dstOff + 3] =
- (byte)ENCODE_TABLE[src[srcOff + 2] & 0x3F];
- }
- else if (len == 2)
- {
- dst[dstOff + 1] =
- (byte)ENCODE_TABLE[
- ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)];
- dst[dstOff + 2] =
- (byte)ENCODE_TABLE[(src[srcOff + 1] << 2) & 0x3C];
+ internal static void encode(byte[] src, int srcOff, int len, byte[] dst,
+ int dstOff)
+ {
+ dst[dstOff] = (byte)ENCODE_TABLE[(src[srcOff] >> 2) & 0x3F];
+ if (len == 3)
+ {
+ dst[dstOff + 1] =
+ (byte)ENCODE_TABLE[
+ ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)];
+ dst[dstOff + 2] =
+ (byte)ENCODE_TABLE[
+ ((src[srcOff + 1] << 2) & 0x3C) | ((src[srcOff + 2] >> 6) & 0x03)];
+ dst[dstOff + 3] =
+ (byte)ENCODE_TABLE[src[srcOff + 2] & 0x3F];
+ }
+ else if (len == 2)
+ {
+ dst[dstOff + 1] =
+ (byte)ENCODE_TABLE[
+ ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)];
+ dst[dstOff + 2] =
+ (byte)ENCODE_TABLE[(src[srcOff + 1] << 2) & 0x3C];
- }
- else
- { // len == 1) {
- dst[dstOff + 1] =
- (byte)ENCODE_TABLE[(src[srcOff] << 4) & 0x30];
- }
- }
+ }
+ else
+ { // len == 1) {
+ dst[dstOff + 1] =
+ (byte)ENCODE_TABLE[(src[srcOff] << 4) & 0x30];
+ }
+ }
- private static int[] DECODE_TABLE = {
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
- 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
- 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
- -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
- 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- };
+ private static int[] DECODE_TABLE = {
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
+ 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
+ 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
+ -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
+ 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ };
- internal static void decode(byte[] src, int srcOff, int len, byte[] dst,
- int dstOff)
- {
- dst[dstOff] = (byte)
- ((DECODE_TABLE[src[srcOff] & 0x0FF] << 2) |
- (DECODE_TABLE[src[srcOff + 1] & 0x0FF] >> 4));
- if (len > 2)
- {
- dst[dstOff + 1] = (byte)
- (((DECODE_TABLE[src[srcOff + 1] & 0x0FF] << 4) & 0xF0) |
- (DECODE_TABLE[src[srcOff + 2] & 0x0FF] >> 2));
- if (len > 3)
- {
- dst[dstOff + 2] = (byte)
- (((DECODE_TABLE[src[srcOff + 2] & 0x0FF] << 6) & 0xC0) |
- DECODE_TABLE[src[srcOff + 3] & 0x0FF]);
- }
- }
- }
+ internal static void decode(byte[] src, int srcOff, int len, byte[] dst,
+ int dstOff)
+ {
+ dst[dstOff] = (byte)
+ ((DECODE_TABLE[src[srcOff] & 0x0FF] << 2) |
+ (DECODE_TABLE[src[srcOff + 1] & 0x0FF] >> 4));
+ if (len > 2)
+ {
+ dst[dstOff + 1] = (byte)
+ (((DECODE_TABLE[src[srcOff + 1] & 0x0FF] << 4) & 0xF0) |
+ (DECODE_TABLE[src[srcOff + 2] & 0x0FF] >> 2));
+ if (len > 3)
+ {
+ dst[dstOff + 2] = (byte)
+ (((DECODE_TABLE[src[srcOff + 2] & 0x0FF] << 6) & 0xC0) |
+ DECODE_TABLE[src[srcOff + 3] & 0x0FF]);
+ }
+ }
+ }
- }
+ }
}
diff --git a/lib/csharp/src/Protocol/TBinaryProtocol.cs b/lib/csharp/src/Protocol/TBinaryProtocol.cs
index 2e86a70..4eceb86 100644
--- a/lib/csharp/src/Protocol/TBinaryProtocol.cs
+++ b/lib/csharp/src/Protocol/TBinaryProtocol.cs
@@ -27,324 +27,324 @@
namespace Thrift.Protocol
{
- public class TBinaryProtocol : TProtocol
- {
- protected const uint VERSION_MASK = 0xffff0000;
- protected const uint VERSION_1 = 0x80010000;
+ public class TBinaryProtocol : TProtocol
+ {
+ protected const uint VERSION_MASK = 0xffff0000;
+ protected const uint VERSION_1 = 0x80010000;
- protected bool strictRead_ = false;
- protected bool strictWrite_ = true;
+ protected bool strictRead_ = false;
+ protected bool strictWrite_ = true;
- #region BinaryProtocol Factory
- /**
- * Factory
- */
- public class Factory : TProtocolFactory {
+ #region BinaryProtocol Factory
+ /**
+ * Factory
+ */
+ public class Factory : TProtocolFactory {
- protected bool strictRead_ = false;
- protected bool strictWrite_ = true;
+ protected bool strictRead_ = false;
+ protected bool strictWrite_ = true;
- public Factory()
- :this(false, true)
- {
- }
+ public Factory()
+ :this(false, true)
+ {
+ }
- public Factory(bool strictRead, bool strictWrite)
- {
- strictRead_ = strictRead;
- strictWrite_ = strictWrite;
- }
+ public Factory(bool strictRead, bool strictWrite)
+ {
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
- public TProtocol GetProtocol(TTransport trans) {
- return new TBinaryProtocol(trans, strictRead_, strictWrite_);
- }
- }
+ public TProtocol GetProtocol(TTransport trans) {
+ return new TBinaryProtocol(trans, strictRead_, strictWrite_);
+ }
+ }
- #endregion
+ #endregion
- public TBinaryProtocol(TTransport trans)
- : this(trans, false, true)
- {
- }
+ public TBinaryProtocol(TTransport trans)
+ : this(trans, false, true)
+ {
+ }
- public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite)
- :base(trans)
- {
- strictRead_ = strictRead;
- strictWrite_ = strictWrite;
- }
+ public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite)
+ :base(trans)
+ {
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
- #region Write Methods
+ #region Write Methods
- public override void WriteMessageBegin(TMessage message)
- {
- if (strictWrite_)
- {
- uint version = VERSION_1 | (uint)(message.Type);
- WriteI32((int)version);
- WriteString(message.Name);
- WriteI32(message.SeqID);
- }
- else
- {
- WriteString(message.Name);
- WriteByte((sbyte)message.Type);
- WriteI32(message.SeqID);
- }
- }
+ public override void WriteMessageBegin(TMessage message)
+ {
+ if (strictWrite_)
+ {
+ uint version = VERSION_1 | (uint)(message.Type);
+ WriteI32((int)version);
+ WriteString(message.Name);
+ WriteI32(message.SeqID);
+ }
+ else
+ {
+ WriteString(message.Name);
+ WriteByte((sbyte)message.Type);
+ WriteI32(message.SeqID);
+ }
+ }
- public override void WriteMessageEnd()
- {
- }
+ public override void WriteMessageEnd()
+ {
+ }
- public override void WriteStructBegin(TStruct struc)
- {
- }
+ public override void WriteStructBegin(TStruct struc)
+ {
+ }
- public override void WriteStructEnd()
- {
- }
+ public override void WriteStructEnd()
+ {
+ }
- public override void WriteFieldBegin(TField field)
- {
- WriteByte((sbyte)field.Type);
- WriteI16(field.ID);
- }
+ public override void WriteFieldBegin(TField field)
+ {
+ WriteByte((sbyte)field.Type);
+ WriteI16(field.ID);
+ }
- public override void WriteFieldEnd()
- {
- }
+ public override void WriteFieldEnd()
+ {
+ }
- public override void WriteFieldStop()
- {
- WriteByte((sbyte)TType.Stop);
- }
+ public override void WriteFieldStop()
+ {
+ WriteByte((sbyte)TType.Stop);
+ }
- public override void WriteMapBegin(TMap map)
- {
- WriteByte((sbyte)map.KeyType);
- WriteByte((sbyte)map.ValueType);
- WriteI32(map.Count);
- }
+ public override void WriteMapBegin(TMap map)
+ {
+ WriteByte((sbyte)map.KeyType);
+ WriteByte((sbyte)map.ValueType);
+ WriteI32(map.Count);
+ }
- public override void WriteMapEnd()
- {
- }
+ public override void WriteMapEnd()
+ {
+ }
- public override void WriteListBegin(TList list)
- {
- WriteByte((sbyte)list.ElementType);
- WriteI32(list.Count);
- }
+ public override void WriteListBegin(TList list)
+ {
+ WriteByte((sbyte)list.ElementType);
+ WriteI32(list.Count);
+ }
- public override void WriteListEnd()
- {
- }
+ public override void WriteListEnd()
+ {
+ }
- public override void WriteSetBegin(TSet set)
- {
- WriteByte((sbyte)set.ElementType);
- WriteI32(set.Count);
- }
+ public override void WriteSetBegin(TSet set)
+ {
+ WriteByte((sbyte)set.ElementType);
+ WriteI32(set.Count);
+ }
- public override void WriteSetEnd()
- {
- }
+ public override void WriteSetEnd()
+ {
+ }
- public override void WriteBool(bool b)
- {
- WriteByte(b ? (sbyte)1 : (sbyte)0);
- }
+ public override void WriteBool(bool b)
+ {
+ WriteByte(b ? (sbyte)1 : (sbyte)0);
+ }
- private byte[] bout = new byte[1];
- public override void WriteByte(sbyte b)
- {
- bout[0] = (byte)b;
- trans.Write(bout, 0, 1);
- }
+ private byte[] bout = new byte[1];
+ public override void WriteByte(sbyte b)
+ {
+ bout[0] = (byte)b;
+ trans.Write(bout, 0, 1);
+ }
- private byte[] i16out = new byte[2];
- public override void WriteI16(short s)
- {
- i16out[0] = (byte)(0xff & (s >> 8));
- i16out[1] = (byte)(0xff & s);
- trans.Write(i16out, 0, 2);
- }
+ private byte[] i16out = new byte[2];
+ public override void WriteI16(short s)
+ {
+ i16out[0] = (byte)(0xff & (s >> 8));
+ i16out[1] = (byte)(0xff & s);
+ trans.Write(i16out, 0, 2);
+ }
- private byte[] i32out = new byte[4];
- public override void WriteI32(int i32)
- {
- i32out[0] = (byte)(0xff & (i32 >> 24));
- i32out[1] = (byte)(0xff & (i32 >> 16));
- i32out[2] = (byte)(0xff & (i32 >> 8));
- i32out[3] = (byte)(0xff & i32);
- trans.Write(i32out, 0, 4);
- }
+ private byte[] i32out = new byte[4];
+ public override void WriteI32(int i32)
+ {
+ i32out[0] = (byte)(0xff & (i32 >> 24));
+ i32out[1] = (byte)(0xff & (i32 >> 16));
+ i32out[2] = (byte)(0xff & (i32 >> 8));
+ i32out[3] = (byte)(0xff & i32);
+ trans.Write(i32out, 0, 4);
+ }
- private byte[] i64out = new byte[8];
- public override void WriteI64(long i64)
- {
- i64out[0] = (byte)(0xff & (i64 >> 56));
- i64out[1] = (byte)(0xff & (i64 >> 48));
- i64out[2] = (byte)(0xff & (i64 >> 40));
- i64out[3] = (byte)(0xff & (i64 >> 32));
- i64out[4] = (byte)(0xff & (i64 >> 24));
- i64out[5] = (byte)(0xff & (i64 >> 16));
- i64out[6] = (byte)(0xff & (i64 >> 8));
- i64out[7] = (byte)(0xff & i64);
- trans.Write(i64out, 0, 8);
- }
+ private byte[] i64out = new byte[8];
+ public override void WriteI64(long i64)
+ {
+ i64out[0] = (byte)(0xff & (i64 >> 56));
+ i64out[1] = (byte)(0xff & (i64 >> 48));
+ i64out[2] = (byte)(0xff & (i64 >> 40));
+ i64out[3] = (byte)(0xff & (i64 >> 32));
+ i64out[4] = (byte)(0xff & (i64 >> 24));
+ i64out[5] = (byte)(0xff & (i64 >> 16));
+ i64out[6] = (byte)(0xff & (i64 >> 8));
+ i64out[7] = (byte)(0xff & i64);
+ trans.Write(i64out, 0, 8);
+ }
- public override void WriteDouble(double d)
- {
+ public override void WriteDouble(double d)
+ {
#if !SILVERLIGHT
- WriteI64(BitConverter.DoubleToInt64Bits(d));
+ WriteI64(BitConverter.DoubleToInt64Bits(d));
#else
var bytes = BitConverter.GetBytes(d);
WriteI64(BitConverter.ToInt64(bytes, 0));
#endif
- }
+ }
- public override void WriteBinary(byte[] b)
- {
- WriteI32(b.Length);
- trans.Write(b, 0, b.Length);
- }
+ public override void WriteBinary(byte[] b)
+ {
+ WriteI32(b.Length);
+ trans.Write(b, 0, b.Length);
+ }
- #endregion
+ #endregion
- #region ReadMethods
+ #region ReadMethods
- public override TMessage ReadMessageBegin()
- {
- TMessage message = new TMessage();
- int size = ReadI32();
- if (size < 0)
- {
- uint version = (uint)size & VERSION_MASK;
- if (version != VERSION_1)
- {
- throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in ReadMessageBegin: " + version);
- }
- message.Type = (TMessageType)(size & 0x000000ff);
- message.Name = ReadString();
- message.SeqID = ReadI32();
- }
- else
- {
- if (strictRead_)
- {
- throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?");
- }
- message.Name = ReadStringBody(size);
- message.Type = (TMessageType)ReadByte();
- message.SeqID = ReadI32();
- }
- return message;
- }
+ public override TMessage ReadMessageBegin()
+ {
+ TMessage message = new TMessage();
+ int size = ReadI32();
+ if (size < 0)
+ {
+ uint version = (uint)size & VERSION_MASK;
+ if (version != VERSION_1)
+ {
+ throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in ReadMessageBegin: " + version);
+ }
+ message.Type = (TMessageType)(size & 0x000000ff);
+ message.Name = ReadString();
+ message.SeqID = ReadI32();
+ }
+ else
+ {
+ if (strictRead_)
+ {
+ throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?");
+ }
+ message.Name = ReadStringBody(size);
+ message.Type = (TMessageType)ReadByte();
+ message.SeqID = ReadI32();
+ }
+ return message;
+ }
- public override void ReadMessageEnd()
- {
- }
+ public override void ReadMessageEnd()
+ {
+ }
- public override TStruct ReadStructBegin()
- {
- return new TStruct();
- }
+ public override TStruct ReadStructBegin()
+ {
+ return new TStruct();
+ }
- public override void ReadStructEnd()
- {
- }
+ public override void ReadStructEnd()
+ {
+ }
- public override TField ReadFieldBegin()
- {
- TField field = new TField();
- field.Type = (TType)ReadByte();
+ public override TField ReadFieldBegin()
+ {
+ TField field = new TField();
+ field.Type = (TType)ReadByte();
- if (field.Type != TType.Stop)
- {
- field.ID = ReadI16();
- }
+ if (field.Type != TType.Stop)
+ {
+ field.ID = ReadI16();
+ }
- return field;
- }
+ return field;
+ }
- public override void ReadFieldEnd()
- {
- }
+ public override void ReadFieldEnd()
+ {
+ }
- public override TMap ReadMapBegin()
- {
- TMap map = new TMap();
- map.KeyType = (TType)ReadByte();
- map.ValueType = (TType)ReadByte();
- map.Count = ReadI32();
+ public override TMap ReadMapBegin()
+ {
+ TMap map = new TMap();
+ map.KeyType = (TType)ReadByte();
+ map.ValueType = (TType)ReadByte();
+ map.Count = ReadI32();
- return map;
- }
+ return map;
+ }
- public override void ReadMapEnd()
- {
- }
+ public override void ReadMapEnd()
+ {
+ }
- public override TList ReadListBegin()
- {
- TList list = new TList();
- list.ElementType = (TType)ReadByte();
- list.Count = ReadI32();
+ public override TList ReadListBegin()
+ {
+ TList list = new TList();
+ list.ElementType = (TType)ReadByte();
+ list.Count = ReadI32();
- return list;
- }
+ return list;
+ }
- public override void ReadListEnd()
- {
- }
+ public override void ReadListEnd()
+ {
+ }
- public override TSet ReadSetBegin()
- {
- TSet set = new TSet();
- set.ElementType = (TType)ReadByte();
- set.Count = ReadI32();
+ public override TSet ReadSetBegin()
+ {
+ TSet set = new TSet();
+ set.ElementType = (TType)ReadByte();
+ set.Count = ReadI32();
- return set;
- }
+ return set;
+ }
- public override void ReadSetEnd()
- {
- }
+ public override void ReadSetEnd()
+ {
+ }
- public override bool ReadBool()
- {
- return ReadByte() == 1;
- }
+ public override bool ReadBool()
+ {
+ return ReadByte() == 1;
+ }
- private byte[] bin = new byte[1];
- public override sbyte ReadByte()
- {
- ReadAll(bin, 0, 1);
- return (sbyte)bin[0];
- }
+ private byte[] bin = new byte[1];
+ public override sbyte ReadByte()
+ {
+ ReadAll(bin, 0, 1);
+ return (sbyte)bin[0];
+ }
- private byte[] i16in = new byte[2];
- public override short ReadI16()
- {
- ReadAll(i16in, 0, 2);
- return (short)(((i16in[0] & 0xff) << 8) | ((i16in[1] & 0xff)));
- }
+ private byte[] i16in = new byte[2];
+ public override short ReadI16()
+ {
+ ReadAll(i16in, 0, 2);
+ return (short)(((i16in[0] & 0xff) << 8) | ((i16in[1] & 0xff)));
+ }
- private byte[] i32in = new byte[4];
- public override int ReadI32()
- {
- ReadAll(i32in, 0, 4);
- return (int)(((i32in[0] & 0xff) << 24) | ((i32in[1] & 0xff) << 16) | ((i32in[2] & 0xff) << 8) | ((i32in[3] & 0xff)));
- }
+ private byte[] i32in = new byte[4];
+ public override int ReadI32()
+ {
+ ReadAll(i32in, 0, 4);
+ return (int)(((i32in[0] & 0xff) << 24) | ((i32in[1] & 0xff) << 16) | ((i32in[2] & 0xff) << 8) | ((i32in[3] & 0xff)));
+ }
#pragma warning disable 675
private byte[] i64in = new byte[8];
- public override long ReadI64()
- {
- ReadAll(i64in, 0, 8);
+ public override long ReadI64()
+ {
+ ReadAll(i64in, 0, 8);
unchecked {
return (long)(
((long)(i64in[0] & 0xff) << 56) |
@@ -361,35 +361,35 @@
#pragma warning restore 675
public override double ReadDouble()
- {
+ {
#if !SILVERLIGHT
- return BitConverter.Int64BitsToDouble(ReadI64());
+ return BitConverter.Int64BitsToDouble(ReadI64());
#else
var value = ReadI64();
var bytes = BitConverter.GetBytes(value);
return BitConverter.ToDouble(bytes, 0);
#endif
- }
+ }
- public override byte[] ReadBinary()
- {
- int size = ReadI32();
- byte[] buf = new byte[size];
- trans.ReadAll(buf, 0, size);
- return buf;
- }
- private string ReadStringBody(int size)
- {
- byte[] buf = new byte[size];
- trans.ReadAll(buf, 0, size);
- return Encoding.UTF8.GetString(buf, 0, buf.Length);
- }
+ public override byte[] ReadBinary()
+ {
+ int size = ReadI32();
+ byte[] buf = new byte[size];
+ trans.ReadAll(buf, 0, size);
+ return buf;
+ }
+ private string ReadStringBody(int size)
+ {
+ byte[] buf = new byte[size];
+ trans.ReadAll(buf, 0, size);
+ return Encoding.UTF8.GetString(buf, 0, buf.Length);
+ }
- private int ReadAll(byte[] buf, int off, int len)
- {
- return trans.ReadAll(buf, off, len);
- }
+ private int ReadAll(byte[] buf, int off, int len)
+ {
+ return trans.ReadAll(buf, off, len);
+ }
- #endregion
- }
+ #endregion
+ }
}
diff --git a/lib/csharp/src/Protocol/TCompactProtocol.cs b/lib/csharp/src/Protocol/TCompactProtocol.cs
index c992e9b..2b4f6f1 100644
--- a/lib/csharp/src/Protocol/TCompactProtocol.cs
+++ b/lib/csharp/src/Protocol/TCompactProtocol.cs
@@ -64,7 +64,7 @@
public const byte STRUCT = 0x0C;
}
- /**
+ /**
* Used to keep track of the last field for the current and previous structs,
* so we can do the delta stuff.
*/
@@ -73,13 +73,13 @@
private short lastFieldId_ = 0;
/**
- * If we encounter a boolean field begin, save the TField here so it can
+ * If we encounter a boolean field begin, save the TField here so it can
* have the value incorporated.
*/
private Nullable<TField> booleanField_;
/**
- * If we Read a field header, and it's a boolean field, save the boolean
+ * If we Read a field header, and it's a boolean field, save the boolean
* value here so that ReadBool can use it.
*/
private Nullable<Boolean> boolValue_;
@@ -88,8 +88,8 @@
#region CompactProtocol Factory
/**
- * Factory
- */
+ * Factory
+ */
public class Factory : TProtocolFactory
{
public Factory() { }
@@ -128,8 +128,8 @@
#region Write Methods
- /**
- * Writes a byte without any possibility of all that field header nonsense.
+ /**
+ * Writes a byte without any possibility of all that field header nonsense.
* Used internally by other writing methods that know they need to Write a byte.
*/
private byte[] byteDirectBuffer = new byte[1];
@@ -139,7 +139,7 @@
trans.Write(byteDirectBuffer);
}
- /**
+ /**
* Writes a byte without any possibility of all that field header nonsense.
*/
private void WriteByteDirect(int n)
@@ -187,7 +187,7 @@
}
/**
- * Write a struct begin. This doesn't actually put anything on the wire. We
+ * Write a struct begin. This doesn't actually put anything on the wire. We
* use it as an opportunity to put special placeholder markers on the field
* stack so we can get the field id deltas correct.
*/
@@ -227,8 +227,8 @@
}
/**
- * The workhorse of WriteFieldBegin. It has the option of doing a
- * 'type override' of the type header. This is used specifically in the
+ * The workhorse of WriteFieldBegin. It has the option of doing a
+ * 'type override' of the type header. This is used specifically in the
* boolean field case.
*/
private void WriteFieldBeginInternal(TField field, byte typeOverride)
@@ -264,7 +264,7 @@
}
/**
- * Write a map header. If the map is empty, omit the key and value type
+ * Write a map header. If the map is empty, omit the key and value type
* headers, as we don't need any additional information to skip it.
*/
public override void WriteMapBegin(TMap map)
@@ -280,7 +280,7 @@
}
}
- /**
+ /**
* Write a list header.
*/
public override void WriteListBegin(TList list)
@@ -297,9 +297,9 @@
}
/**
- * Write a boolean value. Potentially, this could be a boolean field, in
+ * Write a boolean value. Potentially, this could be a boolean field, in
* which case the field header info isn't written yet. If so, decide what the
- * right type header is for the value and then Write the field header.
+ * right type header is for the value and then Write the field header.
* Otherwise, Write a single byte.
*/
public override void WriteBool(Boolean b)
@@ -317,7 +317,7 @@
}
}
- /**
+ /**
* Write a byte. Nothing to see here!
*/
public override void WriteByte(sbyte b)
@@ -369,7 +369,7 @@
}
/**
- * Write a byte array, using a varint for the size.
+ * Write a byte array, using a varint for the size.
*/
public override void WriteBinary(byte[] bin)
{
@@ -383,9 +383,9 @@
}
//
- // These methods are called by structs, but don't actually have any wire
+ // These methods are called by structs, but don't actually have any wire
// output or purpose.
- //
+ //
public override void WriteMessageEnd() { }
public override void WriteMapEnd() { }
@@ -398,7 +398,7 @@
//
/**
- * Abstract method for writing the start of lists and sets. List and sets on
+ * Abstract method for writing the start of lists and sets. List and sets on
* the wire differ only by the type indicator.
*/
protected void WriteCollectionBegin(TType elemType, int size)
@@ -438,7 +438,7 @@
}
/**
- * Convert l into a zigzag long. This allows negative numbers to be
+ * Convert l into a zigzag long. This allows negative numbers to be
* represented compactly as a varint.
*/
private ulong longToZigzag(long n)
@@ -447,7 +447,7 @@
}
/**
- * Convert n into a zigzag int. This allows negative numbers to be
+ * Convert n into a zigzag int. This allows negative numbers to be
* represented compactly as a varint.
*/
private uint intToZigZag(int n)
@@ -456,7 +456,7 @@
}
/**
- * Convert a long into little-endian bytes in buf starting at off and going
+ * Convert a long into little-endian bytes in buf starting at off and going
* until off+7.
*/
private void fixedLongToBytes(long n, byte[] buf, int off)
@@ -476,7 +476,7 @@
#region ReadMethods
/**
- * Read a message header.
+ * Read a message header.
*/
public override TMessage ReadMessageBegin()
{
@@ -509,7 +509,7 @@
}
/**
- * Doesn't actually consume any wire data, just removes the last field for
+ * Doesn't actually consume any wire data, just removes the last field for
* this struct from the field stack.
*/
public override void ReadStructEnd()
@@ -519,7 +519,7 @@
}
/**
- * Read a field header off the wire.
+ * Read a field header off the wire.
*/
public override TField ReadFieldBegin()
{
@@ -560,7 +560,7 @@
return field;
}
- /**
+ /**
* Read a map header off the wire. If the size is zero, skip Reading the key
* and value type. This means that 0-length maps will yield TMaps without the
* "correct" types.
@@ -573,7 +573,7 @@
}
/**
- * Read a list header off the wire. If the list size is 0-14, the size will
+ * Read a list header off the wire. If the list size is 0-14, the size will
* be packed into the element type header. If it's a longer list, the 4 MSB
* of the element type header will be 0xF, and a varint will follow with the
* true size.
@@ -591,7 +591,7 @@
}
/**
- * Read a set header off the wire. If the set size is 0-14, the size will
+ * Read a set header off the wire. If the set size is 0-14, the size will
* be packed into the element type header. If it's a longer set, the 4 MSB
* of the element type header will be 0xF, and a varint will follow with the
* true size.
@@ -677,7 +677,7 @@
}
/**
- * Read a byte[] from the wire.
+ * Read a byte[] from the wire.
*/
public override byte[] ReadBinary()
{
@@ -690,7 +690,7 @@
}
/**
- * Read a byte[] of a known length from the wire.
+ * Read a byte[] of a known length from the wire.
*/
private byte[] ReadBinary(int length)
{
@@ -702,7 +702,7 @@
}
//
- // These methods are here for the struct to call, but don't have any wire
+ // These methods are here for the struct to call, but don't have any wire
// encoding.
//
public override void ReadMessageEnd() { }
@@ -734,7 +734,7 @@
}
/**
- * Read an i64 from the wire as a proper varint. The MSB of each byte is set
+ * Read an i64 from the wire as a proper varint. The MSB of each byte is set
* if there is another byte to follow. This can Read up to 10 bytes.
*/
private ulong ReadVarint64()
@@ -748,7 +748,7 @@
if ((b & 0x80) != 0x80) break;
shift += 7;
}
-
+
return result;
}
@@ -766,7 +766,7 @@
return (int)(n >> 1) ^ (-(int)(n & 1));
}
- /**
+ /**
* Convert from zigzag long to long.
*/
private long zigzagToLong(ulong n)
@@ -775,7 +775,7 @@
}
/**
- * Note that it's important that the mask bytes are long literals,
+ * Note that it's important that the mask bytes are long literals,
* otherwise they'll default to ints, and when you shift an int left 56 bits,
* you just get a messed up int.
*/
@@ -803,7 +803,7 @@
}
/**
- * Given a TCompactProtocol.Types constant, convert it to its corresponding
+ * Given a TCompactProtocol.Types constant, convert it to its corresponding
* TType value.
*/
private TType getTType(byte type)
diff --git a/lib/csharp/src/Protocol/TField.cs b/lib/csharp/src/Protocol/TField.cs
index fa10584..8179557 100644
--- a/lib/csharp/src/Protocol/TField.cs
+++ b/lib/csharp/src/Protocol/TField.cs
@@ -27,36 +27,36 @@
namespace Thrift.Protocol
{
- public struct TField
- {
- private string name;
- private TType type;
- private short id;
+ public struct TField
+ {
+ private string name;
+ private TType type;
+ private short id;
- public TField(string name, TType type, short id)
- :this()
- {
- this.name = name;
- this.type = type;
- this.id = id;
- }
+ public TField(string name, TType type, short id)
+ :this()
+ {
+ this.name = name;
+ this.type = type;
+ this.id = id;
+ }
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
+ public string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
- public TType Type
- {
- get { return type; }
- set { type = value; }
- }
+ public TType Type
+ {
+ get { return type; }
+ set { type = value; }
+ }
- public short ID
- {
- get { return id; }
- set { id = value; }
- }
- }
+ public short ID
+ {
+ get { return id; }
+ set { id = value; }
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TJSONProtocol.cs b/lib/csharp/src/Protocol/TJSONProtocol.cs
index e1d0e78..2e8d99f 100644
--- a/lib/csharp/src/Protocol/TJSONProtocol.cs
+++ b/lib/csharp/src/Protocol/TJSONProtocol.cs
@@ -27,1064 +27,1064 @@
namespace Thrift.Protocol
{
- /// <summary>
- /// JSON protocol implementation for thrift.
- ///
- /// This is a full-featured protocol supporting Write and Read.
- ///
- /// Please see the C++ class header for a detailed description of the
- /// protocol's wire format.
- ///
- /// Adapted from the Java version.
- /// </summary>
- public class TJSONProtocol : TProtocol
- {
- /// <summary>
- /// Factory for JSON protocol objects
- /// </summary>
- public class Factory : TProtocolFactory
- {
- public TProtocol GetProtocol(TTransport trans)
- {
- return new TJSONProtocol(trans);
- }
- }
+ /// <summary>
+ /// JSON protocol implementation for thrift.
+ ///
+ /// This is a full-featured protocol supporting Write and Read.
+ ///
+ /// Please see the C++ class header for a detailed description of the
+ /// protocol's wire format.
+ ///
+ /// Adapted from the Java version.
+ /// </summary>
+ public class TJSONProtocol : TProtocol
+ {
+ /// <summary>
+ /// Factory for JSON protocol objects
+ /// </summary>
+ public class Factory : TProtocolFactory
+ {
+ public TProtocol GetProtocol(TTransport trans)
+ {
+ return new TJSONProtocol(trans);
+ }
+ }
- private static byte[] COMMA = new byte[] { (byte)',' };
- private static byte[] COLON = new byte[] { (byte)':' };
- private static byte[] LBRACE = new byte[] { (byte)'{' };
- private static byte[] RBRACE = new byte[] { (byte)'}' };
- private static byte[] LBRACKET = new byte[] { (byte)'[' };
- private static byte[] RBRACKET = new byte[] { (byte)']' };
- private static byte[] QUOTE = new byte[] { (byte)'"' };
- private static byte[] BACKSLASH = new byte[] { (byte)'\\' };
+ private static byte[] COMMA = new byte[] { (byte)',' };
+ private static byte[] COLON = new byte[] { (byte)':' };
+ private static byte[] LBRACE = new byte[] { (byte)'{' };
+ private static byte[] RBRACE = new byte[] { (byte)'}' };
+ private static byte[] LBRACKET = new byte[] { (byte)'[' };
+ private static byte[] RBRACKET = new byte[] { (byte)']' };
+ private static byte[] QUOTE = new byte[] { (byte)'"' };
+ private static byte[] BACKSLASH = new byte[] { (byte)'\\' };
- private byte[] ESCSEQ = new byte[] { (byte)'\\', (byte)'u', (byte)'0', (byte)'0' };
+ private byte[] ESCSEQ = new byte[] { (byte)'\\', (byte)'u', (byte)'0', (byte)'0' };
- private const long VERSION = 1;
- private byte[] JSON_CHAR_TABLE = {
- 0, 0, 0, 0, 0, 0, 0, 0,(byte)'b',(byte)'t',(byte)'n', 0,(byte)'f',(byte)'r', 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1,(byte)'"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ private const long VERSION = 1;
+ private byte[] JSON_CHAR_TABLE = {
+ 0, 0, 0, 0, 0, 0, 0, 0,(byte)'b',(byte)'t',(byte)'n', 0,(byte)'f',(byte)'r', 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1,(byte)'"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
};
- private char[] ESCAPE_CHARS = "\"\\/bfnrt".ToCharArray();
+ private char[] ESCAPE_CHARS = "\"\\/bfnrt".ToCharArray();
- private byte[] ESCAPE_CHAR_VALS = {
- (byte)'"', (byte)'\\', (byte)'/', (byte)'\b', (byte)'\f', (byte)'\n', (byte)'\r', (byte)'\t',
+ private byte[] ESCAPE_CHAR_VALS = {
+ (byte)'"', (byte)'\\', (byte)'/', (byte)'\b', (byte)'\f', (byte)'\n', (byte)'\r', (byte)'\t',
};
- private const int DEF_STRING_SIZE = 16;
+ private const int DEF_STRING_SIZE = 16;
- private static byte[] NAME_BOOL = new byte[] { (byte)'t', (byte)'f' };
- private static byte[] NAME_BYTE = new byte[] { (byte)'i', (byte)'8' };
- private static byte[] NAME_I16 = new byte[] { (byte)'i', (byte)'1', (byte)'6' };
- private static byte[] NAME_I32 = new byte[] { (byte)'i', (byte)'3', (byte)'2' };
- private static byte[] NAME_I64 = new byte[] { (byte)'i', (byte)'6', (byte)'4' };
- private static byte[] NAME_DOUBLE = new byte[] { (byte)'d', (byte)'b', (byte)'l' };
- private static byte[] NAME_STRUCT = new byte[] { (byte)'r', (byte)'e', (byte)'c' };
- private static byte[] NAME_STRING = new byte[] { (byte)'s', (byte)'t', (byte)'r' };
- private static byte[] NAME_MAP = new byte[] { (byte)'m', (byte)'a', (byte)'p' };
- private static byte[] NAME_LIST = new byte[] { (byte)'l', (byte)'s', (byte)'t' };
- private static byte[] NAME_SET = new byte[] { (byte)'s', (byte)'e', (byte)'t' };
+ private static byte[] NAME_BOOL = new byte[] { (byte)'t', (byte)'f' };
+ private static byte[] NAME_BYTE = new byte[] { (byte)'i', (byte)'8' };
+ private static byte[] NAME_I16 = new byte[] { (byte)'i', (byte)'1', (byte)'6' };
+ private static byte[] NAME_I32 = new byte[] { (byte)'i', (byte)'3', (byte)'2' };
+ private static byte[] NAME_I64 = new byte[] { (byte)'i', (byte)'6', (byte)'4' };
+ private static byte[] NAME_DOUBLE = new byte[] { (byte)'d', (byte)'b', (byte)'l' };
+ private static byte[] NAME_STRUCT = new byte[] { (byte)'r', (byte)'e', (byte)'c' };
+ private static byte[] NAME_STRING = new byte[] { (byte)'s', (byte)'t', (byte)'r' };
+ private static byte[] NAME_MAP = new byte[] { (byte)'m', (byte)'a', (byte)'p' };
+ private static byte[] NAME_LIST = new byte[] { (byte)'l', (byte)'s', (byte)'t' };
+ private static byte[] NAME_SET = new byte[] { (byte)'s', (byte)'e', (byte)'t' };
- private static byte[] GetTypeNameForTypeID(TType typeID)
- {
- switch (typeID)
- {
- case TType.Bool:
- return NAME_BOOL;
- case TType.Byte:
- return NAME_BYTE;
- case TType.I16:
- return NAME_I16;
- case TType.I32:
- return NAME_I32;
- case TType.I64:
- return NAME_I64;
- case TType.Double:
- return NAME_DOUBLE;
- case TType.String:
- return NAME_STRING;
- case TType.Struct:
- return NAME_STRUCT;
- case TType.Map:
- return NAME_MAP;
- case TType.Set:
- return NAME_SET;
- case TType.List:
- return NAME_LIST;
- default:
- throw new TProtocolException(TProtocolException.NOT_IMPLEMENTED,
- "Unrecognized type");
- }
- }
+ private static byte[] GetTypeNameForTypeID(TType typeID)
+ {
+ switch (typeID)
+ {
+ case TType.Bool:
+ return NAME_BOOL;
+ case TType.Byte:
+ return NAME_BYTE;
+ case TType.I16:
+ return NAME_I16;
+ case TType.I32:
+ return NAME_I32;
+ case TType.I64:
+ return NAME_I64;
+ case TType.Double:
+ return NAME_DOUBLE;
+ case TType.String:
+ return NAME_STRING;
+ case TType.Struct:
+ return NAME_STRUCT;
+ case TType.Map:
+ return NAME_MAP;
+ case TType.Set:
+ return NAME_SET;
+ case TType.List:
+ return NAME_LIST;
+ default:
+ throw new TProtocolException(TProtocolException.NOT_IMPLEMENTED,
+ "Unrecognized type");
+ }
+ }
- private static TType GetTypeIDForTypeName(byte[] name)
- {
- TType result = TType.Stop;
- if (name.Length > 1)
- {
- switch (name[0])
- {
- case (byte)'d':
- result = TType.Double;
- break;
- case (byte)'i':
- switch (name[1])
- {
- case (byte)'8':
- result = TType.Byte;
- break;
- case (byte)'1':
- result = TType.I16;
- break;
- case (byte)'3':
- result = TType.I32;
- break;
- case (byte)'6':
- result = TType.I64;
- break;
- }
- break;
- case (byte)'l':
- result = TType.List;
- break;
- case (byte)'m':
- result = TType.Map;
- break;
- case (byte)'r':
- result = TType.Struct;
- break;
- case (byte)'s':
- if (name[1] == (byte)'t')
- {
- result = TType.String;
- }
- else if (name[1] == (byte)'e')
- {
- result = TType.Set;
- }
- break;
- case (byte)'t':
- result = TType.Bool;
- break;
- }
- }
- if (result == TType.Stop)
- {
- throw new TProtocolException(TProtocolException.NOT_IMPLEMENTED,
- "Unrecognized type");
- }
- return result;
- }
+ private static TType GetTypeIDForTypeName(byte[] name)
+ {
+ TType result = TType.Stop;
+ if (name.Length > 1)
+ {
+ switch (name[0])
+ {
+ case (byte)'d':
+ result = TType.Double;
+ break;
+ case (byte)'i':
+ switch (name[1])
+ {
+ case (byte)'8':
+ result = TType.Byte;
+ break;
+ case (byte)'1':
+ result = TType.I16;
+ break;
+ case (byte)'3':
+ result = TType.I32;
+ break;
+ case (byte)'6':
+ result = TType.I64;
+ break;
+ }
+ break;
+ case (byte)'l':
+ result = TType.List;
+ break;
+ case (byte)'m':
+ result = TType.Map;
+ break;
+ case (byte)'r':
+ result = TType.Struct;
+ break;
+ case (byte)'s':
+ if (name[1] == (byte)'t')
+ {
+ result = TType.String;
+ }
+ else if (name[1] == (byte)'e')
+ {
+ result = TType.Set;
+ }
+ break;
+ case (byte)'t':
+ result = TType.Bool;
+ break;
+ }
+ }
+ if (result == TType.Stop)
+ {
+ throw new TProtocolException(TProtocolException.NOT_IMPLEMENTED,
+ "Unrecognized type");
+ }
+ return result;
+ }
- ///<summary>
- /// Base class for tracking JSON contexts that may require
- /// inserting/Reading additional JSON syntax characters
- /// This base context does nothing.
- ///</summary>
- protected class JSONBaseContext
- {
- protected TJSONProtocol proto;
+ ///<summary>
+ /// Base class for tracking JSON contexts that may require
+ /// inserting/Reading additional JSON syntax characters
+ /// This base context does nothing.
+ ///</summary>
+ protected class JSONBaseContext
+ {
+ protected TJSONProtocol proto;
- public JSONBaseContext(TJSONProtocol proto)
- {
- this.proto = proto;
- }
+ public JSONBaseContext(TJSONProtocol proto)
+ {
+ this.proto = proto;
+ }
- public virtual void Write() { }
+ public virtual void Write() { }
- public virtual void Read() { }
+ public virtual void Read() { }
- public virtual bool EscapeNumbers() { return false; }
- }
+ public virtual bool EscapeNumbers() { return false; }
+ }
- ///<summary>
- /// Context for JSON lists. Will insert/Read commas before each item except
- /// for the first one
- ///</summary>
- protected class JSONListContext : JSONBaseContext
- {
- public JSONListContext(TJSONProtocol protocol)
- : base(protocol)
- {
+ ///<summary>
+ /// Context for JSON lists. Will insert/Read commas before each item except
+ /// for the first one
+ ///</summary>
+ protected class JSONListContext : JSONBaseContext
+ {
+ public JSONListContext(TJSONProtocol protocol)
+ : base(protocol)
+ {
- }
+ }
- private bool first = true;
+ private bool first = true;
- public override void Write()
- {
- if (first)
- {
- first = false;
- }
- else
- {
- proto.trans.Write(COMMA);
- }
- }
+ public override void Write()
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ proto.trans.Write(COMMA);
+ }
+ }
- public override void Read()
- {
- if (first)
- {
- first = false;
- }
- else
- {
- proto.ReadJSONSyntaxChar(COMMA);
- }
- }
- }
+ public override void Read()
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ proto.ReadJSONSyntaxChar(COMMA);
+ }
+ }
+ }
- ///<summary>
- /// Context for JSON records. Will insert/Read colons before the value portion
- /// of each record pair, and commas before each key except the first. In
- /// addition, will indicate that numbers in the key position need to be
- /// escaped in quotes (since JSON keys must be strings).
- ///</summary>
- protected class JSONPairContext : JSONBaseContext
- {
- public JSONPairContext(TJSONProtocol proto)
- : base(proto)
- {
+ ///<summary>
+ /// Context for JSON records. Will insert/Read colons before the value portion
+ /// of each record pair, and commas before each key except the first. In
+ /// addition, will indicate that numbers in the key position need to be
+ /// escaped in quotes (since JSON keys must be strings).
+ ///</summary>
+ protected class JSONPairContext : JSONBaseContext
+ {
+ public JSONPairContext(TJSONProtocol proto)
+ : base(proto)
+ {
- }
+ }
- private bool first = true;
- private bool colon = true;
+ private bool first = true;
+ private bool colon = true;
- public override void Write()
- {
- if (first)
- {
- first = false;
- colon = true;
- }
- else
- {
- proto.trans.Write(colon ? COLON : COMMA);
- colon = !colon;
- }
- }
+ public override void Write()
+ {
+ if (first)
+ {
+ first = false;
+ colon = true;
+ }
+ else
+ {
+ proto.trans.Write(colon ? COLON : COMMA);
+ colon = !colon;
+ }
+ }
- public override void Read()
- {
- if (first)
- {
- first = false;
- colon = true;
- }
- else
- {
- proto.ReadJSONSyntaxChar(colon ? COLON : COMMA);
- colon = !colon;
- }
- }
+ public override void Read()
+ {
+ if (first)
+ {
+ first = false;
+ colon = true;
+ }
+ else
+ {
+ proto.ReadJSONSyntaxChar(colon ? COLON : COMMA);
+ colon = !colon;
+ }
+ }
- public override bool EscapeNumbers()
- {
- return colon;
- }
- }
+ public override bool EscapeNumbers()
+ {
+ return colon;
+ }
+ }
- ///<summary>
- /// Holds up to one byte from the transport
- ///</summary>
- protected class LookaheadReader
- {
- protected TJSONProtocol proto;
+ ///<summary>
+ /// Holds up to one byte from the transport
+ ///</summary>
+ protected class LookaheadReader
+ {
+ protected TJSONProtocol proto;
- public LookaheadReader(TJSONProtocol proto)
- {
- this.proto = proto;
- }
+ public LookaheadReader(TJSONProtocol proto)
+ {
+ this.proto = proto;
+ }
- private bool hasData;
- private byte[] data = new byte[1];
+ private bool hasData;
+ private byte[] data = new byte[1];
- ///<summary>
- /// Return and consume the next byte to be Read, either taking it from the
- /// data buffer if present or getting it from the transport otherwise.
- ///</summary>
- public byte Read()
- {
- if (hasData)
- {
- hasData = false;
- }
- else
- {
- proto.trans.ReadAll(data, 0, 1);
- }
- return data[0];
- }
+ ///<summary>
+ /// Return and consume the next byte to be Read, either taking it from the
+ /// data buffer if present or getting it from the transport otherwise.
+ ///</summary>
+ public byte Read()
+ {
+ if (hasData)
+ {
+ hasData = false;
+ }
+ else
+ {
+ proto.trans.ReadAll(data, 0, 1);
+ }
+ return data[0];
+ }
- ///<summary>
- /// Return the next byte to be Read without consuming, filling the data
- /// buffer if it has not been filled alReady.
- ///</summary>
- public byte Peek()
- {
- if (!hasData)
- {
- proto.trans.ReadAll(data, 0, 1);
- }
- hasData = true;
- return data[0];
- }
- }
+ ///<summary>
+ /// Return the next byte to be Read without consuming, filling the data
+ /// buffer if it has not been filled alReady.
+ ///</summary>
+ public byte Peek()
+ {
+ if (!hasData)
+ {
+ proto.trans.ReadAll(data, 0, 1);
+ }
+ hasData = true;
+ return data[0];
+ }
+ }
- // Default encoding
- protected Encoding utf8Encoding = UTF8Encoding.UTF8;
+ // Default encoding
+ protected Encoding utf8Encoding = UTF8Encoding.UTF8;
- // Stack of nested contexts that we may be in
- protected Stack<JSONBaseContext> contextStack = new Stack<JSONBaseContext>();
+ // Stack of nested contexts that we may be in
+ protected Stack<JSONBaseContext> contextStack = new Stack<JSONBaseContext>();
- // Current context that we are in
- protected JSONBaseContext context;
+ // Current context that we are in
+ protected JSONBaseContext context;
- // Reader that manages a 1-byte buffer
- protected LookaheadReader reader;
+ // Reader that manages a 1-byte buffer
+ protected LookaheadReader reader;
- ///<summary>
- /// Push a new JSON context onto the stack.
- ///</summary>
- protected void PushContext(JSONBaseContext c)
- {
- contextStack.Push(context);
- context = c;
- }
+ ///<summary>
+ /// Push a new JSON context onto the stack.
+ ///</summary>
+ protected void PushContext(JSONBaseContext c)
+ {
+ contextStack.Push(context);
+ context = c;
+ }
- ///<summary>
- /// Pop the last JSON context off the stack
- ///</summary>
- protected void PopContext()
- {
- context = contextStack.Pop();
- }
+ ///<summary>
+ /// Pop the last JSON context off the stack
+ ///</summary>
+ protected void PopContext()
+ {
+ context = contextStack.Pop();
+ }
- ///<summary>
- /// TJSONProtocol Constructor
- ///</summary>
- public TJSONProtocol(TTransport trans)
- : base(trans)
- {
- context = new JSONBaseContext(this);
- reader = new LookaheadReader(this);
- }
+ ///<summary>
+ /// TJSONProtocol Constructor
+ ///</summary>
+ public TJSONProtocol(TTransport trans)
+ : base(trans)
+ {
+ context = new JSONBaseContext(this);
+ reader = new LookaheadReader(this);
+ }
- // Temporary buffer used by several methods
- private byte[] tempBuffer = new byte[4];
+ // Temporary buffer used by several methods
+ private byte[] tempBuffer = new byte[4];
- ///<summary>
- /// Read a byte that must match b[0]; otherwise an exception is thrown.
- /// Marked protected to avoid synthetic accessor in JSONListContext.Read
- /// and JSONPairContext.Read
- ///</summary>
- protected void ReadJSONSyntaxChar(byte[] b)
- {
- byte ch = reader.Read();
- if (ch != b[0])
- {
- throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Unexpected character:" + (char)ch);
- }
- }
+ ///<summary>
+ /// Read a byte that must match b[0]; otherwise an exception is thrown.
+ /// Marked protected to avoid synthetic accessor in JSONListContext.Read
+ /// and JSONPairContext.Read
+ ///</summary>
+ protected void ReadJSONSyntaxChar(byte[] b)
+ {
+ byte ch = reader.Read();
+ if (ch != b[0])
+ {
+ throw new TProtocolException(TProtocolException.INVALID_DATA,
+ "Unexpected character:" + (char)ch);
+ }
+ }
- ///<summary>
- /// Convert a byte containing a hex char ('0'-'9' or 'a'-'f') into its
- /// corresponding hex value
- ///</summary>
- private static byte HexVal(byte ch)
- {
- if ((ch >= '0') && (ch <= '9'))
- {
- return (byte)((char)ch - '0');
- }
- else if ((ch >= 'a') && (ch <= 'f'))
- {
- ch += 10;
- return (byte)((char)ch - 'a');
- }
- else
- {
- throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Expected hex character");
- }
- }
+ ///<summary>
+ /// Convert a byte containing a hex char ('0'-'9' or 'a'-'f') into its
+ /// corresponding hex value
+ ///</summary>
+ private static byte HexVal(byte ch)
+ {
+ if ((ch >= '0') && (ch <= '9'))
+ {
+ return (byte)((char)ch - '0');
+ }
+ else if ((ch >= 'a') && (ch <= 'f'))
+ {
+ ch += 10;
+ return (byte)((char)ch - 'a');
+ }
+ else
+ {
+ throw new TProtocolException(TProtocolException.INVALID_DATA,
+ "Expected hex character");
+ }
+ }
- ///<summary>
- /// Convert a byte containing a hex value to its corresponding hex character
- ///</summary>
- private static byte HexChar(byte val)
- {
- val &= 0x0F;
- if (val < 10)
- {
- return (byte)((char)val + '0');
- }
- else
- {
- val -= 10;
- return (byte)((char)val + 'a');
- }
- }
+ ///<summary>
+ /// Convert a byte containing a hex value to its corresponding hex character
+ ///</summary>
+ private static byte HexChar(byte val)
+ {
+ val &= 0x0F;
+ if (val < 10)
+ {
+ return (byte)((char)val + '0');
+ }
+ else
+ {
+ val -= 10;
+ return (byte)((char)val + 'a');
+ }
+ }
- ///<summary>
- /// Write the bytes in array buf as a JSON characters, escaping as needed
- ///</summary>
- private void WriteJSONString(byte[] b)
- {
- context.Write();
- trans.Write(QUOTE);
- int len = b.Length;
- for (int i = 0; i < len; i++)
- {
- if ((b[i] & 0x00FF) >= 0x30)
- {
- if (b[i] == BACKSLASH[0])
- {
- trans.Write(BACKSLASH);
- trans.Write(BACKSLASH);
- }
- else
- {
- trans.Write(b, i, 1);
- }
- }
- else
- {
- tempBuffer[0] = JSON_CHAR_TABLE[b[i]];
- if (tempBuffer[0] == 1)
- {
- trans.Write(b, i, 1);
- }
- else if (tempBuffer[0] > 1)
- {
- trans.Write(BACKSLASH);
- trans.Write(tempBuffer, 0, 1);
- }
- else
- {
- trans.Write(ESCSEQ);
- tempBuffer[0] = HexChar((byte)(b[i] >> 4));
- tempBuffer[1] = HexChar(b[i]);
- trans.Write(tempBuffer, 0, 2);
- }
- }
- }
- trans.Write(QUOTE);
- }
+ ///<summary>
+ /// Write the bytes in array buf as a JSON characters, escaping as needed
+ ///</summary>
+ private void WriteJSONString(byte[] b)
+ {
+ context.Write();
+ trans.Write(QUOTE);
+ int len = b.Length;
+ for (int i = 0; i < len; i++)
+ {
+ if ((b[i] & 0x00FF) >= 0x30)
+ {
+ if (b[i] == BACKSLASH[0])
+ {
+ trans.Write(BACKSLASH);
+ trans.Write(BACKSLASH);
+ }
+ else
+ {
+ trans.Write(b, i, 1);
+ }
+ }
+ else
+ {
+ tempBuffer[0] = JSON_CHAR_TABLE[b[i]];
+ if (tempBuffer[0] == 1)
+ {
+ trans.Write(b, i, 1);
+ }
+ else if (tempBuffer[0] > 1)
+ {
+ trans.Write(BACKSLASH);
+ trans.Write(tempBuffer, 0, 1);
+ }
+ else
+ {
+ trans.Write(ESCSEQ);
+ tempBuffer[0] = HexChar((byte)(b[i] >> 4));
+ tempBuffer[1] = HexChar(b[i]);
+ trans.Write(tempBuffer, 0, 2);
+ }
+ }
+ }
+ trans.Write(QUOTE);
+ }
- ///<summary>
- /// Write out number as a JSON value. If the context dictates so, it will be
- /// wrapped in quotes to output as a JSON string.
- ///</summary>
- private void WriteJSONInteger(long num)
- {
- context.Write();
- String str = num.ToString();
+ ///<summary>
+ /// Write out number as a JSON value. If the context dictates so, it will be
+ /// wrapped in quotes to output as a JSON string.
+ ///</summary>
+ private void WriteJSONInteger(long num)
+ {
+ context.Write();
+ String str = num.ToString();
- bool escapeNum = context.EscapeNumbers();
- if (escapeNum)
- trans.Write(QUOTE);
+ bool escapeNum = context.EscapeNumbers();
+ if (escapeNum)
+ trans.Write(QUOTE);
- trans.Write(utf8Encoding.GetBytes(str));
+ trans.Write(utf8Encoding.GetBytes(str));
- if (escapeNum)
- trans.Write(QUOTE);
- }
+ if (escapeNum)
+ trans.Write(QUOTE);
+ }
- ///<summary>
- /// Write out a double as a JSON value. If it is NaN or infinity or if the
- /// context dictates escaping, Write out as JSON string.
- ///</summary>
- private void WriteJSONDouble(double num)
- {
- context.Write();
- String str = num.ToString(CultureInfo.InvariantCulture);
- bool special = false;
+ ///<summary>
+ /// Write out a double as a JSON value. If it is NaN or infinity or if the
+ /// context dictates escaping, Write out as JSON string.
+ ///</summary>
+ private void WriteJSONDouble(double num)
+ {
+ context.Write();
+ String str = num.ToString(CultureInfo.InvariantCulture);
+ bool special = false;
- switch (str[0])
- {
- case 'N': // NaN
- case 'I': // Infinity
- special = true;
- break;
- case '-':
- if (str[1] == 'I')
- { // -Infinity
- special = true;
- }
- break;
- }
+ switch (str[0])
+ {
+ case 'N': // NaN
+ case 'I': // Infinity
+ special = true;
+ break;
+ case '-':
+ if (str[1] == 'I')
+ { // -Infinity
+ special = true;
+ }
+ break;
+ }
- bool escapeNum = special || context.EscapeNumbers();
+ bool escapeNum = special || context.EscapeNumbers();
- if (escapeNum)
- trans.Write(QUOTE);
+ if (escapeNum)
+ trans.Write(QUOTE);
- trans.Write(utf8Encoding.GetBytes(str));
+ trans.Write(utf8Encoding.GetBytes(str));
- if (escapeNum)
- trans.Write(QUOTE);
- }
- ///<summary>
- /// Write out contents of byte array b as a JSON string with base-64 encoded
- /// data
- ///</summary>
- private void WriteJSONBase64(byte[] b)
- {
- context.Write();
- trans.Write(QUOTE);
+ if (escapeNum)
+ trans.Write(QUOTE);
+ }
+ ///<summary>
+ /// Write out contents of byte array b as a JSON string with base-64 encoded
+ /// data
+ ///</summary>
+ private void WriteJSONBase64(byte[] b)
+ {
+ context.Write();
+ trans.Write(QUOTE);
- int len = b.Length;
- int off = 0;
+ int len = b.Length;
+ int off = 0;
- while (len >= 3)
- {
- // Encode 3 bytes at a time
- TBase64Utils.encode(b, off, 3, tempBuffer, 0);
- trans.Write(tempBuffer, 0, 4);
- off += 3;
- len -= 3;
- }
- if (len > 0)
- {
- // Encode remainder
- TBase64Utils.encode(b, off, len, tempBuffer, 0);
- trans.Write(tempBuffer, 0, len + 1);
- }
+ while (len >= 3)
+ {
+ // Encode 3 bytes at a time
+ TBase64Utils.encode(b, off, 3, tempBuffer, 0);
+ trans.Write(tempBuffer, 0, 4);
+ off += 3;
+ len -= 3;
+ }
+ if (len > 0)
+ {
+ // Encode remainder
+ TBase64Utils.encode(b, off, len, tempBuffer, 0);
+ trans.Write(tempBuffer, 0, len + 1);
+ }
- trans.Write(QUOTE);
- }
+ trans.Write(QUOTE);
+ }
- private void WriteJSONObjectStart()
- {
- context.Write();
- trans.Write(LBRACE);
- PushContext(new JSONPairContext(this));
- }
+ private void WriteJSONObjectStart()
+ {
+ context.Write();
+ trans.Write(LBRACE);
+ PushContext(new JSONPairContext(this));
+ }
- private void WriteJSONObjectEnd()
- {
- PopContext();
- trans.Write(RBRACE);
- }
+ private void WriteJSONObjectEnd()
+ {
+ PopContext();
+ trans.Write(RBRACE);
+ }
- private void WriteJSONArrayStart()
- {
- context.Write();
- trans.Write(LBRACKET);
- PushContext(new JSONListContext(this));
- }
+ private void WriteJSONArrayStart()
+ {
+ context.Write();
+ trans.Write(LBRACKET);
+ PushContext(new JSONListContext(this));
+ }
- private void WriteJSONArrayEnd()
- {
- PopContext();
- trans.Write(RBRACKET);
- }
+ private void WriteJSONArrayEnd()
+ {
+ PopContext();
+ trans.Write(RBRACKET);
+ }
- public override void WriteMessageBegin(TMessage message)
- {
- WriteJSONArrayStart();
- WriteJSONInteger(VERSION);
+ public override void WriteMessageBegin(TMessage message)
+ {
+ WriteJSONArrayStart();
+ WriteJSONInteger(VERSION);
- byte[] b = utf8Encoding.GetBytes(message.Name);
- WriteJSONString(b);
+ byte[] b = utf8Encoding.GetBytes(message.Name);
+ WriteJSONString(b);
- WriteJSONInteger((long)message.Type);
- WriteJSONInteger(message.SeqID);
- }
+ WriteJSONInteger((long)message.Type);
+ WriteJSONInteger(message.SeqID);
+ }
- public override void WriteMessageEnd()
- {
- WriteJSONArrayEnd();
- }
+ public override void WriteMessageEnd()
+ {
+ WriteJSONArrayEnd();
+ }
- public override void WriteStructBegin(TStruct str)
- {
- WriteJSONObjectStart();
- }
+ public override void WriteStructBegin(TStruct str)
+ {
+ WriteJSONObjectStart();
+ }
- public override void WriteStructEnd()
- {
- WriteJSONObjectEnd();
- }
+ public override void WriteStructEnd()
+ {
+ WriteJSONObjectEnd();
+ }
- public override void WriteFieldBegin(TField field)
- {
- WriteJSONInteger(field.ID);
- WriteJSONObjectStart();
- WriteJSONString(GetTypeNameForTypeID(field.Type));
- }
+ public override void WriteFieldBegin(TField field)
+ {
+ WriteJSONInteger(field.ID);
+ WriteJSONObjectStart();
+ WriteJSONString(GetTypeNameForTypeID(field.Type));
+ }
- public override void WriteFieldEnd()
- {
- WriteJSONObjectEnd();
- }
+ public override void WriteFieldEnd()
+ {
+ WriteJSONObjectEnd();
+ }
- public override void WriteFieldStop() { }
+ public override void WriteFieldStop() { }
- public override void WriteMapBegin(TMap map)
- {
- WriteJSONArrayStart();
- WriteJSONString(GetTypeNameForTypeID(map.KeyType));
- WriteJSONString(GetTypeNameForTypeID(map.ValueType));
- WriteJSONInteger(map.Count);
- WriteJSONObjectStart();
- }
+ public override void WriteMapBegin(TMap map)
+ {
+ WriteJSONArrayStart();
+ WriteJSONString(GetTypeNameForTypeID(map.KeyType));
+ WriteJSONString(GetTypeNameForTypeID(map.ValueType));
+ WriteJSONInteger(map.Count);
+ WriteJSONObjectStart();
+ }
- public override void WriteMapEnd()
- {
- WriteJSONObjectEnd();
- WriteJSONArrayEnd();
- }
+ public override void WriteMapEnd()
+ {
+ WriteJSONObjectEnd();
+ WriteJSONArrayEnd();
+ }
- public override void WriteListBegin(TList list)
- {
- WriteJSONArrayStart();
- WriteJSONString(GetTypeNameForTypeID(list.ElementType));
- WriteJSONInteger(list.Count);
- }
+ public override void WriteListBegin(TList list)
+ {
+ WriteJSONArrayStart();
+ WriteJSONString(GetTypeNameForTypeID(list.ElementType));
+ WriteJSONInteger(list.Count);
+ }
- public override void WriteListEnd()
- {
- WriteJSONArrayEnd();
- }
+ public override void WriteListEnd()
+ {
+ WriteJSONArrayEnd();
+ }
- public override void WriteSetBegin(TSet set)
- {
- WriteJSONArrayStart();
- WriteJSONString(GetTypeNameForTypeID(set.ElementType));
- WriteJSONInteger(set.Count);
- }
+ public override void WriteSetBegin(TSet set)
+ {
+ WriteJSONArrayStart();
+ WriteJSONString(GetTypeNameForTypeID(set.ElementType));
+ WriteJSONInteger(set.Count);
+ }
- public override void WriteSetEnd()
- {
- WriteJSONArrayEnd();
- }
+ public override void WriteSetEnd()
+ {
+ WriteJSONArrayEnd();
+ }
- public override void WriteBool(bool b)
- {
- WriteJSONInteger(b ? (long)1 : (long)0);
- }
+ public override void WriteBool(bool b)
+ {
+ WriteJSONInteger(b ? (long)1 : (long)0);
+ }
- public override void WriteByte(sbyte b)
- {
- WriteJSONInteger((long)b);
- }
+ public override void WriteByte(sbyte b)
+ {
+ WriteJSONInteger((long)b);
+ }
- public override void WriteI16(short i16)
- {
- WriteJSONInteger((long)i16);
- }
+ public override void WriteI16(short i16)
+ {
+ WriteJSONInteger((long)i16);
+ }
- public override void WriteI32(int i32)
- {
- WriteJSONInteger((long)i32);
- }
+ public override void WriteI32(int i32)
+ {
+ WriteJSONInteger((long)i32);
+ }
- public override void WriteI64(long i64)
- {
- WriteJSONInteger(i64);
- }
+ public override void WriteI64(long i64)
+ {
+ WriteJSONInteger(i64);
+ }
- public override void WriteDouble(double dub)
- {
- WriteJSONDouble(dub);
- }
+ public override void WriteDouble(double dub)
+ {
+ WriteJSONDouble(dub);
+ }
- public override void WriteString(String str)
- {
- byte[] b = utf8Encoding.GetBytes(str);
- WriteJSONString(b);
- }
+ public override void WriteString(String str)
+ {
+ byte[] b = utf8Encoding.GetBytes(str);
+ WriteJSONString(b);
+ }
- public override void WriteBinary(byte[] bin)
- {
- WriteJSONBase64(bin);
- }
+ public override void WriteBinary(byte[] bin)
+ {
+ WriteJSONBase64(bin);
+ }
- /**
- * Reading methods.
- */
+ /**
+ * Reading methods.
+ */
- ///<summary>
- /// Read in a JSON string, unescaping as appropriate.. Skip Reading from the
- /// context if skipContext is true.
- ///</summary>
- private byte[] ReadJSONString(bool skipContext)
- {
- MemoryStream buffer = new MemoryStream();
+ ///<summary>
+ /// Read in a JSON string, unescaping as appropriate.. Skip Reading from the
+ /// context if skipContext is true.
+ ///</summary>
+ private byte[] ReadJSONString(bool skipContext)
+ {
+ MemoryStream buffer = new MemoryStream();
- if (!skipContext)
- {
- context.Read();
- }
- ReadJSONSyntaxChar(QUOTE);
- while (true)
- {
- byte ch = reader.Read();
- if (ch == QUOTE[0])
- {
- break;
- }
+ if (!skipContext)
+ {
+ context.Read();
+ }
+ ReadJSONSyntaxChar(QUOTE);
+ while (true)
+ {
+ byte ch = reader.Read();
+ if (ch == QUOTE[0])
+ {
+ break;
+ }
- // escaped?
- if (ch != ESCSEQ[0])
- {
- buffer.Write(new byte[] { (byte)ch }, 0, 1);
- continue;
- }
+ // escaped?
+ if (ch != ESCSEQ[0])
+ {
+ buffer.Write(new byte[] { (byte)ch }, 0, 1);
+ continue;
+ }
- // distinguish between \uXXXX and \?
- ch = reader.Read();
- if (ch != ESCSEQ[1]) // control chars like \n
- {
- int off = Array.IndexOf(ESCAPE_CHARS, (char)ch);
- if (off == -1)
- {
- throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Expected control char");
- }
- ch = ESCAPE_CHAR_VALS[off];
- buffer.Write(new byte[] { (byte)ch }, 0, 1);
- continue;
- }
+ // distinguish between \uXXXX and \?
+ ch = reader.Read();
+ if (ch != ESCSEQ[1]) // control chars like \n
+ {
+ int off = Array.IndexOf(ESCAPE_CHARS, (char)ch);
+ if (off == -1)
+ {
+ throw new TProtocolException(TProtocolException.INVALID_DATA,
+ "Expected control char");
+ }
+ ch = ESCAPE_CHAR_VALS[off];
+ buffer.Write(new byte[] { (byte)ch }, 0, 1);
+ continue;
+ }
- // it's \uXXXX
- trans.ReadAll(tempBuffer, 0, 4);
- var wch = (short)((HexVal((byte)tempBuffer[0]) << 12) +
- (HexVal((byte)tempBuffer[1]) << 8) +
- (HexVal((byte)tempBuffer[2]) << 4) +
- HexVal(tempBuffer[3]));
- var tmp = utf8Encoding.GetBytes(new char[] { (char)wch });
- buffer.Write(tmp, 0, tmp.Length);
- }
- return buffer.ToArray();
- }
+ // it's \uXXXX
+ trans.ReadAll(tempBuffer, 0, 4);
+ var wch = (short)((HexVal((byte)tempBuffer[0]) << 12) +
+ (HexVal((byte)tempBuffer[1]) << 8) +
+ (HexVal((byte)tempBuffer[2]) << 4) +
+ HexVal(tempBuffer[3]));
+ var tmp = utf8Encoding.GetBytes(new char[] { (char)wch });
+ buffer.Write(tmp, 0, tmp.Length);
+ }
+ return buffer.ToArray();
+ }
- ///<summary>
- /// Return true if the given byte could be a valid part of a JSON number.
- ///</summary>
- private bool IsJSONNumeric(byte b)
- {
- switch (b)
- {
- case (byte)'+':
- case (byte)'-':
- case (byte)'.':
- case (byte)'0':
- case (byte)'1':
- case (byte)'2':
- case (byte)'3':
- case (byte)'4':
- case (byte)'5':
- case (byte)'6':
- case (byte)'7':
- case (byte)'8':
- case (byte)'9':
- case (byte)'E':
- case (byte)'e':
- return true;
- }
- return false;
- }
+ ///<summary>
+ /// Return true if the given byte could be a valid part of a JSON number.
+ ///</summary>
+ private bool IsJSONNumeric(byte b)
+ {
+ switch (b)
+ {
+ case (byte)'+':
+ case (byte)'-':
+ case (byte)'.':
+ case (byte)'0':
+ case (byte)'1':
+ case (byte)'2':
+ case (byte)'3':
+ case (byte)'4':
+ case (byte)'5':
+ case (byte)'6':
+ case (byte)'7':
+ case (byte)'8':
+ case (byte)'9':
+ case (byte)'E':
+ case (byte)'e':
+ return true;
+ }
+ return false;
+ }
- ///<summary>
- /// Read in a sequence of characters that are all valid in JSON numbers. Does
- /// not do a complete regex check to validate that this is actually a number.
- ////</summary>
- private String ReadJSONNumericChars()
- {
- StringBuilder strbld = new StringBuilder();
- while (true)
- {
- byte ch = reader.Peek();
- if (!IsJSONNumeric(ch))
- {
- break;
- }
- strbld.Append((char)reader.Read());
- }
- return strbld.ToString();
- }
+ ///<summary>
+ /// Read in a sequence of characters that are all valid in JSON numbers. Does
+ /// not do a complete regex check to validate that this is actually a number.
+ ////</summary>
+ private String ReadJSONNumericChars()
+ {
+ StringBuilder strbld = new StringBuilder();
+ while (true)
+ {
+ byte ch = reader.Peek();
+ if (!IsJSONNumeric(ch))
+ {
+ break;
+ }
+ strbld.Append((char)reader.Read());
+ }
+ return strbld.ToString();
+ }
- ///<summary>
- /// Read in a JSON number. If the context dictates, Read in enclosing quotes.
- ///</summary>
- private long ReadJSONInteger()
- {
- context.Read();
- if (context.EscapeNumbers())
- {
- ReadJSONSyntaxChar(QUOTE);
- }
- String str = ReadJSONNumericChars();
- if (context.EscapeNumbers())
- {
- ReadJSONSyntaxChar(QUOTE);
- }
- try
- {
- return Int64.Parse(str);
- }
- catch (FormatException)
- {
- throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Bad data encounted in numeric data");
- }
- }
+ ///<summary>
+ /// Read in a JSON number. If the context dictates, Read in enclosing quotes.
+ ///</summary>
+ private long ReadJSONInteger()
+ {
+ context.Read();
+ if (context.EscapeNumbers())
+ {
+ ReadJSONSyntaxChar(QUOTE);
+ }
+ String str = ReadJSONNumericChars();
+ if (context.EscapeNumbers())
+ {
+ ReadJSONSyntaxChar(QUOTE);
+ }
+ try
+ {
+ return Int64.Parse(str);
+ }
+ catch (FormatException)
+ {
+ throw new TProtocolException(TProtocolException.INVALID_DATA,
+ "Bad data encounted in numeric data");
+ }
+ }
- ///<summary>
- /// Read in a JSON double value. Throw if the value is not wrapped in quotes
- /// when expected or if wrapped in quotes when not expected.
- ///</summary>
- private double ReadJSONDouble()
- {
- context.Read();
- if (reader.Peek() == QUOTE[0])
- {
- byte[] arr = ReadJSONString(true);
- double dub = Double.Parse(utf8Encoding.GetString(arr,0,arr.Length), CultureInfo.InvariantCulture);
+ ///<summary>
+ /// Read in a JSON double value. Throw if the value is not wrapped in quotes
+ /// when expected or if wrapped in quotes when not expected.
+ ///</summary>
+ private double ReadJSONDouble()
+ {
+ context.Read();
+ if (reader.Peek() == QUOTE[0])
+ {
+ byte[] arr = ReadJSONString(true);
+ double dub = Double.Parse(utf8Encoding.GetString(arr,0,arr.Length), CultureInfo.InvariantCulture);
- if (!context.EscapeNumbers() && !Double.IsNaN(dub) &&
- !Double.IsInfinity(dub))
- {
- // Throw exception -- we should not be in a string in this case
- throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Numeric data unexpectedly quoted");
- }
- return dub;
- }
- else
- {
- if (context.EscapeNumbers())
- {
- // This will throw - we should have had a quote if escapeNum == true
- ReadJSONSyntaxChar(QUOTE);
- }
- try
- {
- return Double.Parse(ReadJSONNumericChars(), CultureInfo.InvariantCulture);
- }
- catch (FormatException)
- {
- throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Bad data encounted in numeric data");
- }
- }
- }
+ if (!context.EscapeNumbers() && !Double.IsNaN(dub) &&
+ !Double.IsInfinity(dub))
+ {
+ // Throw exception -- we should not be in a string in this case
+ throw new TProtocolException(TProtocolException.INVALID_DATA,
+ "Numeric data unexpectedly quoted");
+ }
+ return dub;
+ }
+ else
+ {
+ if (context.EscapeNumbers())
+ {
+ // This will throw - we should have had a quote if escapeNum == true
+ ReadJSONSyntaxChar(QUOTE);
+ }
+ try
+ {
+ return Double.Parse(ReadJSONNumericChars(), CultureInfo.InvariantCulture);
+ }
+ catch (FormatException)
+ {
+ throw new TProtocolException(TProtocolException.INVALID_DATA,
+ "Bad data encounted in numeric data");
+ }
+ }
+ }
- //<summary>
- /// Read in a JSON string containing base-64 encoded data and decode it.
- ///</summary>
- private byte[] ReadJSONBase64()
- {
- byte[] b = ReadJSONString(false);
- int len = b.Length;
- int off = 0;
- int size = 0;
- // reduce len to ignore fill bytes
- while ((len > 0) && (b[len - 1] == '='))
- {
- --len;
- }
- // read & decode full byte triplets = 4 source bytes
- while (len > 4)
- {
- // Decode 4 bytes at a time
- TBase64Utils.decode(b, off, 4, b, size); // NB: decoded in place
- off += 4;
- len -= 4;
- size += 3;
- }
- // Don't decode if we hit the end or got a single leftover byte (invalid
- // base64 but legal for skip of regular string type)
- if (len > 1)
- {
- // Decode remainder
- TBase64Utils.decode(b, off, len, b, size); // NB: decoded in place
- size += len - 1;
- }
- // Sadly we must copy the byte[] (any way around this?)
- byte[] result = new byte[size];
- Array.Copy(b, 0, result, 0, size);
- return result;
- }
+ //<summary>
+ /// Read in a JSON string containing base-64 encoded data and decode it.
+ ///</summary>
+ private byte[] ReadJSONBase64()
+ {
+ byte[] b = ReadJSONString(false);
+ int len = b.Length;
+ int off = 0;
+ int size = 0;
+ // reduce len to ignore fill bytes
+ while ((len > 0) && (b[len - 1] == '='))
+ {
+ --len;
+ }
+ // read & decode full byte triplets = 4 source bytes
+ while (len > 4)
+ {
+ // Decode 4 bytes at a time
+ TBase64Utils.decode(b, off, 4, b, size); // NB: decoded in place
+ off += 4;
+ len -= 4;
+ size += 3;
+ }
+ // Don't decode if we hit the end or got a single leftover byte (invalid
+ // base64 but legal for skip of regular string type)
+ if (len > 1)
+ {
+ // Decode remainder
+ TBase64Utils.decode(b, off, len, b, size); // NB: decoded in place
+ size += len - 1;
+ }
+ // Sadly we must copy the byte[] (any way around this?)
+ byte[] result = new byte[size];
+ Array.Copy(b, 0, result, 0, size);
+ return result;
+ }
- private void ReadJSONObjectStart()
- {
- context.Read();
- ReadJSONSyntaxChar(LBRACE);
- PushContext(new JSONPairContext(this));
- }
+ private void ReadJSONObjectStart()
+ {
+ context.Read();
+ ReadJSONSyntaxChar(LBRACE);
+ PushContext(new JSONPairContext(this));
+ }
- private void ReadJSONObjectEnd()
- {
- ReadJSONSyntaxChar(RBRACE);
- PopContext();
- }
+ private void ReadJSONObjectEnd()
+ {
+ ReadJSONSyntaxChar(RBRACE);
+ PopContext();
+ }
- private void ReadJSONArrayStart()
- {
- context.Read();
- ReadJSONSyntaxChar(LBRACKET);
- PushContext(new JSONListContext(this));
- }
+ private void ReadJSONArrayStart()
+ {
+ context.Read();
+ ReadJSONSyntaxChar(LBRACKET);
+ PushContext(new JSONListContext(this));
+ }
- private void ReadJSONArrayEnd()
- {
- ReadJSONSyntaxChar(RBRACKET);
- PopContext();
- }
+ private void ReadJSONArrayEnd()
+ {
+ ReadJSONSyntaxChar(RBRACKET);
+ PopContext();
+ }
- public override TMessage ReadMessageBegin()
- {
- TMessage message = new TMessage();
- ReadJSONArrayStart();
- if (ReadJSONInteger() != VERSION)
- {
- throw new TProtocolException(TProtocolException.BAD_VERSION,
- "Message contained bad version.");
- }
+ public override TMessage ReadMessageBegin()
+ {
+ TMessage message = new TMessage();
+ ReadJSONArrayStart();
+ if (ReadJSONInteger() != VERSION)
+ {
+ throw new TProtocolException(TProtocolException.BAD_VERSION,
+ "Message contained bad version.");
+ }
var buf = ReadJSONString(false);
- message.Name = utf8Encoding.GetString(buf,0,buf.Length);
- message.Type = (TMessageType)ReadJSONInteger();
- message.SeqID = (int)ReadJSONInteger();
- return message;
- }
+ message.Name = utf8Encoding.GetString(buf,0,buf.Length);
+ message.Type = (TMessageType)ReadJSONInteger();
+ message.SeqID = (int)ReadJSONInteger();
+ return message;
+ }
- public override void ReadMessageEnd()
- {
- ReadJSONArrayEnd();
- }
+ public override void ReadMessageEnd()
+ {
+ ReadJSONArrayEnd();
+ }
- public override TStruct ReadStructBegin()
- {
- ReadJSONObjectStart();
- return new TStruct();
- }
+ public override TStruct ReadStructBegin()
+ {
+ ReadJSONObjectStart();
+ return new TStruct();
+ }
- public override void ReadStructEnd()
- {
- ReadJSONObjectEnd();
- }
+ public override void ReadStructEnd()
+ {
+ ReadJSONObjectEnd();
+ }
- public override TField ReadFieldBegin()
- {
- TField field = new TField();
- byte ch = reader.Peek();
- if (ch == RBRACE[0])
- {
- field.Type = TType.Stop;
- }
- else
- {
- field.ID = (short)ReadJSONInteger();
- ReadJSONObjectStart();
- field.Type = GetTypeIDForTypeName(ReadJSONString(false));
- }
- return field;
- }
+ public override TField ReadFieldBegin()
+ {
+ TField field = new TField();
+ byte ch = reader.Peek();
+ if (ch == RBRACE[0])
+ {
+ field.Type = TType.Stop;
+ }
+ else
+ {
+ field.ID = (short)ReadJSONInteger();
+ ReadJSONObjectStart();
+ field.Type = GetTypeIDForTypeName(ReadJSONString(false));
+ }
+ return field;
+ }
- public override void ReadFieldEnd()
- {
- ReadJSONObjectEnd();
- }
+ public override void ReadFieldEnd()
+ {
+ ReadJSONObjectEnd();
+ }
- public override TMap ReadMapBegin()
- {
- TMap map = new TMap();
- ReadJSONArrayStart();
- map.KeyType = GetTypeIDForTypeName(ReadJSONString(false));
- map.ValueType = GetTypeIDForTypeName(ReadJSONString(false));
- map.Count = (int)ReadJSONInteger();
- ReadJSONObjectStart();
- return map;
- }
+ public override TMap ReadMapBegin()
+ {
+ TMap map = new TMap();
+ ReadJSONArrayStart();
+ map.KeyType = GetTypeIDForTypeName(ReadJSONString(false));
+ map.ValueType = GetTypeIDForTypeName(ReadJSONString(false));
+ map.Count = (int)ReadJSONInteger();
+ ReadJSONObjectStart();
+ return map;
+ }
- public override void ReadMapEnd()
- {
- ReadJSONObjectEnd();
- ReadJSONArrayEnd();
- }
+ public override void ReadMapEnd()
+ {
+ ReadJSONObjectEnd();
+ ReadJSONArrayEnd();
+ }
- public override TList ReadListBegin()
- {
- TList list = new TList();
- ReadJSONArrayStart();
- list.ElementType = GetTypeIDForTypeName(ReadJSONString(false));
- list.Count = (int)ReadJSONInteger();
- return list;
- }
+ public override TList ReadListBegin()
+ {
+ TList list = new TList();
+ ReadJSONArrayStart();
+ list.ElementType = GetTypeIDForTypeName(ReadJSONString(false));
+ list.Count = (int)ReadJSONInteger();
+ return list;
+ }
- public override void ReadListEnd()
- {
- ReadJSONArrayEnd();
- }
+ public override void ReadListEnd()
+ {
+ ReadJSONArrayEnd();
+ }
- public override TSet ReadSetBegin()
- {
- TSet set = new TSet();
- ReadJSONArrayStart();
- set.ElementType = GetTypeIDForTypeName(ReadJSONString(false));
- set.Count = (int)ReadJSONInteger();
- return set;
- }
+ public override TSet ReadSetBegin()
+ {
+ TSet set = new TSet();
+ ReadJSONArrayStart();
+ set.ElementType = GetTypeIDForTypeName(ReadJSONString(false));
+ set.Count = (int)ReadJSONInteger();
+ return set;
+ }
- public override void ReadSetEnd()
- {
- ReadJSONArrayEnd();
- }
+ public override void ReadSetEnd()
+ {
+ ReadJSONArrayEnd();
+ }
- public override bool ReadBool()
- {
- return (ReadJSONInteger() == 0 ? false : true);
- }
+ public override bool ReadBool()
+ {
+ return (ReadJSONInteger() == 0 ? false : true);
+ }
- public override sbyte ReadByte()
- {
- return (sbyte)ReadJSONInteger();
- }
+ public override sbyte ReadByte()
+ {
+ return (sbyte)ReadJSONInteger();
+ }
- public override short ReadI16()
- {
- return (short)ReadJSONInteger();
- }
+ public override short ReadI16()
+ {
+ return (short)ReadJSONInteger();
+ }
- public override int ReadI32()
- {
- return (int)ReadJSONInteger();
- }
+ public override int ReadI32()
+ {
+ return (int)ReadJSONInteger();
+ }
- public override long ReadI64()
- {
- return (long)ReadJSONInteger();
- }
+ public override long ReadI64()
+ {
+ return (long)ReadJSONInteger();
+ }
- public override double ReadDouble()
- {
- return ReadJSONDouble();
- }
+ public override double ReadDouble()
+ {
+ return ReadJSONDouble();
+ }
- public override String ReadString()
- {
+ public override String ReadString()
+ {
var buf = ReadJSONString(false);
- return utf8Encoding.GetString(buf,0,buf.Length);
- }
+ return utf8Encoding.GetString(buf,0,buf.Length);
+ }
- public override byte[] ReadBinary()
- {
- return ReadJSONBase64();
- }
+ public override byte[] ReadBinary()
+ {
+ return ReadJSONBase64();
+ }
- }
+ }
}
diff --git a/lib/csharp/src/Protocol/TList.cs b/lib/csharp/src/Protocol/TList.cs
index a651eb1..0c8f214 100644
--- a/lib/csharp/src/Protocol/TList.cs
+++ b/lib/csharp/src/Protocol/TList.cs
@@ -27,28 +27,28 @@
namespace Thrift.Protocol
{
- public struct TList
- {
- private TType elementType;
- private int count;
+ public struct TList
+ {
+ private TType elementType;
+ private int count;
- public TList(TType elementType, int count)
- :this()
- {
- this.elementType = elementType;
- this.count = count;
- }
+ public TList(TType elementType, int count)
+ :this()
+ {
+ this.elementType = elementType;
+ this.count = count;
+ }
- public TType ElementType
- {
- get { return elementType; }
- set { elementType = value; }
- }
+ public TType ElementType
+ {
+ get { return elementType; }
+ set { elementType = value; }
+ }
- public int Count
- {
- get { return count; }
- set { count = value; }
- }
- }
+ public int Count
+ {
+ get { return count; }
+ set { count = value; }
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TMap.cs b/lib/csharp/src/Protocol/TMap.cs
index 5c8d650..aba9d3a 100644
--- a/lib/csharp/src/Protocol/TMap.cs
+++ b/lib/csharp/src/Protocol/TMap.cs
@@ -27,36 +27,36 @@
namespace Thrift.Protocol
{
- public struct TMap
- {
- private TType keyType;
- private TType valueType;
- private int count;
+ public struct TMap
+ {
+ private TType keyType;
+ private TType valueType;
+ private int count;
- public TMap(TType keyType, TType valueType, int count)
- :this()
- {
- this.keyType = keyType;
- this.valueType = valueType;
- this.count = count;
- }
+ public TMap(TType keyType, TType valueType, int count)
+ :this()
+ {
+ this.keyType = keyType;
+ this.valueType = valueType;
+ this.count = count;
+ }
- public TType KeyType
- {
- get { return keyType; }
- set { keyType = value; }
- }
+ public TType KeyType
+ {
+ get { return keyType; }
+ set { keyType = value; }
+ }
- public TType ValueType
- {
- get { return valueType; }
- set { valueType = value; }
- }
+ public TType ValueType
+ {
+ get { return valueType; }
+ set { valueType = value; }
+ }
- public int Count
- {
- get { return count; }
- set { count = value; }
- }
- }
+ public int Count
+ {
+ get { return count; }
+ set { count = value; }
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TMessage.cs b/lib/csharp/src/Protocol/TMessage.cs
index 8e96da5..348263c 100644
--- a/lib/csharp/src/Protocol/TMessage.cs
+++ b/lib/csharp/src/Protocol/TMessage.cs
@@ -27,36 +27,36 @@
namespace Thrift.Protocol
{
- public struct TMessage
- {
- private string name;
- private TMessageType type;
- private int seqID;
+ public struct TMessage
+ {
+ private string name;
+ private TMessageType type;
+ private int seqID;
- public TMessage(string name, TMessageType type, int seqid)
- :this()
- {
- this.name = name;
- this.type = type;
- this.seqID = seqid;
- }
+ public TMessage(string name, TMessageType type, int seqid)
+ :this()
+ {
+ this.name = name;
+ this.type = type;
+ this.seqID = seqid;
+ }
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
+ public string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
- public TMessageType Type
- {
- get { return type; }
- set { type = value; }
- }
+ public TMessageType Type
+ {
+ get { return type; }
+ set { type = value; }
+ }
- public int SeqID
- {
- get { return seqID; }
- set { seqID = value; }
- }
- }
+ public int SeqID
+ {
+ get { return seqID; }
+ set { seqID = value; }
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TMessageType.cs b/lib/csharp/src/Protocol/TMessageType.cs
index ab07cf6..c7091fe 100644
--- a/lib/csharp/src/Protocol/TMessageType.cs
+++ b/lib/csharp/src/Protocol/TMessageType.cs
@@ -21,11 +21,11 @@
namespace Thrift.Protocol
{
- public enum TMessageType
- {
- Call = 1,
- Reply = 2,
- Exception = 3,
- Oneway = 4
- }
+ public enum TMessageType
+ {
+ Call = 1,
+ Reply = 2,
+ Exception = 3,
+ Oneway = 4
+ }
}
diff --git a/lib/csharp/src/Protocol/TMultiplexedProcessor.cs b/lib/csharp/src/Protocol/TMultiplexedProcessor.cs
index 4ce8d62..050b162 100644
--- a/lib/csharp/src/Protocol/TMultiplexedProcessor.cs
+++ b/lib/csharp/src/Protocol/TMultiplexedProcessor.cs
@@ -27,12 +27,12 @@
using System.Collections.Generic;
using System.IO;
-namespace Thrift.Protocol
+namespace Thrift.Protocol
{
/**
* TMultiplexedProcessor is a TProcessor allowing a single TServer to provide multiple services.
- * To do so, you instantiate the processor and then register additional processors with it,
+ * To do so, you instantiate the processor and then register additional processors with it,
* as shown in the following example:
*
* TMultiplexedProcessor processor = new TMultiplexedProcessor();
@@ -50,26 +50,26 @@
*
* server.serve();
*/
- public class TMultiplexedProcessor : TProcessor
+ public class TMultiplexedProcessor : TProcessor
{
private Dictionary<String,TProcessor> ServiceProcessorMap = new Dictionary<String,TProcessor>();
/**
- * 'Register' a service with this TMultiplexedProcessor. This allows us to broker
+ * 'Register' a service with this TMultiplexedProcessor. This allows us to broker
* requests to individual services by using the service name to select them at request time.
*
- * Args:
+ * Args:
* - serviceName Name of a service, has to be identical to the name
* declared in the Thrift IDL, e.g. "WeatherReport".
- * - processor Implementation of a service, ususally referred to as "handlers",
+ * - processor Implementation of a service, ususally referred to as "handlers",
* e.g. WeatherReportHandler implementing WeatherReport.Iface.
*/
- public void RegisterProcessor(String serviceName, TProcessor processor)
+ public void RegisterProcessor(String serviceName, TProcessor processor)
{
ServiceProcessorMap.Add(serviceName, processor);
}
-
+
private void Fail( TProtocol oprot, TMessage message, TApplicationException.ExceptionType extype, string etxt)
{
TApplicationException appex = new TApplicationException( extype, etxt);
@@ -81,8 +81,8 @@
oprot.WriteMessageEnd();
oprot.Transport.Flush();
}
-
-
+
+
/**
* This implementation of process performs the following steps:
*
@@ -91,11 +91,11 @@
* - Using the service name to locate the appropriate processor.
* - Dispatch to the processor, with a decorated instance of TProtocol
* that allows readMessageBegin() to return the original TMessage.
- *
- * Throws an exception if
- * - the message type is not CALL or ONEWAY,
- * - the service name was not found in the message, or
- * - the service name has not been RegisterProcessor()ed.
+ *
+ * Throws an exception if
+ * - the message type is not CALL or ONEWAY,
+ * - the service name was not found in the message, or
+ * - the service name has not been RegisterProcessor()ed.
*/
public bool Process(TProtocol iprot, TProtocol oprot)
{
@@ -160,17 +160,17 @@
* to allow them to call readMessageBegin() and get a TMessage in exactly
* the standard format, without the service name prepended to TMessage.name.
*/
- private class StoredMessageProtocol : TProtocolDecorator
+ private class StoredMessageProtocol : TProtocolDecorator
{
TMessage MsgBegin;
- public StoredMessageProtocol(TProtocol protocol, TMessage messageBegin)
+ public StoredMessageProtocol(TProtocol protocol, TMessage messageBegin)
:base(protocol)
{
this.MsgBegin = messageBegin;
}
- public override TMessage ReadMessageBegin()
+ public override TMessage ReadMessageBegin()
{
return MsgBegin;
}
diff --git a/lib/csharp/src/Protocol/TMultiplexedProtocol.cs b/lib/csharp/src/Protocol/TMultiplexedProtocol.cs
index ccd7fcf..1e2af83 100644
--- a/lib/csharp/src/Protocol/TMultiplexedProtocol.cs
+++ b/lib/csharp/src/Protocol/TMultiplexedProtocol.cs
@@ -26,22 +26,22 @@
using Thrift.Transport;
using System.Collections.Generic;
-namespace Thrift.Protocol
+namespace Thrift.Protocol
{
/**
- * TMultiplexedProtocol is a protocol-independent concrete decorator that allows a Thrift
- * client to communicate with a multiplexing Thrift server, by prepending the service name
+ * TMultiplexedProtocol is a protocol-independent concrete decorator that allows a Thrift
+ * client to communicate with a multiplexing Thrift server, by prepending the service name
* to the function name during function calls.
*
- * NOTE: THIS IS NOT TO BE USED BY SERVERS.
+ * NOTE: THIS IS NOT TO BE USED BY SERVERS.
* On the server, use TMultiplexedProcessor to handle requests from a multiplexing client.
*
* This example uses a single socket transport to invoke two services:
*
* TSocket transport = new TSocket("localhost", 9090);
* transport.open();
- *
+ *
* TBinaryProtocol protocol = new TBinaryProtocol(transport);
*
* TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "Calculator");
@@ -54,7 +54,7 @@
* System.out.println(service2.getTemperature());
*
*/
- public class TMultiplexedProtocol : TProtocolDecorator
+ public class TMultiplexedProtocol : TProtocolDecorator
{
/** Used to delimit the service name from the function name */
@@ -72,7 +72,7 @@
* protocol Your communication protocol of choice, e.g. TBinaryProtocol
* serviceName The service name of the service communicating via this protocol.
*/
- public TMultiplexedProtocol(TProtocol protocol, String serviceName)
+ public TMultiplexedProtocol(TProtocol protocol, String serviceName)
: base(protocol)
{
ServiceName = serviceName;
@@ -83,7 +83,7 @@
* Args:
* tMessage The original message.
*/
- public override void WriteMessageBegin(TMessage tMessage)
+ public override void WriteMessageBegin(TMessage tMessage)
{
switch(tMessage.Type)
{
diff --git a/lib/csharp/src/Protocol/TProtocol.cs b/lib/csharp/src/Protocol/TProtocol.cs
index 70920d4..1f5bd81 100644
--- a/lib/csharp/src/Protocol/TProtocol.cs
+++ b/lib/csharp/src/Protocol/TProtocol.cs
@@ -27,19 +27,19 @@
namespace Thrift.Protocol
{
- public abstract class TProtocol : IDisposable
- {
- protected TTransport trans;
+ public abstract class TProtocol : IDisposable
+ {
+ protected TTransport trans;
- protected TProtocol(TTransport trans)
- {
- this.trans = trans;
- }
+ protected TProtocol(TTransport trans)
+ {
+ this.trans = trans;
+ }
- public TTransport Transport
- {
- get { return trans; }
- }
+ public TTransport Transport
+ {
+ get { return trans; }
+ }
#region " IDisposable Support "
private bool _IsDisposed;
@@ -64,52 +64,52 @@
}
#endregion
- public abstract void WriteMessageBegin(TMessage message);
- public abstract void WriteMessageEnd();
- public abstract void WriteStructBegin(TStruct struc);
- public abstract void WriteStructEnd();
- public abstract void WriteFieldBegin(TField field);
- public abstract void WriteFieldEnd();
- public abstract void WriteFieldStop();
- public abstract void WriteMapBegin(TMap map);
- public abstract void WriteMapEnd();
- public abstract void WriteListBegin(TList list);
- public abstract void WriteListEnd();
- public abstract void WriteSetBegin(TSet set);
- public abstract void WriteSetEnd();
- public abstract void WriteBool(bool b);
- public abstract void WriteByte(sbyte b);
- public abstract void WriteI16(short i16);
- public abstract void WriteI32(int i32);
- public abstract void WriteI64(long i64);
- public abstract void WriteDouble(double d);
- public virtual void WriteString(string s) {
- WriteBinary(Encoding.UTF8.GetBytes(s));
- }
- public abstract void WriteBinary(byte[] b);
+ public abstract void WriteMessageBegin(TMessage message);
+ public abstract void WriteMessageEnd();
+ public abstract void WriteStructBegin(TStruct struc);
+ public abstract void WriteStructEnd();
+ public abstract void WriteFieldBegin(TField field);
+ public abstract void WriteFieldEnd();
+ public abstract void WriteFieldStop();
+ public abstract void WriteMapBegin(TMap map);
+ public abstract void WriteMapEnd();
+ public abstract void WriteListBegin(TList list);
+ public abstract void WriteListEnd();
+ public abstract void WriteSetBegin(TSet set);
+ public abstract void WriteSetEnd();
+ public abstract void WriteBool(bool b);
+ public abstract void WriteByte(sbyte b);
+ public abstract void WriteI16(short i16);
+ public abstract void WriteI32(int i32);
+ public abstract void WriteI64(long i64);
+ public abstract void WriteDouble(double d);
+ public virtual void WriteString(string s) {
+ WriteBinary(Encoding.UTF8.GetBytes(s));
+ }
+ public abstract void WriteBinary(byte[] b);
- public abstract TMessage ReadMessageBegin();
- public abstract void ReadMessageEnd();
- public abstract TStruct ReadStructBegin();
- public abstract void ReadStructEnd();
- public abstract TField ReadFieldBegin();
- public abstract void ReadFieldEnd();
- public abstract TMap ReadMapBegin();
- public abstract void ReadMapEnd();
- public abstract TList ReadListBegin();
- public abstract void ReadListEnd();
- public abstract TSet ReadSetBegin();
- public abstract void ReadSetEnd();
- public abstract bool ReadBool();
- public abstract sbyte ReadByte();
- public abstract short ReadI16();
- public abstract int ReadI32();
- public abstract long ReadI64();
- public abstract double ReadDouble();
- public virtual string ReadString() {
+ public abstract TMessage ReadMessageBegin();
+ public abstract void ReadMessageEnd();
+ public abstract TStruct ReadStructBegin();
+ public abstract void ReadStructEnd();
+ public abstract TField ReadFieldBegin();
+ public abstract void ReadFieldEnd();
+ public abstract TMap ReadMapBegin();
+ public abstract void ReadMapEnd();
+ public abstract TList ReadListBegin();
+ public abstract void ReadListEnd();
+ public abstract TSet ReadSetBegin();
+ public abstract void ReadSetEnd();
+ public abstract bool ReadBool();
+ public abstract sbyte ReadByte();
+ public abstract short ReadI16();
+ public abstract int ReadI32();
+ public abstract long ReadI64();
+ public abstract double ReadDouble();
+ public virtual string ReadString() {
var buf = ReadBinary();
return Encoding.UTF8.GetString(buf, 0, buf.Length);
}
- public abstract byte[] ReadBinary();
- }
+ public abstract byte[] ReadBinary();
+ }
}
diff --git a/lib/csharp/src/Protocol/TProtocolDecorator.cs b/lib/csharp/src/Protocol/TProtocolDecorator.cs
index 218a5c1..7bc34ef 100644
--- a/lib/csharp/src/Protocol/TProtocolDecorator.cs
+++ b/lib/csharp/src/Protocol/TProtocolDecorator.cs
@@ -26,19 +26,19 @@
using Thrift.Transport;
using System.Collections.Generic;
-namespace Thrift.Protocol
+namespace Thrift.Protocol
{
/**
- * TProtocolDecorator forwards all requests to an enclosed TProtocol instance,
- * providing a way to author concise concrete decorator subclasses. While it has
- * no abstract methods, it is marked abstract as a reminder that by itself,
+ * TProtocolDecorator forwards all requests to an enclosed TProtocol instance,
+ * providing a way to author concise concrete decorator subclasses. While it has
+ * no abstract methods, it is marked abstract as a reminder that by itself,
* it does not modify the behaviour of the enclosed TProtocol.
*
* See p.175 of Design Patterns (by Gamma et al.)
* See TMultiplexedProtocol
*/
- public abstract class TProtocolDecorator : TProtocol
+ public abstract class TProtocolDecorator : TProtocol
{
private TProtocol WrappedProtocol;
@@ -46,14 +46,14 @@
* Encloses the specified protocol.
* @param protocol All operations will be forward to this protocol. Must be non-null.
*/
- public TProtocolDecorator(TProtocol protocol)
+ public TProtocolDecorator(TProtocol protocol)
: base( protocol.Transport)
{
-
+
WrappedProtocol = protocol;
}
- public override void WriteMessageBegin(TMessage tMessage)
+ public override void WriteMessageBegin(TMessage tMessage)
{
WrappedProtocol.WriteMessageBegin(tMessage);
}
@@ -88,7 +88,7 @@
WrappedProtocol.WriteFieldStop();
}
- public override void WriteMapBegin(TMap tMap)
+ public override void WriteMapBegin(TMap tMap)
{
WrappedProtocol.WriteMapBegin(tMap);
}
@@ -98,7 +98,7 @@
WrappedProtocol.WriteMapEnd();
}
- public override void WriteListBegin(TList tList)
+ public override void WriteListBegin(TList tList)
{
WrappedProtocol.WriteListBegin(tList);
}
@@ -108,7 +108,7 @@
WrappedProtocol.WriteListEnd();
}
- public override void WriteSetBegin(TSet tSet)
+ public override void WriteSetBegin(TSet tSet)
{
WrappedProtocol.WriteSetBegin(tSet);
}
@@ -118,7 +118,7 @@
WrappedProtocol.WriteSetEnd();
}
- public override void WriteBool(bool b)
+ public override void WriteBool(bool b)
{
WrappedProtocol.WriteBool(b);
}
diff --git a/lib/csharp/src/Protocol/TProtocolException.cs b/lib/csharp/src/Protocol/TProtocolException.cs
index 05eb2db..76c749d 100644
--- a/lib/csharp/src/Protocol/TProtocolException.cs
+++ b/lib/csharp/src/Protocol/TProtocolException.cs
@@ -25,43 +25,43 @@
namespace Thrift.Protocol
{
- public class TProtocolException : TException
- {
- public const int UNKNOWN = 0;
- public const int INVALID_DATA = 1;
- public const int NEGATIVE_SIZE = 2;
- public const int SIZE_LIMIT = 3;
- public const int BAD_VERSION = 4;
- public const int NOT_IMPLEMENTED = 5;
- public const int DEPTH_LIMIT = 6;
+ public class TProtocolException : TException
+ {
+ public const int UNKNOWN = 0;
+ public const int INVALID_DATA = 1;
+ public const int NEGATIVE_SIZE = 2;
+ public const int SIZE_LIMIT = 3;
+ public const int BAD_VERSION = 4;
+ public const int NOT_IMPLEMENTED = 5;
+ public const int DEPTH_LIMIT = 6;
- protected int type_ = UNKNOWN;
+ protected int type_ = UNKNOWN;
- public TProtocolException()
- : base()
- {
- }
+ public TProtocolException()
+ : base()
+ {
+ }
- public TProtocolException(int type)
- : base()
- {
- type_ = type;
- }
+ public TProtocolException(int type)
+ : base()
+ {
+ type_ = type;
+ }
- public TProtocolException(int type, String message)
- : base(message)
- {
- type_ = type;
- }
+ public TProtocolException(int type, String message)
+ : base(message)
+ {
+ type_ = type;
+ }
- public TProtocolException(String message)
- : base(message)
- {
- }
+ public TProtocolException(String message)
+ : base(message)
+ {
+ }
- public int getType()
- {
- return type_;
- }
- }
+ public int getType()
+ {
+ return type_;
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TProtocolFactory.cs b/lib/csharp/src/Protocol/TProtocolFactory.cs
index ebc7367..71360a1 100644
--- a/lib/csharp/src/Protocol/TProtocolFactory.cs
+++ b/lib/csharp/src/Protocol/TProtocolFactory.cs
@@ -26,8 +26,8 @@
namespace Thrift.Protocol
{
- public interface TProtocolFactory
- {
- TProtocol GetProtocol(TTransport trans);
- }
+ public interface TProtocolFactory
+ {
+ TProtocol GetProtocol(TTransport trans);
+ }
}
diff --git a/lib/csharp/src/Protocol/TProtocolUtil.cs b/lib/csharp/src/Protocol/TProtocolUtil.cs
index 82cd3e3..91140d3 100644
--- a/lib/csharp/src/Protocol/TProtocolUtil.cs
+++ b/lib/csharp/src/Protocol/TProtocolUtil.cs
@@ -25,74 +25,74 @@
namespace Thrift.Protocol
{
- public static class TProtocolUtil
- {
- public static void Skip(TProtocol prot, TType type)
- {
- switch (type)
- {
- case TType.Bool:
- prot.ReadBool();
- break;
- case TType.Byte:
- prot.ReadByte();
- break;
- case TType.I16:
- prot.ReadI16();
- break;
- case TType.I32:
- prot.ReadI32();
- break;
- case TType.I64:
- prot.ReadI64();
- break;
- case TType.Double:
- prot.ReadDouble();
- break;
- case TType.String:
- // Don't try to decode the string, just skip it.
- prot.ReadBinary();
- break;
- case TType.Struct:
- prot.ReadStructBegin();
- while (true)
- {
- TField field = prot.ReadFieldBegin();
- if (field.Type == TType.Stop)
- {
- break;
- }
- Skip(prot, field.Type);
- prot.ReadFieldEnd();
- }
- prot.ReadStructEnd();
- break;
- case TType.Map:
- TMap map = prot.ReadMapBegin();
- for (int i = 0; i < map.Count; i++)
- {
- Skip(prot, map.KeyType);
- Skip(prot, map.ValueType);
- }
- prot.ReadMapEnd();
- break;
- case TType.Set:
- TSet set = prot.ReadSetBegin();
- for (int i = 0; i < set.Count; i++)
- {
- Skip(prot, set.ElementType);
- }
- prot.ReadSetEnd();
- break;
- case TType.List:
- TList list = prot.ReadListBegin();
- for (int i = 0; i < list.Count; i++)
- {
- Skip(prot, list.ElementType);
- }
- prot.ReadListEnd();
- break;
- }
- }
- }
+ public static class TProtocolUtil
+ {
+ public static void Skip(TProtocol prot, TType type)
+ {
+ switch (type)
+ {
+ case TType.Bool:
+ prot.ReadBool();
+ break;
+ case TType.Byte:
+ prot.ReadByte();
+ break;
+ case TType.I16:
+ prot.ReadI16();
+ break;
+ case TType.I32:
+ prot.ReadI32();
+ break;
+ case TType.I64:
+ prot.ReadI64();
+ break;
+ case TType.Double:
+ prot.ReadDouble();
+ break;
+ case TType.String:
+ // Don't try to decode the string, just skip it.
+ prot.ReadBinary();
+ break;
+ case TType.Struct:
+ prot.ReadStructBegin();
+ while (true)
+ {
+ TField field = prot.ReadFieldBegin();
+ if (field.Type == TType.Stop)
+ {
+ break;
+ }
+ Skip(prot, field.Type);
+ prot.ReadFieldEnd();
+ }
+ prot.ReadStructEnd();
+ break;
+ case TType.Map:
+ TMap map = prot.ReadMapBegin();
+ for (int i = 0; i < map.Count; i++)
+ {
+ Skip(prot, map.KeyType);
+ Skip(prot, map.ValueType);
+ }
+ prot.ReadMapEnd();
+ break;
+ case TType.Set:
+ TSet set = prot.ReadSetBegin();
+ for (int i = 0; i < set.Count; i++)
+ {
+ Skip(prot, set.ElementType);
+ }
+ prot.ReadSetEnd();
+ break;
+ case TType.List:
+ TList list = prot.ReadListBegin();
+ for (int i = 0; i < list.Count; i++)
+ {
+ Skip(prot, list.ElementType);
+ }
+ prot.ReadListEnd();
+ break;
+ }
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TSet.cs b/lib/csharp/src/Protocol/TSet.cs
index 68e5286..a918ab5 100644
--- a/lib/csharp/src/Protocol/TSet.cs
+++ b/lib/csharp/src/Protocol/TSet.cs
@@ -27,33 +27,33 @@
namespace Thrift.Protocol
{
- public struct TSet
- {
- private TType elementType;
- private int count;
+ public struct TSet
+ {
+ private TType elementType;
+ private int count;
- public TSet(TType elementType, int count)
- :this()
- {
- this.elementType = elementType;
- this.count = count;
- }
+ public TSet(TType elementType, int count)
+ :this()
+ {
+ this.elementType = elementType;
+ this.count = count;
+ }
- public TSet(TList list)
- : this(list.ElementType, list.Count)
- {
- }
+ public TSet(TList list)
+ : this(list.ElementType, list.Count)
+ {
+ }
- public TType ElementType
- {
- get { return elementType; }
- set { elementType = value; }
- }
+ public TType ElementType
+ {
+ get { return elementType; }
+ set { elementType = value; }
+ }
- public int Count
- {
- get { return count; }
- set { count = value; }
- }
- }
+ public int Count
+ {
+ get { return count; }
+ set { count = value; }
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TStruct.cs b/lib/csharp/src/Protocol/TStruct.cs
index 37d1106..f4844a4 100644
--- a/lib/csharp/src/Protocol/TStruct.cs
+++ b/lib/csharp/src/Protocol/TStruct.cs
@@ -27,20 +27,20 @@
namespace Thrift.Protocol
{
- public struct TStruct
- {
- private string name;
+ public struct TStruct
+ {
+ private string name;
- public TStruct(string name)
- :this()
- {
- this.name = name;
- }
+ public TStruct(string name)
+ :this()
+ {
+ this.name = name;
+ }
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- }
+ public string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+ }
}
diff --git a/lib/csharp/src/Protocol/TType.cs b/lib/csharp/src/Protocol/TType.cs
index efc7bef..9ce915e 100644
--- a/lib/csharp/src/Protocol/TType.cs
+++ b/lib/csharp/src/Protocol/TType.cs
@@ -25,20 +25,20 @@
namespace Thrift.Protocol
{
- public enum TType : byte
- {
- Stop = 0,
- Void = 1,
- Bool = 2,
- Byte = 3,
- Double = 4,
- I16 = 6,
- I32 = 8,
- I64 = 10,
- String = 11,
- Struct = 12,
- Map = 13,
- Set = 14,
- List = 15
- }
+ public enum TType : byte
+ {
+ Stop = 0,
+ Void = 1,
+ Bool = 2,
+ Byte = 3,
+ Double = 4,
+ I16 = 6,
+ I32 = 8,
+ I64 = 10,
+ String = 11,
+ Struct = 12,
+ Map = 13,
+ Set = 14,
+ List = 15
+ }
}
diff --git a/lib/csharp/src/Server/TSimpleServer.cs b/lib/csharp/src/Server/TSimpleServer.cs
index 42e0cbe..36bbe9d 100644
--- a/lib/csharp/src/Server/TSimpleServer.cs
+++ b/lib/csharp/src/Server/TSimpleServer.cs
@@ -118,7 +118,7 @@
//Process client requests until client disconnects
while (true)
{
- if (!inputTransport.Peek())
+ if (!inputTransport.Peek())
break;
//Fire processContext server event
diff --git a/lib/csharp/src/Server/TThreadPoolServer.cs b/lib/csharp/src/Server/TThreadPoolServer.cs
index 8542b6d..aff5733 100644
--- a/lib/csharp/src/Server/TThreadPoolServer.cs
+++ b/lib/csharp/src/Server/TThreadPoolServer.cs
@@ -172,7 +172,7 @@
//Process client requests until client disconnects
while (true)
{
- if (!inputTransport.Peek())
+ if (!inputTransport.Peek())
break;
//Fire processContext server event
diff --git a/lib/csharp/src/Server/TThreadedServer.cs b/lib/csharp/src/Server/TThreadedServer.cs
index 87bff31..9e96371 100644
--- a/lib/csharp/src/Server/TThreadedServer.cs
+++ b/lib/csharp/src/Server/TThreadedServer.cs
@@ -204,7 +204,7 @@
//Process client requests until client disconnects
while (true)
{
- if (!inputTransport.Peek())
+ if (!inputTransport.Peek())
break;
//Fire processContext server event
diff --git a/lib/csharp/src/TApplicationException.cs b/lib/csharp/src/TApplicationException.cs
index 4a1b2d2..4c0d3a3 100644
--- a/lib/csharp/src/TApplicationException.cs
+++ b/lib/csharp/src/TApplicationException.cs
@@ -26,116 +26,116 @@
namespace Thrift
{
- public class TApplicationException : TException
- {
- protected ExceptionType type;
+ public class TApplicationException : TException
+ {
+ protected ExceptionType type;
- public TApplicationException()
- {
- }
+ public TApplicationException()
+ {
+ }
- public TApplicationException(ExceptionType type)
- {
- this.type = type;
- }
+ public TApplicationException(ExceptionType type)
+ {
+ this.type = type;
+ }
- public TApplicationException(ExceptionType type, string message)
- : base(message)
- {
- this.type = type;
- }
+ public TApplicationException(ExceptionType type, string message)
+ : base(message)
+ {
+ this.type = type;
+ }
- public static TApplicationException Read(TProtocol iprot)
- {
- TField field;
+ public static TApplicationException Read(TProtocol iprot)
+ {
+ TField field;
- string message = null;
- ExceptionType type = ExceptionType.Unknown;
+ string message = null;
+ ExceptionType type = ExceptionType.Unknown;
- iprot.ReadStructBegin();
- while (true)
- {
- field = iprot.ReadFieldBegin();
- if (field.Type == TType.Stop)
- {
- break;
- }
+ iprot.ReadStructBegin();
+ while (true)
+ {
+ field = iprot.ReadFieldBegin();
+ if (field.Type == TType.Stop)
+ {
+ 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 = (ExceptionType)iprot.ReadI32();
- }
- else
- {
- TProtocolUtil.Skip(iprot, field.Type);
- }
- break;
- default:
- TProtocolUtil.Skip(iprot, field.Type);
- 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 = (ExceptionType)iprot.ReadI32();
+ }
+ else
+ {
+ TProtocolUtil.Skip(iprot, field.Type);
+ }
+ break;
+ default:
+ TProtocolUtil.Skip(iprot, field.Type);
+ break;
+ }
- iprot.ReadFieldEnd();
- }
+ iprot.ReadFieldEnd();
+ }
- iprot.ReadStructEnd();
+ iprot.ReadStructEnd();
- return new TApplicationException(type, message);
- }
+ return new TApplicationException(type, message);
+ }
- public void Write(TProtocol oprot)
- {
- TStruct struc = new TStruct("TApplicationException");
- TField field = new TField();
+ public void Write(TProtocol oprot)
+ {
+ TStruct struc = new TStruct("TApplicationException");
+ TField field = new TField();
- oprot.WriteStructBegin(struc);
+ oprot.WriteStructBegin(struc);
- if (!String.IsNullOrEmpty(Message))
- {
- field.Name = "message";
- field.Type = TType.String;
- field.ID = 1;
- oprot.WriteFieldBegin(field);
- oprot.WriteString(Message);
- oprot.WriteFieldEnd();
- }
+ if (!String.IsNullOrEmpty(Message))
+ {
+ field.Name = "message";
+ field.Type = TType.String;
+ field.ID = 1;
+ oprot.WriteFieldBegin(field);
+ oprot.WriteString(Message);
+ oprot.WriteFieldEnd();
+ }
- field.Name = "type";
- field.Type = TType.I32;
- field.ID = 2;
- oprot.WriteFieldBegin(field);
- oprot.WriteI32((int)type);
- oprot.WriteFieldEnd();
- oprot.WriteFieldStop();
- oprot.WriteStructEnd();
- }
+ field.Name = "type";
+ field.Type = TType.I32;
+ field.ID = 2;
+ oprot.WriteFieldBegin(field);
+ oprot.WriteI32((int)type);
+ oprot.WriteFieldEnd();
+ oprot.WriteFieldStop();
+ oprot.WriteStructEnd();
+ }
- public enum ExceptionType
- {
- Unknown,
- UnknownMethod,
- InvalidMessageType,
- WrongMethodName,
- BadSequenceID,
- MissingResult,
- InternalError,
- ProtocolError,
- InvalidTransform,
- InvalidProtocol,
- UnsupportedClientType
- }
- }
+ public enum ExceptionType
+ {
+ Unknown,
+ UnknownMethod,
+ InvalidMessageType,
+ WrongMethodName,
+ BadSequenceID,
+ MissingResult,
+ InternalError,
+ ProtocolError,
+ InvalidTransform,
+ InvalidProtocol,
+ UnsupportedClientType
+ }
+ }
}
diff --git a/lib/csharp/src/TException.cs b/lib/csharp/src/TException.cs
index a99bfa8..65509ec 100644
--- a/lib/csharp/src/TException.cs
+++ b/lib/csharp/src/TException.cs
@@ -25,16 +25,16 @@
namespace Thrift
{
- public class TException : Exception
- {
- public TException()
- {
- }
+ public class TException : Exception
+ {
+ public TException()
+ {
+ }
- public TException( string message)
- : base(message)
- {
- }
+ public TException( string message)
+ : base(message)
+ {
+ }
- }
+ }
}
diff --git a/lib/csharp/src/TProcessor.cs b/lib/csharp/src/TProcessor.cs
index dc1b795..71ce755 100644
--- a/lib/csharp/src/TProcessor.cs
+++ b/lib/csharp/src/TProcessor.cs
@@ -26,8 +26,8 @@
namespace Thrift
{
- public interface TProcessor
- {
- bool Process(TProtocol iprot, TProtocol oprot);
- }
+ public interface TProcessor
+ {
+ bool Process(TProtocol iprot, TProtocol oprot);
+ }
}
diff --git a/lib/csharp/src/Thrift.WP7.csproj b/lib/csharp/src/Thrift.WP7.csproj
index d35adf4..ee4942f 100644
--- a/lib/csharp/src/Thrift.WP7.csproj
+++ b/lib/csharp/src/Thrift.WP7.csproj
@@ -108,7 +108,7 @@
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<ProjectExtensions />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
diff --git a/lib/csharp/src/Thrift.sln b/lib/csharp/src/Thrift.sln
index ee0a3e7..dd8437d 100644
--- a/lib/csharp/src/Thrift.sln
+++ b/lib/csharp/src/Thrift.sln
@@ -4,35 +4,35 @@
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thrift", "Thrift.csproj", "{499EB63C-D74C-47E8-AE48-A2FC94538E9D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftTest", "..\test\ThriftTest\ThriftTest.csproj", "{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}"
- ProjectSection(ProjectDependencies) = postProject
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D} = {499EB63C-D74C-47E8-AE48-A2FC94538E9D}
- EndProjectSection
+ ProjectSection(ProjectDependencies) = postProject
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D} = {499EB63C-D74C-47E8-AE48-A2FC94538E9D}
+ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftMSBuildTask", "..\ThriftMSBuildTask\ThriftMSBuildTask.csproj", "{EC0A0231-66EA-4593-A792-C6CA3BB8668E}"
EndProject
Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.Build.0 = Release|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.Build.0 = Release|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(MonoDevelopProperties) = preSolution
- StartupItem = Thrift.csproj
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = Thrift.csproj
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
EndGlobal
diff --git a/lib/csharp/src/Transport/TBufferedTransport.cs b/lib/csharp/src/Transport/TBufferedTransport.cs
index 6cb0457..89b9ca7 100644
--- a/lib/csharp/src/Transport/TBufferedTransport.cs
+++ b/lib/csharp/src/Transport/TBufferedTransport.cs
@@ -23,85 +23,85 @@
namespace Thrift.Transport
{
public class TBufferedTransport : TTransport, IDisposable
- {
- private BufferedStream inputBuffer;
- private BufferedStream outputBuffer;
- private int bufSize;
- private TStreamTransport transport;
+ {
+ private BufferedStream inputBuffer;
+ private BufferedStream outputBuffer;
+ private int bufSize;
+ private TStreamTransport transport;
- public TBufferedTransport(TStreamTransport transport)
- :this(transport, 1024)
- {
+ public TBufferedTransport(TStreamTransport transport)
+ :this(transport, 1024)
+ {
- }
+ }
- public TBufferedTransport(TStreamTransport transport, int bufSize)
- {
- this.bufSize = bufSize;
- this.transport = transport;
- InitBuffers();
- }
+ public TBufferedTransport(TStreamTransport transport, int bufSize)
+ {
+ this.bufSize = bufSize;
+ this.transport = transport;
+ InitBuffers();
+ }
- private void InitBuffers()
- {
- if (transport.InputStream != null)
- {
- inputBuffer = new BufferedStream(transport.InputStream, bufSize);
- }
- if (transport.OutputStream != null)
- {
- outputBuffer = new BufferedStream(transport.OutputStream, bufSize);
- }
- }
+ private void InitBuffers()
+ {
+ if (transport.InputStream != null)
+ {
+ inputBuffer = new BufferedStream(transport.InputStream, bufSize);
+ }
+ if (transport.OutputStream != null)
+ {
+ outputBuffer = new BufferedStream(transport.OutputStream, bufSize);
+ }
+ }
- private void CloseBuffers()
- {
- if (inputBuffer != null && inputBuffer.CanRead)
- {
- inputBuffer.Close();
- }
- if (outputBuffer != null && outputBuffer.CanWrite)
- {
- outputBuffer.Close();
- }
- }
+ private void CloseBuffers()
+ {
+ if (inputBuffer != null && inputBuffer.CanRead)
+ {
+ inputBuffer.Close();
+ }
+ if (outputBuffer != null && outputBuffer.CanWrite)
+ {
+ outputBuffer.Close();
+ }
+ }
- public TTransport UnderlyingTransport
- {
- get { return transport; }
- }
+ public TTransport UnderlyingTransport
+ {
+ get { return transport; }
+ }
- public override bool IsOpen
- {
- get { return transport.IsOpen; }
- }
+ public override bool IsOpen
+ {
+ get { return transport.IsOpen; }
+ }
- public override void Open()
- {
- transport.Open();
- InitBuffers();
- }
+ public override void Open()
+ {
+ transport.Open();
+ InitBuffers();
+ }
- public override void Close()
- {
- CloseBuffers();
- transport.Close();
- }
+ public override void Close()
+ {
+ CloseBuffers();
+ transport.Close();
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- return inputBuffer.Read(buf, off, len);
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ return inputBuffer.Read(buf, off, len);
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- outputBuffer.Write(buf, off, len);
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ outputBuffer.Write(buf, off, len);
+ }
- public override void Flush()
- {
- outputBuffer.Flush();
- }
+ public override void Flush()
+ {
+ outputBuffer.Flush();
+ }
#region " IDisposable Support "
private bool _IsDisposed;
diff --git a/lib/csharp/src/Transport/TFramedTransport.cs b/lib/csharp/src/Transport/TFramedTransport.cs
index aefbc09..8af227f 100644
--- a/lib/csharp/src/Transport/TFramedTransport.cs
+++ b/lib/csharp/src/Transport/TFramedTransport.cs
@@ -20,147 +20,147 @@
using System.IO;
namespace Thrift.Transport
-{
+{
public class TFramedTransport : TTransport, IDisposable
- {
- protected TTransport transport = null;
- protected MemoryStream writeBuffer;
- protected MemoryStream readBuffer = null;
+ {
+ protected TTransport transport = null;
+ protected MemoryStream writeBuffer;
+ protected MemoryStream readBuffer = null;
- private const int header_size = 4;
- private static byte[] header_dummy = new byte[header_size]; // used as header placeholder while initilizing new write buffer
+ private const int header_size = 4;
+ private static byte[] header_dummy = new byte[header_size]; // used as header placeholder while initilizing new write buffer
- public class Factory : TTransportFactory
- {
- public override TTransport GetTransport(TTransport trans)
- {
- return new TFramedTransport(trans);
- }
- }
+ public class Factory : TTransportFactory
+ {
+ public override TTransport GetTransport(TTransport trans)
+ {
+ return new TFramedTransport(trans);
+ }
+ }
- protected TFramedTransport()
- {
- InitWriteBuffer();
- }
+ protected TFramedTransport()
+ {
+ InitWriteBuffer();
+ }
- public TFramedTransport(TTransport transport) : this()
- {
- this.transport = transport;
- }
+ public TFramedTransport(TTransport transport) : this()
+ {
+ this.transport = transport;
+ }
- public override void Open()
- {
- transport.Open();
- }
+ public override void Open()
+ {
+ transport.Open();
+ }
- public override bool IsOpen
- {
- get
- {
- return transport.IsOpen;
- }
- }
+ public override bool IsOpen
+ {
+ get
+ {
+ return transport.IsOpen;
+ }
+ }
- public override void Close()
- {
- transport.Close();
- }
+ public override void Close()
+ {
+ transport.Close();
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- if (readBuffer != null)
- {
- int got = readBuffer.Read(buf, off, len);
- if (got > 0)
- {
- return got;
- }
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (readBuffer != null)
+ {
+ int got = readBuffer.Read(buf, off, len);
+ if (got > 0)
+ {
+ return got;
+ }
+ }
- // Read another frame of data
- ReadFrame();
+ // Read another frame of data
+ ReadFrame();
- return readBuffer.Read(buf, off, len);
- }
+ return readBuffer.Read(buf, off, len);
+ }
- private void ReadFrame()
- {
- byte[] i32rd = new byte[header_size];
- transport.ReadAll(i32rd, 0, header_size);
- int size = DecodeFrameSize(i32rd);
+ private void ReadFrame()
+ {
+ byte[] i32rd = new byte[header_size];
+ transport.ReadAll(i32rd, 0, header_size);
+ int size = DecodeFrameSize(i32rd);
- byte[] buff = new byte[size];
- transport.ReadAll(buff, 0, size);
- readBuffer = new MemoryStream(buff);
- }
+ byte[] buff = new byte[size];
+ transport.ReadAll(buff, 0, size);
+ readBuffer = new MemoryStream(buff);
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- writeBuffer.Write(buf, off, len);
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ writeBuffer.Write(buf, off, len);
+ }
- public override void Flush()
- {
- byte[] buf = writeBuffer.GetBuffer();
- int len = (int)writeBuffer.Length;
- int data_len = len - header_size;
- if ( data_len < 0 )
- throw new System.InvalidOperationException (); // logic error actually
+ public override void Flush()
+ {
+ byte[] buf = writeBuffer.GetBuffer();
+ int len = (int)writeBuffer.Length;
+ int data_len = len - header_size;
+ if ( data_len < 0 )
+ throw new System.InvalidOperationException (); // logic error actually
- InitWriteBuffer();
+ InitWriteBuffer();
- // Inject message header into the reserved buffer space
- EncodeFrameSize(data_len,ref buf);
+ // Inject message header into the reserved buffer space
+ EncodeFrameSize(data_len,ref buf);
- // Send the entire message at once
- transport.Write(buf, 0, len);
+ // Send the entire message at once
+ transport.Write(buf, 0, len);
- transport.Flush();
- }
+ transport.Flush();
+ }
- private void InitWriteBuffer ()
- {
- // Create new buffer instance
- writeBuffer = new MemoryStream(1024);
+ private void InitWriteBuffer ()
+ {
+ // Create new buffer instance
+ writeBuffer = new MemoryStream(1024);
- // Reserve space for message header to be put right before sending it out
- writeBuffer.Write ( header_dummy, 0, header_size );
- }
-
- 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));
- }
+ // Reserve space for message header to be put right before sending it out
+ writeBuffer.Write ( header_dummy, 0, header_size );
+ }
+
+ 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
- }
+ #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/THttpClient.cs b/lib/csharp/src/Transport/THttpClient.cs
index 1581e83..a56a3e8 100644
--- a/lib/csharp/src/Transport/THttpClient.cs
+++ b/lib/csharp/src/Transport/THttpClient.cs
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -15,8 +15,8 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
- *
+ *
+ *
*/
using System;
@@ -48,40 +48,40 @@
private IWebProxy proxy = WebRequest.DefaultWebProxy;
#endif
- public THttpClient(Uri u)
+ public THttpClient(Uri u)
: this(u, Enumerable.Empty<X509Certificate>())
- {
- }
+ {
+ }
- public THttpClient(Uri u, IEnumerable<X509Certificate> certificates)
- {
- uri = u;
+ public THttpClient(Uri u, IEnumerable<X509Certificate> certificates)
+ {
+ uri = u;
this.certificates = (certificates ?? Enumerable.Empty<X509Certificate>()).ToArray();
- }
+ }
public int ConnectTimeout
- {
- set
- {
- connectTimeout = value;
- }
- }
+ {
+ set
+ {
+ connectTimeout = value;
+ }
+ }
- public int ReadTimeout
- {
- set
- {
- readTimeout = value;
- }
- }
+ public int ReadTimeout
+ {
+ set
+ {
+ readTimeout = value;
+ }
+ }
- public IDictionary<String, String> CustomHeaders
- {
- get
- {
- return customHeaders;
- }
- }
+ public IDictionary<String, String> CustomHeaders
+ {
+ get
+ {
+ return customHeaders;
+ }
+ }
#if !SILVERLIGHT
public IWebProxy Proxy
@@ -93,162 +93,162 @@
}
#endif
- public override bool IsOpen
- {
- get
- {
- return true;
- }
- }
+ public override bool IsOpen
+ {
+ get
+ {
+ return true;
+ }
+ }
- public override void Open()
- {
- }
+ public override void Open()
+ {
+ }
- public override void Close()
- {
- if (inputStream != null)
- {
- inputStream.Close();
- inputStream = null;
- }
- if (outputStream != null)
- {
- outputStream.Close();
- outputStream = null;
- }
- }
+ public override void Close()
+ {
+ if (inputStream != null)
+ {
+ inputStream.Close();
+ inputStream = null;
+ }
+ if (outputStream != null)
+ {
+ outputStream.Close();
+ outputStream = null;
+ }
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- if (inputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No request has been sent");
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (inputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No request has been sent");
+ }
- try
- {
- int ret = inputStream.Read(buf, off, len);
+ try
+ {
+ int ret = inputStream.Read(buf, off, len);
- if (ret == -1)
- {
- throw new TTransportException(TTransportException.ExceptionType.EndOfFile, "No more data available");
- }
+ if (ret == -1)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.EndOfFile, "No more data available");
+ }
- return ret;
- }
- catch (IOException iox)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
- }
- }
+ return ret;
+ }
+ catch (IOException iox)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
+ }
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- outputStream.Write(buf, off, len);
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ outputStream.Write(buf, off, len);
+ }
#if !SILVERLIGHT
- public override void Flush()
- {
- try
- {
- SendRequest();
- }
- finally
- {
- outputStream = new MemoryStream();
- }
- }
+ public override void Flush()
+ {
+ try
+ {
+ SendRequest();
+ }
+ finally
+ {
+ outputStream = new MemoryStream();
+ }
+ }
- private void SendRequest()
- {
- try
- {
- HttpWebRequest connection = CreateRequest();
+ private void SendRequest()
+ {
+ try
+ {
+ HttpWebRequest connection = CreateRequest();
- byte[] data = outputStream.ToArray();
- connection.ContentLength = data.Length;
+ byte[] data = outputStream.ToArray();
+ connection.ContentLength = data.Length;
- using (Stream requestStream = connection.GetRequestStream())
- {
- requestStream.Write(data, 0, data.Length);
+ using (Stream requestStream = connection.GetRequestStream())
+ {
+ requestStream.Write(data, 0, data.Length);
- // Resolve HTTP hang that can happens after successive calls by making sure
- // that we release the response and response stream. To support this, we copy
- // the response to a memory stream.
- using (var response = connection.GetResponse())
- {
- using (var responseStream = response.GetResponseStream())
- {
- // Copy the response to a memory stream so that we can
- // cleanly close the response and response stream.
- inputStream = new MemoryStream();
- byte[] buffer = new byte[8096];
- int bytesRead;
- while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
- {
- inputStream.Write (buffer, 0, bytesRead);
- }
- inputStream.Seek(0, 0);
- }
- }
- }
- }
- catch (IOException iox)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
- }
- catch (WebException wx)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx);
- }
- }
+ // Resolve HTTP hang that can happens after successive calls by making sure
+ // that we release the response and response stream. To support this, we copy
+ // the response to a memory stream.
+ using (var response = connection.GetResponse())
+ {
+ using (var responseStream = response.GetResponseStream())
+ {
+ // Copy the response to a memory stream so that we can
+ // cleanly close the response and response stream.
+ inputStream = new MemoryStream();
+ byte[] buffer = new byte[8096];
+ int bytesRead;
+ while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ inputStream.Write (buffer, 0, bytesRead);
+ }
+ inputStream.Seek(0, 0);
+ }
+ }
+ }
+ }
+ catch (IOException iox)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
+ }
+ catch (WebException wx)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx);
+ }
+ }
#endif
- private HttpWebRequest CreateRequest()
- {
- HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(uri);
+ private HttpWebRequest CreateRequest()
+ {
+ HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(uri);
#if !SILVERLIGHT
- // Adding certificates through code is not supported with WP7 Silverlight
- // see "Windows Phone 7 and Certificates_FINAL_121610.pdf"
- connection.ClientCertificates.AddRange(certificates);
+ // Adding certificates through code is not supported with WP7 Silverlight
+ // see "Windows Phone 7 and Certificates_FINAL_121610.pdf"
+ connection.ClientCertificates.AddRange(certificates);
- if (connectTimeout > 0)
- {
- connection.Timeout = connectTimeout;
- }
- if (readTimeout > 0)
- {
- connection.ReadWriteTimeout = readTimeout;
- }
+ if (connectTimeout > 0)
+ {
+ connection.Timeout = connectTimeout;
+ }
+ if (readTimeout > 0)
+ {
+ connection.ReadWriteTimeout = readTimeout;
+ }
#endif
- // Make the request
- connection.ContentType = "application/x-thrift";
- connection.Accept = "application/x-thrift";
- connection.UserAgent = "C#/THttpClient";
- connection.Method = "POST";
+ // Make the request
+ connection.ContentType = "application/x-thrift";
+ connection.Accept = "application/x-thrift";
+ connection.UserAgent = "C#/THttpClient";
+ connection.Method = "POST";
#if !SILVERLIGHT
- connection.ProtocolVersion = HttpVersion.Version10;
+ connection.ProtocolVersion = HttpVersion.Version10;
#endif
//add custom headers here
- foreach (KeyValuePair<string, string> item in customHeaders)
- {
+ foreach (KeyValuePair<string, string> item in customHeaders)
+ {
#if !SILVERLIGHT
- connection.Headers.Add(item.Key, item.Value);
+ connection.Headers.Add(item.Key, item.Value);
#else
connection.Headers[item.Key] = item.Value;
#endif
- }
+ }
#if !SILVERLIGHT
connection.Proxy = proxy;
#endif
return connection;
- }
+ }
public override IAsyncResult BeginFlush(AsyncCallback callback, object state)
{
@@ -388,12 +388,12 @@
}
internal void UpdateStatusToComplete()
{
- _isCompleted = true; //1. set _iscompleted to true
+ _isCompleted = true; //1. set _iscompleted to true
lock (_locker)
{
if (_evt != null)
{
- _evt.Set(); //2. set the event, when it exists
+ _evt.Set(); //2. set the event, when it exists
}
}
}
@@ -408,23 +408,23 @@
}
#region " IDisposable Support "
- private bool _IsDisposed;
+ private bool _IsDisposed;
- // IDisposable
- protected override void Dispose(bool disposing)
- {
- if (!_IsDisposed)
- {
- if (disposing)
- {
- if (inputStream != null)
- inputStream.Dispose();
- if (outputStream != null)
- outputStream.Dispose();
- }
- }
- _IsDisposed = true;
- }
+ // IDisposable
+ protected override void Dispose(bool disposing)
+ {
+ if (!_IsDisposed)
+ {
+ if (disposing)
+ {
+ if (inputStream != null)
+ inputStream.Dispose();
+ if (outputStream != null)
+ outputStream.Dispose();
+ }
+ }
+ _IsDisposed = true;
+ }
#endregion
- }
+ }
}
diff --git a/lib/csharp/src/Transport/THttpHandler.cs b/lib/csharp/src/Transport/THttpHandler.cs
index 884f1ad..4115ef9 100644
--- a/lib/csharp/src/Transport/THttpHandler.cs
+++ b/lib/csharp/src/Transport/THttpHandler.cs
@@ -1,11 +1,23 @@
-//
-// THttpHandler.cs
-//
-// Authors:
-// Fredrik Hedberg <fhedberg@availo.com>
-//
-// Distributed under the Apache Public License
-//
+/**
+ * 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.
+ *
+ *
+ */
using System;
using System.Web;
@@ -31,7 +43,7 @@
{
}
-
+
public THttpHandler(TProcessor processor, TProtocolFactory protocolFactory)
: this(processor, protocolFactory, protocolFactory)
{
diff --git a/lib/csharp/src/Transport/TMemoryBuffer.cs b/lib/csharp/src/Transport/TMemoryBuffer.cs
index ca31fee..d8ff9dc 100644
--- a/lib/csharp/src/Transport/TMemoryBuffer.cs
+++ b/lib/csharp/src/Transport/TMemoryBuffer.cs
@@ -23,77 +23,77 @@
using Thrift.Protocol;
namespace Thrift.Transport {
- public class TMemoryBuffer : TTransport {
+ public class TMemoryBuffer : TTransport {
- private readonly MemoryStream byteStream;
+ private readonly MemoryStream byteStream;
- public TMemoryBuffer() {
- byteStream = new MemoryStream();
- }
+ public TMemoryBuffer() {
+ byteStream = new MemoryStream();
+ }
- public TMemoryBuffer(byte[] buf) {
- byteStream = new MemoryStream(buf);
- }
+ public TMemoryBuffer(byte[] buf) {
+ byteStream = new MemoryStream(buf);
+ }
- public override void Open() {
- /** do nothing **/
- }
+ public override void Open() {
+ /** do nothing **/
+ }
- public override void Close() {
- /** do nothing **/
- }
+ public override void Close() {
+ /** do nothing **/
+ }
- public override int Read(byte[] buf, int off, int len) {
- return byteStream.Read(buf, off, len);
- }
+ public override int Read(byte[] buf, int off, int len) {
+ return byteStream.Read(buf, off, len);
+ }
- public override void Write(byte[] buf, int off, int len) {
- byteStream.Write(buf, off, len);
- }
+ public override void Write(byte[] buf, int off, int len) {
+ byteStream.Write(buf, off, len);
+ }
- public byte[] GetBuffer() {
- return byteStream.ToArray();
- }
+ public byte[] GetBuffer() {
+ return byteStream.ToArray();
+ }
- public override bool IsOpen {
- get { return true; }
- }
+ public override bool IsOpen {
+ get { return true; }
+ }
- public static byte[] Serialize(TAbstractBase s) {
- var t = new TMemoryBuffer();
- var p = new TBinaryProtocol(t);
+ public static byte[] Serialize(TAbstractBase s) {
+ var t = new TMemoryBuffer();
+ var p = new TBinaryProtocol(t);
- s.Write(p);
+ s.Write(p);
- return t.GetBuffer();
- }
+ return t.GetBuffer();
+ }
- 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});
- }
- }
+ 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;
+ private bool _IsDisposed;
- // IDisposable
- protected override void Dispose(bool disposing) {
- if (!_IsDisposed) {
- if (disposing) {
- if (byteStream != null)
- byteStream.Dispose();
- }
- }
- _IsDisposed = true;
- }
- }
+ // IDisposable
+ protected override void Dispose(bool disposing) {
+ if (!_IsDisposed) {
+ if (disposing) {
+ if (byteStream != null)
+ byteStream.Dispose();
+ }
+ }
+ _IsDisposed = true;
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/csharp/src/Transport/TNamedPipeClientTransport.cs b/lib/csharp/src/Transport/TNamedPipeClientTransport.cs
index 7dafdd6..9faa6e7 100644
--- a/lib/csharp/src/Transport/TNamedPipeClientTransport.cs
+++ b/lib/csharp/src/Transport/TNamedPipeClientTransport.cs
@@ -25,71 +25,71 @@
namespace Thrift.Transport
{
- public class TNamedPipeClientTransport : TTransport
- {
- private NamedPipeClientStream client;
- private string ServerName;
- private string PipeName;
+ public class TNamedPipeClientTransport : TTransport
+ {
+ private NamedPipeClientStream client;
+ private string ServerName;
+ private string PipeName;
- public TNamedPipeClientTransport(string pipe)
- {
- ServerName = ".";
- PipeName = pipe;
- }
+ public TNamedPipeClientTransport(string pipe)
+ {
+ ServerName = ".";
+ PipeName = pipe;
+ }
- public TNamedPipeClientTransport(string server, string pipe)
- {
- ServerName = (server != "") ? server : ".";
- PipeName = pipe;
- }
+ public TNamedPipeClientTransport(string server, string pipe)
+ {
+ ServerName = (server != "") ? server : ".";
+ PipeName = pipe;
+ }
- public override bool IsOpen
- {
- get { return client != null && client.IsConnected; }
- }
+ public override bool IsOpen
+ {
+ get { return client != null && client.IsConnected; }
+ }
- public override void Open()
- {
- if (IsOpen)
- {
- throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen);
- }
- client = new NamedPipeClientStream(ServerName, PipeName, PipeDirection.InOut, PipeOptions.None);
- client.Connect();
- }
+ public override void Open()
+ {
+ if (IsOpen)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen);
+ }
+ client = new NamedPipeClientStream(ServerName, PipeName, PipeDirection.InOut, PipeOptions.None);
+ client.Connect();
+ }
- public override void Close()
- {
- if (client != null)
- {
- client.Close();
- client = null;
- }
- }
+ public override void Close()
+ {
+ if (client != null)
+ {
+ client.Close();
+ client = null;
+ }
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- if (client == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (client == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
- return client.Read(buf, off, len);
- }
+ return client.Read(buf, off, len);
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- if (client == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ if (client == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
- client.Write(buf, off, len);
- }
+ client.Write(buf, off, len);
+ }
- protected override void Dispose(bool disposing)
- {
- client.Dispose();
- }
- }
+ protected override void Dispose(bool disposing)
+ {
+ client.Dispose();
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
index 815af19..b3f34eb 100644
--- a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
+++ b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
@@ -27,110 +27,110 @@
namespace Thrift.Transport
{
- public class TNamedPipeServerTransport : TServerTransport
- {
- /// <summary>
- /// This is the address of the Pipe on the localhost.
- /// </summary>
- private readonly string pipeAddress;
- NamedPipeServerStream stream = null;
+ public class TNamedPipeServerTransport : TServerTransport
+ {
+ /// <summary>
+ /// This is the address of the Pipe on the localhost.
+ /// </summary>
+ private readonly string pipeAddress;
+ NamedPipeServerStream stream = null;
- public TNamedPipeServerTransport(string pipeAddress)
- {
- this.pipeAddress = pipeAddress;
- }
+ public TNamedPipeServerTransport(string pipeAddress)
+ {
+ this.pipeAddress = pipeAddress;
+ }
- public override void Listen()
- {
- // nothing to do here
- }
+ public override void Listen()
+ {
+ // nothing to do here
+ }
- public override void Close()
- {
- if (stream != null)
- {
- try
- {
- stream.Close();
- stream.Dispose();
- }
- finally
- {
- stream = null;
- }
- }
- }
+ public override void Close()
+ {
+ if (stream != null)
+ {
+ try
+ {
+ stream.Close();
+ stream.Dispose();
+ }
+ finally
+ {
+ stream = null;
+ }
+ }
+ }
- private void EnsurePipeInstance()
- {
- if( stream == null)
- stream = new NamedPipeServerStream(
- pipeAddress, PipeDirection.InOut, 254,
- PipeTransmissionMode.Byte,
- PipeOptions.None, 4096, 4096 /*TODO: security*/);
- }
+ private void EnsurePipeInstance()
+ {
+ if( stream == null)
+ stream = new NamedPipeServerStream(
+ pipeAddress, PipeDirection.InOut, 254,
+ PipeTransmissionMode.Byte,
+ PipeOptions.None, 4096, 4096 /*TODO: security*/);
+ }
- protected override TTransport AcceptImpl()
- {
- try
- {
- EnsurePipeInstance();
- stream.WaitForConnection();
- var trans = new ServerTransport(stream);
- stream = null; // pass ownership to ServerTransport
- return trans;
- }
- catch (Exception e)
- {
- Close();
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message);
- }
- }
+ protected override TTransport AcceptImpl()
+ {
+ try
+ {
+ EnsurePipeInstance();
+ stream.WaitForConnection();
+ var trans = new ServerTransport(stream);
+ stream = null; // pass ownership to ServerTransport
+ return trans;
+ }
+ catch (Exception e)
+ {
+ Close();
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message);
+ }
+ }
- private class ServerTransport : TTransport
- {
- private NamedPipeServerStream server;
- public ServerTransport(NamedPipeServerStream server)
- {
- this.server = server;
- }
+ private class ServerTransport : TTransport
+ {
+ private NamedPipeServerStream server;
+ public ServerTransport(NamedPipeServerStream server)
+ {
+ this.server = server;
+ }
- public override bool IsOpen
- {
- get { return server != null && server.IsConnected; }
- }
+ public override bool IsOpen
+ {
+ get { return server != null && server.IsConnected; }
+ }
- public override void Open()
- {
- }
+ public override void Open()
+ {
+ }
- public override void Close()
- {
- if (server != null) server.Close();
- }
+ public override void Close()
+ {
+ if (server != null) server.Close();
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- if (server == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
- return server.Read(buf, off, len);
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (server == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
+ return server.Read(buf, off, len);
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- if (server == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
- server.Write(buf, off, len);
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ if (server == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
+ server.Write(buf, off, len);
+ }
- protected override void Dispose(bool disposing)
- {
- server.Dispose();
- }
- }
- }
+ protected override void Dispose(bool disposing)
+ {
+ server.Dispose();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/lib/csharp/src/Transport/TServerSocket.cs b/lib/csharp/src/Transport/TServerSocket.cs
index eefa4f9..82a367c 100644
--- a/lib/csharp/src/Transport/TServerSocket.cs
+++ b/lib/csharp/src/Transport/TServerSocket.cs
@@ -27,94 +27,94 @@
namespace Thrift.Transport
{
- public class TServerSocket : TServerTransport
- {
- /**
- * Underlying server with socket
- */
- private TcpListener server = null;
+ public class TServerSocket : TServerTransport
+ {
+ /**
+ * Underlying server with socket
+ */
+ private TcpListener server = null;
- /**
- * Port to listen on
- */
- private int port = 0;
+ /**
+ * Port to listen on
+ */
+ private int port = 0;
- /**
- * Timeout for client sockets from accept
- */
- private int clientTimeout = 0;
+ /**
+ * Timeout for client sockets from accept
+ */
+ private int clientTimeout = 0;
- /**
- * Whether or not to wrap new TSocket connections in buffers
- */
- private bool useBufferedSockets = false;
+ /**
+ * Whether or not to wrap new TSocket connections in buffers
+ */
+ private bool useBufferedSockets = false;
- /**
- * Creates a server socket from underlying socket object
- */
- public TServerSocket(TcpListener listener)
- :this(listener, 0)
- {
- }
+ /**
+ * Creates a server socket from underlying socket object
+ */
+ public TServerSocket(TcpListener listener)
+ :this(listener, 0)
+ {
+ }
- /**
- * Creates a server socket from underlying socket object
- */
- public TServerSocket(TcpListener listener, int clientTimeout)
- {
- this.server = listener;
- this.clientTimeout = clientTimeout;
- }
+ /**
+ * Creates a server socket from underlying socket object
+ */
+ public TServerSocket(TcpListener listener, int clientTimeout)
+ {
+ this.server = listener;
+ this.clientTimeout = clientTimeout;
+ }
- /**
- * Creates just a port listening server socket
- */
- public TServerSocket(int port)
- : this(port, 0)
- {
- }
+ /**
+ * Creates just a port listening server socket
+ */
+ public TServerSocket(int port)
+ : this(port, 0)
+ {
+ }
- /**
- * Creates just a port listening server socket
- */
- public TServerSocket(int port, int clientTimeout)
- :this(port, clientTimeout, false)
- {
- }
+ /**
+ * Creates just a port listening server socket
+ */
+ public TServerSocket(int port, int clientTimeout)
+ :this(port, clientTimeout, false)
+ {
+ }
- public TServerSocket(int port, int clientTimeout, bool useBufferedSockets)
- {
- this.port = port;
- this.clientTimeout = clientTimeout;
- this.useBufferedSockets = useBufferedSockets;
- try
- {
- // Make server socket
- server = new TcpListener(System.Net.IPAddress.Any, this.port);
- server.Server.NoDelay = true;
- }
- catch (Exception)
- {
- server = null;
- throw new TTransportException("Could not create ServerSocket on port " + port + ".");
- }
- }
+ public TServerSocket(int port, int clientTimeout, bool useBufferedSockets)
+ {
+ this.port = port;
+ this.clientTimeout = clientTimeout;
+ this.useBufferedSockets = useBufferedSockets;
+ try
+ {
+ // Make server socket
+ server = new TcpListener(System.Net.IPAddress.Any, this.port);
+ server.Server.NoDelay = true;
+ }
+ catch (Exception)
+ {
+ server = null;
+ throw new TTransportException("Could not create ServerSocket on port " + port + ".");
+ }
+ }
- public override void Listen()
- {
- // Make sure not to block on accept
- if (server != null)
- {
- try
- {
- server.Start();
- }
- catch (SocketException sx)
- {
- throw new TTransportException("Could not accept on listening socket: " + sx.Message);
- }
- }
- }
+ public override void Listen()
+ {
+ // Make sure not to block on accept
+ if (server != null)
+ {
+ try
+ {
+ server.Start();
+ }
+ catch (SocketException sx)
+ {
+ throw new TTransportException("Could not accept on listening socket: " + sx.Message);
+ }
+ }
+ }
protected override TTransport AcceptImpl()
{
@@ -142,7 +142,7 @@
}
catch (System.Exception)
{
- // If a TSocket was successfully created, then let
+ // If a TSocket was successfully created, then let
// it do proper cleanup of the TcpClient object.
if (result2 != null)
result2.Dispose();
@@ -158,19 +158,19 @@
}
public override void Close()
- {
- if (server != null)
- {
- try
- {
- server.Stop();
- }
- catch (Exception ex)
- {
- throw new TTransportException("WARNING: Could not close server socket: " + ex);
- }
- server = null;
- }
- }
- }
+ {
+ if (server != null)
+ {
+ try
+ {
+ server.Stop();
+ }
+ catch (Exception ex)
+ {
+ throw new TTransportException("WARNING: Could not close server socket: " + ex);
+ }
+ server = null;
+ }
+ }
+ }
}
diff --git a/lib/csharp/src/Transport/TServerTransport.cs b/lib/csharp/src/Transport/TServerTransport.cs
index c99d07f..05d7d0f 100644
--- a/lib/csharp/src/Transport/TServerTransport.cs
+++ b/lib/csharp/src/Transport/TServerTransport.cs
@@ -25,19 +25,19 @@
namespace Thrift.Transport
{
- public abstract class TServerTransport
- {
- public abstract void Listen();
- public abstract void Close();
- protected abstract TTransport AcceptImpl();
+ public abstract class TServerTransport
+ {
+ public abstract void Listen();
+ public abstract void Close();
+ protected abstract TTransport AcceptImpl();
- public TTransport Accept()
- {
- TTransport transport = AcceptImpl();
- if (transport == null) {
- throw new TTransportException("accept() may not return NULL");
- }
- return transport;
- }
- }
+ public TTransport Accept()
+ {
+ TTransport transport = AcceptImpl();
+ if (transport == null) {
+ throw new TTransportException("accept() may not return NULL");
+ }
+ return transport;
+ }
+ }
}
diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs
index 35fbe97..cf1a440 100644
--- a/lib/csharp/src/Transport/TSocket.cs
+++ b/lib/csharp/src/Transport/TSocket.cs
@@ -26,118 +26,118 @@
namespace Thrift.Transport
{
- public class TSocket : TStreamTransport
- {
- private TcpClient client = null;
- private string host = null;
- private int port = 0;
- private int timeout = 0;
+ public class TSocket : TStreamTransport
+ {
+ private TcpClient client = null;
+ private string host = null;
+ private int port = 0;
+ private int timeout = 0;
- public TSocket(TcpClient client)
- {
- this.client = client;
+ public TSocket(TcpClient client)
+ {
+ this.client = client;
- if (IsOpen)
- {
- inputStream = client.GetStream();
- outputStream = client.GetStream();
- }
- }
+ if (IsOpen)
+ {
+ inputStream = client.GetStream();
+ outputStream = client.GetStream();
+ }
+ }
- public TSocket(string host, int port)
- : this(host, port, 0)
- {
- }
+ public TSocket(string host, int port)
+ : this(host, port, 0)
+ {
+ }
- public TSocket(string host, int port, int timeout)
- {
- this.host = host;
- this.port = port;
- this.timeout = timeout;
+ public TSocket(string host, int port, int timeout)
+ {
+ this.host = host;
+ this.port = port;
+ this.timeout = timeout;
- InitSocket();
- }
+ InitSocket();
+ }
- private void InitSocket()
- {
- client = new TcpClient();
- client.ReceiveTimeout = client.SendTimeout = timeout;
- client.Client.NoDelay = true;
- }
+ private void InitSocket()
+ {
+ client = new TcpClient();
+ client.ReceiveTimeout = client.SendTimeout = timeout;
+ client.Client.NoDelay = true;
+ }
- public int Timeout
- {
- set
- {
- client.ReceiveTimeout = client.SendTimeout = timeout = value;
- }
- }
+ public int Timeout
+ {
+ set
+ {
+ client.ReceiveTimeout = client.SendTimeout = timeout = value;
+ }
+ }
- public TcpClient TcpClient
- {
- get
- {
- return client;
- }
- }
+ public TcpClient TcpClient
+ {
+ get
+ {
+ return client;
+ }
+ }
- public string Host
- {
- get
- {
- return host;
- }
- }
+ public string Host
+ {
+ get
+ {
+ return host;
+ }
+ }
- public int Port
- {
- get
- {
- return port;
- }
- }
+ public int Port
+ {
+ get
+ {
+ return port;
+ }
+ }
- public override bool IsOpen
- {
- get
- {
- if (client == null)
- {
- return false;
- }
+ public override bool IsOpen
+ {
+ get
+ {
+ if (client == null)
+ {
+ return false;
+ }
- return client.Connected;
- }
- }
+ return client.Connected;
+ }
+ }
- public override void Open()
- {
- if (IsOpen)
- {
- throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
- }
+ public override void Open()
+ {
+ if (IsOpen)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
+ }
- if (String.IsNullOrEmpty(host))
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
- }
+ if (String.IsNullOrEmpty(host))
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
+ }
- if (port <= 0)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
- }
+ if (port <= 0)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
+ }
- if (client == null)
- {
- InitSocket();
- }
+ if (client == null)
+ {
+ InitSocket();
+ }
- if( timeout == 0) // no timeout -> infinite
- {
- client.Connect(host, port);
- }
- else // we have a timeout -> use it
- {
+ if( timeout == 0) // no timeout -> infinite
+ {
+ client.Connect(host, port);
+ }
+ else // we have a timeout -> use it
+ {
ConnectHelper hlp = new ConnectHelper(client);
IAsyncResult asyncres = client.BeginConnect(host, port, new AsyncCallback(ConnectCallback), hlp);
bool bConnected = asyncres.AsyncWaitHandle.WaitOne(timeout) && client.Connected;
@@ -158,11 +158,11 @@
}
throw new TTransportException(TTransportException.ExceptionType.TimedOut, "Connect timed out");
}
- }
+ }
- inputStream = client.GetStream();
- outputStream = client.GetStream();
- }
+ inputStream = client.GetStream();
+ outputStream = client.GetStream();
+ }
static void ConnectCallback(IAsyncResult asyncres)
@@ -171,7 +171,7 @@
lock (hlp.Mutex)
{
hlp.CallbackDone = true;
-
+
try
{
if( hlp.Client.Client != null)
@@ -182,16 +182,16 @@
// catch that away
}
- if (hlp.DoCleanup)
+ if (hlp.DoCleanup)
{
- try {
- asyncres.AsyncWaitHandle.Close();
- } catch (Exception) {}
-
- try {
- if (hlp.Client is IDisposable)
- ((IDisposable)hlp.Client).Dispose();
- } catch (Exception) {}
+ try {
+ asyncres.AsyncWaitHandle.Close();
+ } catch (Exception) {}
+
+ try {
+ if (hlp.Client is IDisposable)
+ ((IDisposable)hlp.Client).Dispose();
+ } catch (Exception) {}
hlp.Client = null;
}
}
@@ -209,15 +209,15 @@
}
}
- public override void Close()
- {
- base.Close();
- if (client != null)
- {
- client.Close();
- client = null;
- }
- }
+ public override void Close()
+ {
+ base.Close();
+ if (client != null)
+ {
+ client.Close();
+ client = null;
+ }
+ }
#region " IDisposable Support "
private bool _IsDisposed;
diff --git a/lib/csharp/src/Transport/TStreamTransport.cs b/lib/csharp/src/Transport/TStreamTransport.cs
index eb1d2cc..468743c 100644
--- a/lib/csharp/src/Transport/TStreamTransport.cs
+++ b/lib/csharp/src/Transport/TStreamTransport.cs
@@ -26,83 +26,83 @@
namespace Thrift.Transport
{
- public class TStreamTransport : TTransport
- {
- protected Stream inputStream;
- protected Stream outputStream;
+ public class TStreamTransport : TTransport
+ {
+ protected Stream inputStream;
+ protected Stream outputStream;
- protected TStreamTransport()
- {
- }
+ protected TStreamTransport()
+ {
+ }
- public TStreamTransport(Stream inputStream, Stream outputStream)
- {
- this.inputStream = inputStream;
- this.outputStream = outputStream;
- }
+ public TStreamTransport(Stream inputStream, Stream outputStream)
+ {
+ this.inputStream = inputStream;
+ this.outputStream = outputStream;
+ }
- public Stream OutputStream
- {
- get { return outputStream; }
- }
+ public Stream OutputStream
+ {
+ get { return outputStream; }
+ }
- public Stream InputStream
- {
- get { return inputStream; }
- }
+ public Stream InputStream
+ {
+ get { return inputStream; }
+ }
- public override bool IsOpen
- {
- get { return true; }
- }
+ public override bool IsOpen
+ {
+ get { return true; }
+ }
- public override void Open()
- {
- }
+ public override void Open()
+ {
+ }
- public override void Close()
- {
- if (inputStream != null)
- {
- inputStream.Close();
- inputStream = null;
- }
- if (outputStream != null)
- {
- outputStream.Close();
- outputStream = null;
- }
- }
+ public override void Close()
+ {
+ if (inputStream != null)
+ {
+ inputStream.Close();
+ inputStream = null;
+ }
+ if (outputStream != null)
+ {
+ outputStream.Close();
+ outputStream = null;
+ }
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- if (inputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot read from null inputstream");
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (inputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot read from null inputstream");
+ }
- return inputStream.Read(buf, off, len);
- }
+ return inputStream.Read(buf, off, len);
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- if (outputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot write to null outputstream");
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ if (outputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot write to null outputstream");
+ }
- outputStream.Write(buf, off, len);
- }
+ outputStream.Write(buf, off, len);
+ }
- public override void Flush()
- {
- if (outputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot flush null outputstream");
- }
+ public override void Flush()
+ {
+ if (outputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot flush null outputstream");
+ }
- outputStream.Flush();
- }
+ outputStream.Flush();
+ }
#region " IDisposable Support "
diff --git a/lib/csharp/src/Transport/TTLSServerSocket.cs b/lib/csharp/src/Transport/TTLSServerSocket.cs
index 948b1d7..9753d47 100644
--- a/lib/csharp/src/Transport/TTLSServerSocket.cs
+++ b/lib/csharp/src/Transport/TTLSServerSocket.cs
@@ -23,164 +23,164 @@
namespace Thrift.Transport
{
- /// <summary>
- /// SSL Server Socket Wrapper Class
- /// </summary>
- public class TTLSServerSocket : TServerTransport
- {
- /// <summary>
- /// Underlying tcp server
- /// </summary>
- private TcpListener server = null;
+ /// <summary>
+ /// SSL Server Socket Wrapper Class
+ /// </summary>
+ public class TTLSServerSocket : TServerTransport
+ {
+ /// <summary>
+ /// Underlying tcp server
+ /// </summary>
+ private TcpListener server = null;
- /// <summary>
- /// The port where the socket listen
- /// </summary>
- private int port = 0;
+ /// <summary>
+ /// The port where the socket listen
+ /// </summary>
+ private int port = 0;
- /// <summary>
- /// Timeout for the created server socket
- /// </summary>
- private int clientTimeout = 0;
+ /// <summary>
+ /// Timeout for the created server socket
+ /// </summary>
+ private int clientTimeout = 0;
- /// <summary>
- /// Whether or not to wrap new TSocket connections in buffers
- /// </summary>
- private bool useBufferedSockets = false;
+ /// <summary>
+ /// Whether or not to wrap new TSocket connections in buffers
+ /// </summary>
+ private bool useBufferedSockets = false;
- /// <summary>
- /// The servercertificate with the private- and public-key
- /// </summary>
- private X509Certificate serverCertificate;
+ /// <summary>
+ /// The servercertificate with the private- and public-key
+ /// </summary>
+ private X509Certificate serverCertificate;
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
- /// </summary>
- /// <param name="port">The port where the server runs.</param>
- /// <param name="certificate">The certificate object.</param>
- public TTLSServerSocket(int port, X509Certificate2 certificate)
- : this(port, 0, certificate)
- {
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
+ /// </summary>
+ /// <param name="port">The port where the server runs.</param>
+ /// <param name="certificate">The certificate object.</param>
+ public TTLSServerSocket(int port, X509Certificate2 certificate)
+ : this(port, 0, certificate)
+ {
+ }
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
- /// </summary>
- /// <param name="port">The port where the server runs.</param>
- /// <param name="clientTimeout">Send/receive timeout.</param>
- /// <param name="certificate">The certificate object.</param>
- public TTLSServerSocket(int port, int clientTimeout, X509Certificate2 certificate)
- : this(port, clientTimeout, false, certificate)
- {
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
+ /// </summary>
+ /// <param name="port">The port where the server runs.</param>
+ /// <param name="clientTimeout">Send/receive timeout.</param>
+ /// <param name="certificate">The certificate object.</param>
+ public TTLSServerSocket(int port, int clientTimeout, X509Certificate2 certificate)
+ : this(port, clientTimeout, false, certificate)
+ {
+ }
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
- /// </summary>
- /// <param name="port">The port where the server runs.</param>
- /// <param name="clientTimeout">Send/receive timeout.</param>
- /// <param name="useBufferedSockets">If set to <c>true</c> [use buffered sockets].</param>
- /// <param name="certificate">The certificate object.</param>
- public TTLSServerSocket(int port, int clientTimeout, bool useBufferedSockets, X509Certificate2 certificate)
- {
- if (!certificate.HasPrivateKey)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, "Your server-certificate needs to have a private key");
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
+ /// </summary>
+ /// <param name="port">The port where the server runs.</param>
+ /// <param name="clientTimeout">Send/receive timeout.</param>
+ /// <param name="useBufferedSockets">If set to <c>true</c> [use buffered sockets].</param>
+ /// <param name="certificate">The certificate object.</param>
+ public TTLSServerSocket(int port, int clientTimeout, bool useBufferedSockets, X509Certificate2 certificate)
+ {
+ if (!certificate.HasPrivateKey)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, "Your server-certificate needs to have a private key");
+ }
- this.port = port;
- this.serverCertificate = certificate;
- this.useBufferedSockets = useBufferedSockets;
- try
- {
- // Create server socket
- server = new TcpListener(System.Net.IPAddress.Any, this.port);
- server.Server.NoDelay = true;
- }
- catch (Exception)
- {
- server = null;
- throw new TTransportException("Could not create ServerSocket on port " + port + ".");
- }
- }
+ this.port = port;
+ this.serverCertificate = certificate;
+ this.useBufferedSockets = useBufferedSockets;
+ try
+ {
+ // Create server socket
+ server = new TcpListener(System.Net.IPAddress.Any, this.port);
+ server.Server.NoDelay = true;
+ }
+ catch (Exception)
+ {
+ server = null;
+ throw new TTransportException("Could not create ServerSocket on port " + port + ".");
+ }
+ }
- /// <summary>
- /// Starts the server.
- /// </summary>
- public override void Listen()
- {
- // Make sure accept is not blocking
- if (this.server != null)
- {
- try
- {
- this.server.Start();
- }
- catch (SocketException sx)
- {
- throw new TTransportException("Could not accept on listening socket: " + sx.Message);
- }
- }
- }
+ /// <summary>
+ /// Starts the server.
+ /// </summary>
+ public override void Listen()
+ {
+ // Make sure accept is not blocking
+ if (this.server != null)
+ {
+ try
+ {
+ this.server.Start();
+ }
+ catch (SocketException sx)
+ {
+ throw new TTransportException("Could not accept on listening socket: " + sx.Message);
+ }
+ }
+ }
- /// <summary>
- /// Callback for Accept Implementation
- /// </summary>
- /// <returns>
- /// TTransport-object.
- /// </returns>
- protected override TTransport AcceptImpl()
- {
- if (this.server == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
- }
+ /// <summary>
+ /// Callback for Accept Implementation
+ /// </summary>
+ /// <returns>
+ /// TTransport-object.
+ /// </returns>
+ protected override TTransport AcceptImpl()
+ {
+ if (this.server == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
+ }
- try
- {
- TcpClient client = this.server.AcceptTcpClient();
- client.SendTimeout = client.ReceiveTimeout = this.clientTimeout;
+ try
+ {
+ TcpClient client = this.server.AcceptTcpClient();
+ client.SendTimeout = client.ReceiveTimeout = this.clientTimeout;
- //wrap the client in an SSL Socket passing in the SSL cert
- TTLSSocket socket = new TTLSSocket(client, this.serverCertificate, true);
+ //wrap the client in an SSL Socket passing in the SSL cert
+ TTLSSocket socket = new TTLSSocket(client, this.serverCertificate, true);
- socket.setupTLS();
+ socket.setupTLS();
- if (useBufferedSockets)
- {
- TBufferedTransport trans = new TBufferedTransport(socket);
- return trans;
- }
- else
- {
- return socket;
- }
-
- }
- catch (Exception ex)
- {
- throw new TTransportException(ex.ToString());
- }
- }
+ if (useBufferedSockets)
+ {
+ TBufferedTransport trans = new TBufferedTransport(socket);
+ return trans;
+ }
+ else
+ {
+ return socket;
+ }
- /// <summary>
- /// Stops the Server
- /// </summary>
- public override void Close()
- {
- if (this.server != null)
- {
- try
- {
- this.server.Stop();
- }
- catch (Exception ex)
- {
- throw new TTransportException("WARNING: Could not close server socket: " + ex);
- }
- this.server = null;
- }
- }
- }
+ }
+ catch (Exception ex)
+ {
+ throw new TTransportException(ex.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Stops the Server
+ /// </summary>
+ public override void Close()
+ {
+ if (this.server != null)
+ {
+ try
+ {
+ this.server.Stop();
+ }
+ catch (Exception ex)
+ {
+ throw new TTransportException("WARNING: Could not close server socket: " + ex);
+ }
+ this.server = null;
+ }
+ }
+ }
}
diff --git a/lib/csharp/src/Transport/TTLSSocket.cs b/lib/csharp/src/Transport/TTLSSocket.cs
index b87576d..9e1f9f2 100644
--- a/lib/csharp/src/Transport/TTLSSocket.cs
+++ b/lib/csharp/src/Transport/TTLSSocket.cs
@@ -25,276 +25,276 @@
namespace Thrift.Transport
{
- /// <summary>
- /// SSL Socket Wrapper class
- /// </summary>
- public class TTLSSocket : TStreamTransport
- {
- /// <summary>
- /// Internal TCP Client
- /// </summary>
- private TcpClient client = null;
+ /// <summary>
+ /// SSL Socket Wrapper class
+ /// </summary>
+ public class TTLSSocket : TStreamTransport
+ {
+ /// <summary>
+ /// Internal TCP Client
+ /// </summary>
+ private TcpClient client = null;
- /// <summary>
- /// The host
- /// </summary>
- private string host = null;
+ /// <summary>
+ /// The host
+ /// </summary>
+ private string host = null;
- /// <summary>
- /// The port
- /// </summary>
- private int port = 0;
+ /// <summary>
+ /// The port
+ /// </summary>
+ private int port = 0;
- /// <summary>
- /// The timeout for the connection
- /// </summary>
- private int timeout = 0;
+ /// <summary>
+ /// The timeout for the connection
+ /// </summary>
+ private int timeout = 0;
- /// <summary>
- /// Internal SSL Stream for IO
- /// </summary>
- private SslStream secureStream = null;
+ /// <summary>
+ /// Internal SSL Stream for IO
+ /// </summary>
+ private SslStream secureStream = null;
- /// <summary>
- /// Defines wheter or not this socket is a server socket<br/>
- /// This is used for the TLS-authentication
- /// </summary>
- private bool isServer = false;
+ /// <summary>
+ /// Defines wheter or not this socket is a server socket<br/>
+ /// This is used for the TLS-authentication
+ /// </summary>
+ private bool isServer = false;
- /// <summary>
- /// The certificate
- /// </summary>
- private X509Certificate certificate = null;
+ /// <summary>
+ /// The certificate
+ /// </summary>
+ private X509Certificate certificate = null;
- /// <summary>
- /// User defined certificate validator.
- /// </summary>
- private RemoteCertificateValidationCallback certValidator = null;
+ /// <summary>
+ /// User defined certificate validator.
+ /// </summary>
+ private RemoteCertificateValidationCallback certValidator = null;
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
- /// </summary>
- /// <param name="client">An already created TCP-client</param>
- /// <param name="certificate">The certificate.</param>
- /// <param name="isServer">if set to <c>true</c> [is server].</param>
- public TTLSSocket(TcpClient client, X509Certificate certificate, bool isServer = false)
- {
- this.client = client;
- this.certificate = certificate;
- this.isServer = isServer;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
+ /// </summary>
+ /// <param name="client">An already created TCP-client</param>
+ /// <param name="certificate">The certificate.</param>
+ /// <param name="isServer">if set to <c>true</c> [is server].</param>
+ public TTLSSocket(TcpClient client, X509Certificate certificate, bool isServer = false)
+ {
+ this.client = client;
+ this.certificate = certificate;
+ this.isServer = isServer;
- if (IsOpen)
- {
- base.inputStream = client.GetStream();
- base.outputStream = client.GetStream();
- }
- }
+ if (IsOpen)
+ {
+ base.inputStream = client.GetStream();
+ base.outputStream = client.GetStream();
+ }
+ }
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
- /// </summary>
- /// <param name="host">The host, where the socket should connect to.</param>
- /// <param name="port">The port.</param>
- /// <param name="certificatePath">The certificate path.</param>
- /// <param name="certValidator">User defined cert validator.</param>
- public TTLSSocket(string host, int port, string certificatePath, RemoteCertificateValidationCallback certValidator = null)
- : this(host, port, 0, X509Certificate.CreateFromCertFile(certificatePath), certValidator)
- {
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
+ /// </summary>
+ /// <param name="host">The host, where the socket should connect to.</param>
+ /// <param name="port">The port.</param>
+ /// <param name="certificatePath">The certificate path.</param>
+ /// <param name="certValidator">User defined cert validator.</param>
+ public TTLSSocket(string host, int port, string certificatePath, RemoteCertificateValidationCallback certValidator = null)
+ : this(host, port, 0, X509Certificate.CreateFromCertFile(certificatePath), certValidator)
+ {
+ }
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
- /// </summary>
- /// <param name="host">The host, where the socket should connect to.</param>
- /// <param name="port">The port.</param>
- /// <param name="certificate">The certificate.</param>
- /// <param name="certValidator">User defined cert validator.</param>
- public TTLSSocket(string host, int port, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null)
- : this(host, port, 0, certificate, certValidator)
- {
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
+ /// </summary>
+ /// <param name="host">The host, where the socket should connect to.</param>
+ /// <param name="port">The port.</param>
+ /// <param name="certificate">The certificate.</param>
+ /// <param name="certValidator">User defined cert validator.</param>
+ public TTLSSocket(string host, int port, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null)
+ : this(host, port, 0, certificate, certValidator)
+ {
+ }
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
- /// </summary>
- /// <param name="host">The host, where the socket should connect to.</param>
- /// <param name="port">The port.</param>
- /// <param name="timeout">The timeout.</param>
- /// <param name="certificate">The certificate.</param>
- /// <param name="certValidator">User defined cert validator.</param>
- public TTLSSocket(string host, int port, int timeout, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null)
- {
- this.host = host;
- this.port = port;
- this.timeout = timeout;
- this.certificate = certificate;
- this.certValidator = certValidator;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSSocket"/> class.
+ /// </summary>
+ /// <param name="host">The host, where the socket should connect to.</param>
+ /// <param name="port">The port.</param>
+ /// <param name="timeout">The timeout.</param>
+ /// <param name="certificate">The certificate.</param>
+ /// <param name="certValidator">User defined cert validator.</param>
+ public TTLSSocket(string host, int port, int timeout, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null)
+ {
+ this.host = host;
+ this.port = port;
+ this.timeout = timeout;
+ this.certificate = certificate;
+ this.certValidator = certValidator;
- InitSocket();
- }
+ InitSocket();
+ }
- /// <summary>
- /// Creates the TcpClient and sets the timeouts
- /// </summary>
- private void InitSocket()
- {
- this.client = new TcpClient();
- client.ReceiveTimeout = client.SendTimeout = timeout;
- client.Client.NoDelay = true;
- }
+ /// <summary>
+ /// Creates the TcpClient and sets the timeouts
+ /// </summary>
+ private void InitSocket()
+ {
+ this.client = new TcpClient();
+ client.ReceiveTimeout = client.SendTimeout = timeout;
+ client.Client.NoDelay = true;
+ }
- /// <summary>
- /// Sets Send / Recv Timeout for IO
- /// </summary>
- public int Timeout
- {
- set
- {
- this.client.ReceiveTimeout = this.client.SendTimeout = this.timeout = value;
- }
- }
+ /// <summary>
+ /// Sets Send / Recv Timeout for IO
+ /// </summary>
+ public int Timeout
+ {
+ set
+ {
+ this.client.ReceiveTimeout = this.client.SendTimeout = this.timeout = value;
+ }
+ }
- /// <summary>
- /// Gets the TCP client.
- /// </summary>
- public TcpClient TcpClient
- {
- get
- {
- return client;
- }
- }
+ /// <summary>
+ /// Gets the TCP client.
+ /// </summary>
+ public TcpClient TcpClient
+ {
+ get
+ {
+ return client;
+ }
+ }
- /// <summary>
- /// Gets the host.
- /// </summary>
- public string Host
- {
- get
- {
- return host;
- }
- }
+ /// <summary>
+ /// Gets the host.
+ /// </summary>
+ public string Host
+ {
+ get
+ {
+ return host;
+ }
+ }
- /// <summary>
- /// Gets the port.
- /// </summary>
- public int Port
- {
- get
- {
- return port;
- }
- }
+ /// <summary>
+ /// Gets the port.
+ /// </summary>
+ public int Port
+ {
+ get
+ {
+ return port;
+ }
+ }
- /// <summary>
- /// Gets a value indicating whether TCP Client is Cpen
- /// </summary>
- public override bool IsOpen
- {
- get
- {
- if (this.client == null)
- {
- return false;
- }
+ /// <summary>
+ /// Gets a value indicating whether TCP Client is Cpen
+ /// </summary>
+ public override bool IsOpen
+ {
+ get
+ {
+ if (this.client == null)
+ {
+ return false;
+ }
- return this.client.Connected;
- }
- }
+ return this.client.Connected;
+ }
+ }
- /// <summary>
- /// Validates the certificates!<br/>
- /// </summary>
- /// <param name="sender">The sender-object.</param>
- /// <param name="certificate">The used certificate.</param>
- /// <param name="chain">The certificate chain.</param>
- /// <param name="sslPolicyErrors">An enum, which lists all the errors from the .NET certificate check.</param>
- /// <returns></returns>
- private bool CertificateValidator(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslValidationErrors)
- {
- return (sslValidationErrors == SslPolicyErrors.None);
- }
+ /// <summary>
+ /// Validates the certificates!<br/>
+ /// </summary>
+ /// <param name="sender">The sender-object.</param>
+ /// <param name="certificate">The used certificate.</param>
+ /// <param name="chain">The certificate chain.</param>
+ /// <param name="sslPolicyErrors">An enum, which lists all the errors from the .NET certificate check.</param>
+ /// <returns></returns>
+ private bool CertificateValidator(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslValidationErrors)
+ {
+ return (sslValidationErrors == SslPolicyErrors.None);
+ }
- /// <summary>
- /// Connects to the host and starts the routine, which sets up the TLS
- /// </summary>
- public override void Open()
- {
- if (IsOpen)
- {
- throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
- }
+ /// <summary>
+ /// Connects to the host and starts the routine, which sets up the TLS
+ /// </summary>
+ public override void Open()
+ {
+ if (IsOpen)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
+ }
- if (String.IsNullOrEmpty(host))
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
- }
+ if (String.IsNullOrEmpty(host))
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
+ }
- if (port <= 0)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
- }
+ if (port <= 0)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
+ }
- if (client == null)
- {
- InitSocket();
- }
+ if (client == null)
+ {
+ InitSocket();
+ }
- client.Connect(host, port);
+ client.Connect(host, port);
- setupTLS();
- }
+ setupTLS();
+ }
- /// <summary>
- /// Creates a TLS-stream and lays it over the existing socket
- /// </summary>
- public void setupTLS()
- {
- if (isServer)
- {
- // Server authentication
- this.secureStream = new SslStream(this.client.GetStream(), false);
- this.secureStream.AuthenticateAsServer(this.certificate, false, SslProtocols.Tls, true);
- }
- else
- {
- // Client authentication
- X509CertificateCollection validCerts = new X509CertificateCollection();
- validCerts.Add(certificate);
+ /// <summary>
+ /// Creates a TLS-stream and lays it over the existing socket
+ /// </summary>
+ public void setupTLS()
+ {
+ if (isServer)
+ {
+ // Server authentication
+ this.secureStream = new SslStream(this.client.GetStream(), false);
+ this.secureStream.AuthenticateAsServer(this.certificate, false, SslProtocols.Tls, true);
+ }
+ else
+ {
+ // Client authentication
+ X509CertificateCollection validCerts = new X509CertificateCollection();
+ validCerts.Add(certificate);
- if (this.certValidator != null)
- {
- this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(this.certValidator));
- }
- else
- {
- this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidator));
- }
- this.secureStream.AuthenticateAsClient(host, validCerts, SslProtocols.Tls, true);
- }
+ if (this.certValidator != null)
+ {
+ this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(this.certValidator));
+ }
+ else
+ {
+ this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidator));
+ }
+ this.secureStream.AuthenticateAsClient(host, validCerts, SslProtocols.Tls, true);
+ }
- inputStream = this.secureStream;
- outputStream = this.secureStream;
- }
+ inputStream = this.secureStream;
+ outputStream = this.secureStream;
+ }
- /// <summary>
- /// Closes the SSL Socket
- /// </summary>
- public override void Close()
- {
- base.Close();
- if (this.client != null)
- {
- this.client.Close();
- this.client = null;
- }
+ /// <summary>
+ /// Closes the SSL Socket
+ /// </summary>
+ public override void Close()
+ {
+ base.Close();
+ if (this.client != null)
+ {
+ this.client.Close();
+ this.client = null;
+ }
- if (this.secureStream != null)
- {
- this.secureStream.Close();
- this.secureStream = null;
- }
- }
- }
+ if (this.secureStream != null)
+ {
+ this.secureStream.Close();
+ this.secureStream = null;
+ }
+ }
+ }
}
diff --git a/lib/csharp/src/Transport/TTransport.cs b/lib/csharp/src/Transport/TTransport.cs
index 5bb8f9e..13314ec 100644
--- a/lib/csharp/src/Transport/TTransport.cs
+++ b/lib/csharp/src/Transport/TTransport.cs
@@ -25,24 +25,24 @@
namespace Thrift.Transport
{
- public abstract class TTransport : IDisposable
- {
- public abstract bool IsOpen
- {
- get;
- }
+ public abstract class TTransport : IDisposable
+ {
+ public abstract bool IsOpen
+ {
+ get;
+ }
- private byte[] _peekBuffer = new byte[1];
+ private byte[] _peekBuffer = new byte[1];
private bool _hasPeekByte = false;
public bool Peek()
{
//If we already have a byte read but not consumed, do nothing.
- if (_hasPeekByte)
+ if (_hasPeekByte)
return true;
//If transport closed we can't peek.
- if (!IsOpen)
+ if (!IsOpen)
return false;
//Try to read one byte. If succeeds we will need to store it for the next read.
@@ -54,15 +54,15 @@
return true;
}
- public abstract void Open();
+ public abstract void Open();
- public abstract void Close();
+ public abstract void Close();
- public abstract int Read(byte[] buf, int off, int len);
+ public abstract int Read(byte[] buf, int off, int len);
- public int ReadAll(byte[] buf, int off, int len)
- {
- int got = 0;
+ public int ReadAll(byte[] buf, int off, int len)
+ {
+ int got = 0;
//If we previously peeked a byte, we need to use that first.
if (_hasPeekByte)
@@ -83,19 +83,19 @@
got += ret;
}
return got;
- }
+ }
- public virtual void Write(byte[] buf)
- {
- Write (buf, 0, buf.Length);
- }
+ public virtual void Write(byte[] buf)
+ {
+ Write (buf, 0, buf.Length);
+ }
- public abstract void Write(byte[] buf, int off, int len);
+ public abstract void Write(byte[] buf, int off, int len);
- public virtual void Flush()
- {
- }
-
+ public virtual void Flush()
+ {
+ }
+
public virtual IAsyncResult BeginFlush(AsyncCallback callback, object state)
{
throw new TTransportException(
@@ -110,16 +110,16 @@
"Asynchronous operations are not supported by this transport.");
}
- #region " IDisposable Support "
- // IDisposable
- protected abstract void Dispose(bool disposing);
+ #region " IDisposable Support "
+ // IDisposable
+ protected abstract void Dispose(bool disposing);
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- #endregion
- }
+ public void Dispose()
+ {
+ // Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ #endregion
+ }
}
diff --git a/lib/csharp/src/Transport/TTransportException.cs b/lib/csharp/src/Transport/TTransportException.cs
index fda0138..6dcd987 100644
--- a/lib/csharp/src/Transport/TTransportException.cs
+++ b/lib/csharp/src/Transport/TTransportException.cs
@@ -25,44 +25,44 @@
namespace Thrift.Transport
{
- public class TTransportException : TException
- {
- protected ExceptionType type;
+ public class TTransportException : TException
+ {
+ protected ExceptionType type;
- public TTransportException()
- : base()
- {
- }
+ public TTransportException()
+ : base()
+ {
+ }
- public TTransportException(ExceptionType type)
- : this()
- {
- this.type = type;
- }
+ public TTransportException(ExceptionType type)
+ : this()
+ {
+ this.type = type;
+ }
- public TTransportException(ExceptionType type, string message)
- : base(message)
- {
- this.type = type;
- }
+ public TTransportException(ExceptionType type, string message)
+ : base(message)
+ {
+ this.type = type;
+ }
- public TTransportException(string message)
- : base(message)
- {
- }
+ public TTransportException(string message)
+ : base(message)
+ {
+ }
- public ExceptionType Type
- {
- get { return type; }
- }
+ public ExceptionType Type
+ {
+ get { return type; }
+ }
- public enum ExceptionType
- {
- Unknown,
- NotOpen,
- AlreadyOpen,
- TimedOut,
- EndOfFile
- }
- }
+ public enum ExceptionType
+ {
+ Unknown,
+ NotOpen,
+ AlreadyOpen,
+ TimedOut,
+ EndOfFile
+ }
+ }
}
diff --git a/lib/csharp/src/Transport/TTransportFactory.cs b/lib/csharp/src/Transport/TTransportFactory.cs
index 8f4f15d..fa10033 100644
--- a/lib/csharp/src/Transport/TTransportFactory.cs
+++ b/lib/csharp/src/Transport/TTransportFactory.cs
@@ -25,18 +25,18 @@
namespace Thrift.Transport
{
- /// <summary>
- /// From Mark Slee & Aditya Agarwal of Facebook:
- /// Factory class used to create wrapped instance of Transports.
- /// This is used primarily in servers, which get Transports from
- /// a ServerTransport and then may want to mutate them (i.e. create
- /// a BufferedTransport from the underlying base transport)
- /// </summary>
- public class TTransportFactory
- {
- public virtual TTransport GetTransport(TTransport trans)
- {
- return trans;
- }
- }
+ /// <summary>
+ /// From Mark Slee & Aditya Agarwal of Facebook:
+ /// Factory class used to create wrapped instance of Transports.
+ /// This is used primarily in servers, which get Transports from
+ /// a ServerTransport and then may want to mutate them (i.e. create
+ /// a BufferedTransport from the underlying base transport)
+ /// </summary>
+ public class TTransportFactory
+ {
+ public virtual TTransport GetTransport(TTransport trans)
+ {
+ return trans;
+ }
+ }
}