http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TJSONProtocol.cs ---------------------------------------------------------------------- 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 @@ using System.Globalization; 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); - } - } - - 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 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, + /// <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 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 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 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 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; - - public JSONBaseContext(TJSONProtocol proto) - { - this.proto = proto; - } - - public virtual void Write() { } - - public virtual void Read() { } - - 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) - { - - } - - private bool first = true; - - 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); - } - } - } - - ///<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; - - 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 bool EscapeNumbers() - { - return colon; - } - } - - ///<summary> - /// Holds up to one byte from the transport - ///</summary> - protected class LookaheadReader - { - protected TJSONProtocol proto; - - public LookaheadReader(TJSONProtocol proto) - { - this.proto = proto; - } - - 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 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; - - // 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; - - // 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> - /// 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); - } - - // 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> - /// 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> - /// 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(); - - bool escapeNum = context.EscapeNumbers(); - if (escapeNum) - trans.Write(QUOTE); - - trans.Write(utf8Encoding.GetBytes(str)); - - 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; - - 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(); - - if (escapeNum) - trans.Write(QUOTE); - - 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); - - 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); - } - - trans.Write(QUOTE); - } - - private void WriteJSONObjectStart() - { - context.Write(); - trans.Write(LBRACE); - PushContext(new JSONPairContext(this)); - } - - private void WriteJSONObjectEnd() - { - PopContext(); - trans.Write(RBRACE); - } - - private void WriteJSONArrayStart() - { - context.Write(); - trans.Write(LBRACKET); - PushContext(new JSONListContext(this)); - } - - private void WriteJSONArrayEnd() - { - PopContext(); - trans.Write(RBRACKET); - } - - public override void WriteMessageBegin(TMessage message) - { - WriteJSONArrayStart(); - WriteJSONInteger(VERSION); - - byte[] b = utf8Encoding.GetBytes(message.Name); - WriteJSONString(b); - - WriteJSONInteger((long)message.Type); - WriteJSONInteger(message.SeqID); - } - - public override void WriteMessageEnd() - { - WriteJSONArrayEnd(); - } - - public override void WriteStructBegin(TStruct str) - { - WriteJSONObjectStart(); - } - - public override void WriteStructEnd() - { - WriteJSONObjectEnd(); - } - - public override void WriteFieldBegin(TField field) - { - WriteJSONInteger(field.ID); - WriteJSONObjectStart(); - WriteJSONString(GetTypeNameForTypeID(field.Type)); - } - - public override void WriteFieldEnd() - { - WriteJSONObjectEnd(); - } - - 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 WriteMapEnd() - { - WriteJSONObjectEnd(); - WriteJSONArrayEnd(); - } - - public override void WriteListBegin(TList list) - { - WriteJSONArrayStart(); - WriteJSONString(GetTypeNameForTypeID(list.ElementType)); - WriteJSONInteger(list.Count); - } - - public override void WriteListEnd() - { - WriteJSONArrayEnd(); - } - - public override void WriteSetBegin(TSet set) - { - WriteJSONArrayStart(); - WriteJSONString(GetTypeNameForTypeID(set.ElementType)); - WriteJSONInteger(set.Count); - } - - public override void WriteSetEnd() - { - WriteJSONArrayEnd(); - } - - public override void WriteBool(bool b) - { - WriteJSONInteger(b ? (long)1 : (long)0); - } - - public override void WriteByte(sbyte b) - { - WriteJSONInteger((long)b); - } - - public override void WriteI16(short i16) - { - WriteJSONInteger((long)i16); - } - - public override void WriteI32(int i32) - { - WriteJSONInteger((long)i32); - } - - public override void WriteI64(long i64) - { - WriteJSONInteger(i64); - } - - public override void WriteDouble(double dub) - { - WriteJSONDouble(dub); - } - - public override void WriteString(String str) - { - byte[] b = utf8Encoding.GetBytes(str); - WriteJSONString(b); - } - - public override void WriteBinary(byte[] bin) - { - WriteJSONBase64(bin); - } - - /** - * 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(); - - - 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; - } - - // 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(); - } - - ///<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 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); - - 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; - } - - private void ReadJSONObjectStart() - { - context.Read(); - ReadJSONSyntaxChar(LBRACE); - PushContext(new JSONPairContext(this)); - } - - private void ReadJSONObjectEnd() - { - ReadJSONSyntaxChar(RBRACE); - PopContext(); - } - - private void ReadJSONArrayStart() - { - context.Read(); - ReadJSONSyntaxChar(LBRACKET); - PushContext(new JSONListContext(this)); - } - - 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."); - } + 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[] 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; + } + + ///<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 virtual void Write() { } + + public virtual void Read() { } + + 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) + { + + } + + private bool first = true; + + 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); + } + } + } + + ///<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; + + 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 bool EscapeNumbers() + { + return colon; + } + } + + ///<summary> + /// Holds up to one byte from the transport + ///</summary> + protected class LookaheadReader + { + protected TJSONProtocol proto; + + public LookaheadReader(TJSONProtocol proto) + { + this.proto = proto; + } + + 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 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; + + // 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; + + // 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> + /// 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); + } + + // 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> + /// 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> + /// 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(); + + bool escapeNum = context.EscapeNumbers(); + if (escapeNum) + trans.Write(QUOTE); + + trans.Write(utf8Encoding.GetBytes(str)); + + 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; + + 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(); + + if (escapeNum) + trans.Write(QUOTE); + + 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); + + 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); + } + + trans.Write(QUOTE); + } + + private void WriteJSONObjectStart() + { + context.Write(); + trans.Write(LBRACE); + PushContext(new JSONPairContext(this)); + } + + private void WriteJSONObjectEnd() + { + PopContext(); + trans.Write(RBRACE); + } + + private void WriteJSONArrayStart() + { + context.Write(); + trans.Write(LBRACKET); + PushContext(new JSONListContext(this)); + } + + private void WriteJSONArrayEnd() + { + PopContext(); + trans.Write(RBRACKET); + } + + public override void WriteMessageBegin(TMessage message) + { + WriteJSONArrayStart(); + WriteJSONInteger(VERSION); + + byte[] b = utf8Encoding.GetBytes(message.Name); + WriteJSONString(b); + + WriteJSONInteger((long)message.Type); + WriteJSONInteger(message.SeqID); + } + + public override void WriteMessageEnd() + { + WriteJSONArrayEnd(); + } + + public override void WriteStructBegin(TStruct str) + { + WriteJSONObjectStart(); + } + + public override void WriteStructEnd() + { + WriteJSONObjectEnd(); + } + + public override void WriteFieldBegin(TField field) + { + WriteJSONInteger(field.ID); + WriteJSONObjectStart(); + WriteJSONString(GetTypeNameForTypeID(field.Type)); + } + + public override void WriteFieldEnd() + { + WriteJSONObjectEnd(); + } + + 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 WriteMapEnd() + { + WriteJSONObjectEnd(); + WriteJSONArrayEnd(); + } + + public override void WriteListBegin(TList list) + { + WriteJSONArrayStart(); + WriteJSONString(GetTypeNameForTypeID(list.ElementType)); + WriteJSONInteger(list.Count); + } + + public override void WriteListEnd() + { + WriteJSONArrayEnd(); + } + + public override void WriteSetBegin(TSet set) + { + WriteJSONArrayStart(); + WriteJSONString(GetTypeNameForTypeID(set.ElementType)); + WriteJSONInteger(set.Count); + } + + public override void WriteSetEnd() + { + WriteJSONArrayEnd(); + } + + public override void WriteBool(bool b) + { + WriteJSONInteger(b ? (long)1 : (long)0); + } + + public override void WriteByte(sbyte b) + { + WriteJSONInteger((long)b); + } + + public override void WriteI16(short i16) + { + WriteJSONInteger((long)i16); + } + + public override void WriteI32(int i32) + { + WriteJSONInteger((long)i32); + } + + public override void WriteI64(long i64) + { + WriteJSONInteger(i64); + } + + public override void WriteDouble(double dub) + { + WriteJSONDouble(dub); + } + + public override void WriteString(String str) + { + byte[] b = utf8Encoding.GetBytes(str); + WriteJSONString(b); + } + + public override void WriteBinary(byte[] bin) + { + WriteJSONBase64(bin); + } + + /** + * 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(); + + + 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; + } + + // 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(); + } + + ///<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 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); + + 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; + } + + private void ReadJSONObjectStart() + { + context.Read(); + ReadJSONSyntaxChar(LBRACE); + PushContext(new JSONPairContext(this)); + } + + private void ReadJSONObjectEnd() + { + ReadJSONSyntaxChar(RBRACE); + PopContext(); + } + + private void ReadJSONArrayStart() + { + context.Read(); + ReadJSONSyntaxChar(LBRACKET); + PushContext(new JSONListContext(this)); + } + + 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."); + } var buf = ReadJSONString(false); - 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 TStruct ReadStructBegin() - { - ReadJSONObjectStart(); - return new TStruct(); - } - - 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 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 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 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 void ReadSetEnd() - { - ReadJSONArrayEnd(); - } - - public override bool ReadBool() - { - return (ReadJSONInteger() == 0 ? false : true); - } - - public override sbyte ReadByte() - { - return (sbyte)ReadJSONInteger(); - } - - public override short ReadI16() - { - return (short)ReadJSONInteger(); - } - - public override int ReadI32() - { - return (int)ReadJSONInteger(); - } - - public override long ReadI64() - { - return (long)ReadJSONInteger(); - } - - public override double ReadDouble() - { - return ReadJSONDouble(); - } - - public override String ReadString() - { + 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 TStruct ReadStructBegin() + { + ReadJSONObjectStart(); + return new TStruct(); + } + + 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 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 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 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 void ReadSetEnd() + { + ReadJSONArrayEnd(); + } + + public override bool ReadBool() + { + return (ReadJSONInteger() == 0 ? false : true); + } + + public override sbyte ReadByte() + { + return (sbyte)ReadJSONInteger(); + } + + public override short ReadI16() + { + return (short)ReadJSONInteger(); + } + + public override int ReadI32() + { + return (int)ReadJSONInteger(); + } + + public override long ReadI64() + { + return (long)ReadJSONInteger(); + } + + public override double ReadDouble() + { + return ReadJSONDouble(); + } + + 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(); + } - } + } }
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TList.cs ---------------------------------------------------------------------- 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 @@ using System.Text; 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; } + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TMap.cs ---------------------------------------------------------------------- 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 @@ using System.Text; 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; } + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TMessage.cs ---------------------------------------------------------------------- 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 @@ using System.Text; 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; } + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TMessageType.cs ---------------------------------------------------------------------- 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 @@ using System; 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 + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TMultiplexedProcessor.cs ---------------------------------------------------------------------- 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 Thrift.Transport; 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 @@ namespace Thrift.Protocol * * 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 @@ namespace Thrift.Protocol oprot.WriteMessageEnd(); oprot.Transport.Flush(); } - - + + /** * This implementation of process performs the following steps: * @@ -91,11 +91,11 @@ namespace Thrift.Protocol * - 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 @@ namespace Thrift.Protocol * 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; } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TMultiplexedProtocol.cs ---------------------------------------------------------------------- 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 System.Text; 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 @@ namespace Thrift.Protocol * 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 @@ namespace Thrift.Protocol * 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 @@ namespace Thrift.Protocol * Args: * tMessage The original message. */ - public override void WriteMessageBegin(TMessage tMessage) + public override void WriteMessageBegin(TMessage tMessage) { switch(tMessage.Type) { http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TProtocol.cs ---------------------------------------------------------------------- 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 @@ using Thrift.Transport; 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 @@ namespace Thrift.Protocol } #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(); + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TProtocolDecorator.cs ---------------------------------------------------------------------- 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 System.Text; 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 @@ namespace Thrift.Protocol * 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 @@ namespace Thrift.Protocol WrappedProtocol.WriteFieldStop(); } - public override void WriteMapBegin(TMap tMap) + public override void WriteMapBegin(TMap tMap) { WrappedProtocol.WriteMapBegin(tMap); } @@ -98,7 +98,7 @@ namespace Thrift.Protocol WrappedProtocol.WriteMapEnd(); } - public override void WriteListBegin(TList tList) + public override void WriteListBegin(TList tList) { WrappedProtocol.WriteListBegin(tList); } @@ -108,7 +108,7 @@ namespace Thrift.Protocol WrappedProtocol.WriteListEnd(); } - public override void WriteSetBegin(TSet tSet) + public override void WriteSetBegin(TSet tSet) { WrappedProtocol.WriteSetBegin(tSet); } @@ -118,7 +118,7 @@ namespace Thrift.Protocol WrappedProtocol.WriteSetEnd(); } - public override void WriteBool(bool b) + public override void WriteBool(bool b) { WrappedProtocol.WriteBool(b); } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TProtocolException.cs ---------------------------------------------------------------------- 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 @@ using System; 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_; + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TProtocolFactory.cs ---------------------------------------------------------------------- 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 @@ using Thrift.Transport; namespace Thrift.Protocol { - public interface TProtocolFactory - { - TProtocol GetProtocol(TTransport trans); - } + public interface TProtocolFactory + { + TProtocol GetProtocol(TTransport trans); + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TProtocolUtil.cs ---------------------------------------------------------------------- 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 @@ using System; 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; + } + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TSet.cs ---------------------------------------------------------------------- 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 @@ using System.Text; 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; } + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TStruct.cs ---------------------------------------------------------------------- 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 @@ using System.Text; 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; } + } + } }
