mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
THRIFT-4535: XML docs; code cleanup (tabs->spaces; String->string)
Client: C# Patch: Christian Weiss This closes #1524
This commit is contained in:
parent
d4fb364d30
commit
8fb719efb1
@ -79,7 +79,7 @@ namespace Thrift.Collections
|
||||
}
|
||||
|
||||
int hashcode = 0;
|
||||
foreach (Object obj in enumerable)
|
||||
foreach (object obj in enumerable)
|
||||
{
|
||||
IEnumerable enum2 = obj as IEnumerable;
|
||||
int objHash = enum2 == null ? obj.GetHashCode () : GetHashCode (enum2);
|
||||
|
@ -21,9 +21,9 @@ namespace Thrift.Protocol
|
||||
{
|
||||
public interface TAbstractBase
|
||||
{
|
||||
///
|
||||
/// Writes the objects out to the protocol
|
||||
///
|
||||
/// <summary>
|
||||
/// Writes the objects out to the protocol.
|
||||
/// </summary>
|
||||
void Write(TProtocol tProtocol);
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ namespace Thrift.Protocol
|
||||
{
|
||||
public interface TBase : TAbstractBase
|
||||
{
|
||||
///
|
||||
/// <summary>
|
||||
/// Reads the TObject from the given input protocol.
|
||||
///
|
||||
/// </summary>
|
||||
void Read(TProtocol tProtocol);
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +36,9 @@ namespace Thrift.Protocol
|
||||
protected bool strictWrite_ = true;
|
||||
|
||||
#region BinaryProtocol Factory
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
public class Factory : TProtocolFactory {
|
||||
|
||||
public class Factory : TProtocolFactory
|
||||
{
|
||||
protected bool strictRead_ = false;
|
||||
protected bool strictWrite_ = true;
|
||||
|
||||
@ -55,7 +53,8 @@ namespace Thrift.Protocol
|
||||
strictWrite_ = strictWrite;
|
||||
}
|
||||
|
||||
public TProtocol GetProtocol(TTransport trans) {
|
||||
public TProtocol GetProtocol(TTransport trans)
|
||||
{
|
||||
return new TBinaryProtocol(trans, strictRead_, strictWrite_);
|
||||
}
|
||||
}
|
||||
@ -345,7 +344,8 @@ namespace Thrift.Protocol
|
||||
public override long ReadI64()
|
||||
{
|
||||
ReadAll(i64in, 0, 8);
|
||||
unchecked {
|
||||
unchecked
|
||||
{
|
||||
return (long)(
|
||||
((long)(i64in[0] & 0xff) << 56) |
|
||||
((long)(i64in[1] & 0xff) << 48) |
|
||||
|
@ -44,9 +44,9 @@ namespace Thrift.Protocol
|
||||
private const byte TYPE_BITS = 0x07; // 0000 0111
|
||||
private const int TYPE_SHIFT_AMOUNT = 5;
|
||||
|
||||
/**
|
||||
* All of the on-wire type codes.
|
||||
*/
|
||||
/// <summary>
|
||||
/// All of the on-wire type codes.
|
||||
/// </summary>
|
||||
private static class Types
|
||||
{
|
||||
public const byte STOP = 0x00;
|
||||
@ -64,32 +64,29 @@ namespace Thrift.Protocol
|
||||
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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Used to keep track of the last field for the current and previous structs,
|
||||
/// so we can do the delta stuff.
|
||||
/// </summary>
|
||||
private Stack<short> lastField_ = new Stack<short>(15);
|
||||
|
||||
private short lastFieldId_ = 0;
|
||||
|
||||
/**
|
||||
* If we encounter a boolean field begin, save the TField here so it can
|
||||
* have the value incorporated.
|
||||
*/
|
||||
/// <summary>
|
||||
/// If we encounter a boolean field begin, save the TField here so it can
|
||||
/// have the value incorporated.
|
||||
/// </summary>
|
||||
private Nullable<TField> booleanField_;
|
||||
|
||||
/**
|
||||
* If we Read a field header, and it's a boolean field, save the boolean
|
||||
* value here so that ReadBool can use it.
|
||||
*/
|
||||
/// <summary>
|
||||
/// If we Read a field header, and it's a boolean field, save the boolean
|
||||
/// value here so that ReadBool can use it.
|
||||
/// </summary>
|
||||
private Nullable<Boolean> boolValue_;
|
||||
|
||||
|
||||
#region CompactProtocol Factory
|
||||
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
public class Factory : TProtocolFactory
|
||||
{
|
||||
public Factory() { }
|
||||
@ -127,31 +124,32 @@ namespace Thrift.Protocol
|
||||
|
||||
#region Write Methods
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private byte[] byteDirectBuffer = new byte[1];
|
||||
|
||||
private void WriteByteDirect(byte b)
|
||||
{
|
||||
byteDirectBuffer[0] = b;
|
||||
trans.Write(byteDirectBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a byte without any possibility of all that field header nonsense.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Writes a byte without any possibility of all that field header nonsense.
|
||||
/// </summary>
|
||||
private void WriteByteDirect(int n)
|
||||
{
|
||||
WriteByteDirect((byte)n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an i32 as a varint. Results in 1-5 bytes on the wire.
|
||||
* TODO: make a permanent buffer like WriteVarint64?
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write an i32 as a varint. Results in 1-5 bytes on the wire.
|
||||
/// TODO: make a permanent buffer like WriteVarint64?
|
||||
/// </summary>
|
||||
byte[] i32buf = new byte[5];
|
||||
|
||||
private void WriteVarint32(uint n)
|
||||
{
|
||||
int idx = 0;
|
||||
@ -174,10 +172,10 @@ namespace Thrift.Protocol
|
||||
trans.Write(i32buf, 0, idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message header to the wire. Compact Protocol messages contain the
|
||||
* protocol version so we can migrate forwards in the future if need be.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a message header to the wire. Compact Protocol messages contain the
|
||||
/// protocol version so we can migrate forwards in the future if need be.
|
||||
/// </summary>
|
||||
public override void WriteMessageBegin(TMessage message)
|
||||
{
|
||||
WriteByteDirect(PROTOCOL_ID);
|
||||
@ -186,33 +184,33 @@ namespace Thrift.Protocol
|
||||
WriteString(message.Name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public override void WriteStructBegin(TStruct strct)
|
||||
{
|
||||
lastField_.Push(lastFieldId_);
|
||||
lastFieldId_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a struct end. This doesn't actually put anything on the wire. We use
|
||||
* this as an opportunity to pop the last field from the current struct off
|
||||
* of the field stack.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a struct end. This doesn't actually put anything on the wire. We use
|
||||
/// this as an opportunity to pop the last field from the current struct off
|
||||
/// of the field stack.
|
||||
/// </summary>
|
||||
public override void WriteStructEnd()
|
||||
{
|
||||
lastFieldId_ = lastField_.Pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a field header containing the field id and field type. If the
|
||||
* difference between the current field id and the last one is small (< 15),
|
||||
* then the field id will be encoded in the 4 MSB as a delta. Otherwise, the
|
||||
* field id will follow the type header as a zigzag varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a field header containing the field id and field type. If the
|
||||
/// difference between the current field id and the last one is small (< 15),
|
||||
/// then the field id will be encoded in the 4 MSB as a delta. Otherwise, the
|
||||
/// field id will follow the type header as a zigzag varint.
|
||||
/// </summary>
|
||||
public override void WriteFieldBegin(TField field)
|
||||
{
|
||||
if (field.Type == TType.Bool)
|
||||
@ -226,11 +224,11 @@ namespace Thrift.Protocol
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private void WriteFieldBeginInternal(TField field, byte typeOverride)
|
||||
{
|
||||
// short lastField = lastField_.Pop();
|
||||
@ -255,18 +253,18 @@ namespace Thrift.Protocol
|
||||
// lastField_.push(field.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the STOP symbol so we know there are no more fields in this struct.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write the STOP symbol so we know there are no more fields in this struct.
|
||||
/// </summary>
|
||||
public override void WriteFieldStop()
|
||||
{
|
||||
WriteByteDirect(Types.STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public override void WriteMapBegin(TMap map)
|
||||
{
|
||||
if (map.Count == 0)
|
||||
@ -280,28 +278,28 @@ namespace Thrift.Protocol
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a list header.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a list header.
|
||||
/// </summary>
|
||||
public override void WriteListBegin(TList list)
|
||||
{
|
||||
WriteCollectionBegin(list.ElementType, list.Count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a set header.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a set header.
|
||||
/// </summary>
|
||||
public override void WriteSetBegin(TSet set)
|
||||
{
|
||||
WriteCollectionBegin(set.ElementType, set.Count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Otherwise, Write a single byte.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// Otherwise, Write a single byte.
|
||||
/// </summary>
|
||||
public override void WriteBool(Boolean b)
|
||||
{
|
||||
if (booleanField_ != null)
|
||||
@ -317,41 +315,41 @@ namespace Thrift.Protocol
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a byte. Nothing to see here!
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a byte. Nothing to see here!
|
||||
/// </summary>
|
||||
public override void WriteByte(sbyte b)
|
||||
{
|
||||
WriteByteDirect((byte)b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an I16 as a zigzag varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write an I16 as a zigzag varint.
|
||||
/// </summary>
|
||||
public override void WriteI16(short i16)
|
||||
{
|
||||
WriteVarint32(intToZigZag(i16));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an i32 as a zigzag varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write an i32 as a zigzag varint.
|
||||
/// </summary>
|
||||
public override void WriteI32(int i32)
|
||||
{
|
||||
WriteVarint32(intToZigZag(i32));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an i64 as a zigzag varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write an i64 as a zigzag varint.
|
||||
/// </summary>
|
||||
public override void WriteI64(long i64)
|
||||
{
|
||||
WriteVarint64(longToZigzag(i64));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a double to the wire as 8 bytes.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a double to the wire as 8 bytes.
|
||||
/// </summary>
|
||||
public override void WriteDouble(double dub)
|
||||
{
|
||||
byte[] data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
@ -359,18 +357,18 @@ namespace Thrift.Protocol
|
||||
trans.Write(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to the wire with a varint size preceding.
|
||||
*/
|
||||
public override void WriteString(String str)
|
||||
/// <summary>
|
||||
/// Write a string to the wire with a varint size preceding.
|
||||
/// </summary>
|
||||
public override void WriteString(string str)
|
||||
{
|
||||
byte[] bytes = UTF8Encoding.UTF8.GetBytes(str);
|
||||
WriteBinary(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a byte array, using a varint for the size.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write a byte array, using a varint for the size.
|
||||
/// </summary>
|
||||
public override void WriteBinary(byte[] bin)
|
||||
{
|
||||
WriteBinary(bin, 0, bin.Length);
|
||||
@ -397,10 +395,10 @@ namespace Thrift.Protocol
|
||||
// Internal writing methods
|
||||
//
|
||||
|
||||
/**
|
||||
* Abstract method for writing the start of lists and sets. List and sets on
|
||||
* the wire differ only by the type indicator.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Abstract method for writing the start of lists and sets. List and sets on
|
||||
/// the wire differ only by the type indicator.
|
||||
/// </summary>
|
||||
protected void WriteCollectionBegin(TType elemType, int size)
|
||||
{
|
||||
if (size <= 14)
|
||||
@ -414,9 +412,9 @@ namespace Thrift.Protocol
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an i64 as a varint. Results in 1-10 bytes on the wire.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Write an i64 as a varint. Results in 1-10 bytes on the wire.
|
||||
/// </summary>
|
||||
byte[] varint64out = new byte[10];
|
||||
private void WriteVarint64(ulong n)
|
||||
{
|
||||
@ -437,28 +435,28 @@ namespace Thrift.Protocol
|
||||
trans.Write(varint64out, 0, idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert l into a zigzag long. This allows negative numbers to be
|
||||
* represented compactly as a varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Convert l into a zigzag long. This allows negative numbers to be
|
||||
/// represented compactly as a varint.
|
||||
/// </summary>
|
||||
private ulong longToZigzag(long n)
|
||||
{
|
||||
return (ulong)(n << 1) ^ (ulong)(n >> 63);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert n into a zigzag int. This allows negative numbers to be
|
||||
* represented compactly as a varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Convert n into a zigzag int. This allows negative numbers to be
|
||||
/// represented compactly as a varint.
|
||||
/// </summary>
|
||||
private uint intToZigZag(int n)
|
||||
{
|
||||
return (uint)(n << 1) ^ (uint)(n >> 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a long into little-endian bytes in buf starting at off and going
|
||||
* until off+7.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Convert a long into little-endian bytes in buf starting at off and going
|
||||
/// until off+7.
|
||||
/// </summary>
|
||||
private void fixedLongToBytes(long n, byte[] buf, int off)
|
||||
{
|
||||
buf[off + 0] = (byte)(n & 0xff);
|
||||
@ -475,9 +473,9 @@ namespace Thrift.Protocol
|
||||
|
||||
#region ReadMethods
|
||||
|
||||
/**
|
||||
* Read a message header.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read a message header.
|
||||
/// </summary>
|
||||
public override TMessage ReadMessageBegin()
|
||||
{
|
||||
byte protocolId = (byte)ReadByte();
|
||||
@ -493,14 +491,14 @@ namespace Thrift.Protocol
|
||||
}
|
||||
byte type = (byte)((versionAndType >> TYPE_SHIFT_AMOUNT) & TYPE_BITS);
|
||||
int seqid = (int)ReadVarint32();
|
||||
String messageName = ReadString();
|
||||
string messageName = ReadString();
|
||||
return new TMessage(messageName, (TMessageType)type, seqid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a struct begin. There's nothing on the wire for this, but it is our
|
||||
* opportunity to push a new struct begin marker onto the field stack.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read a struct begin. There's nothing on the wire for this, but it is our
|
||||
/// opportunity to push a new struct begin marker onto the field stack.
|
||||
/// </summary>
|
||||
public override TStruct ReadStructBegin()
|
||||
{
|
||||
lastField_.Push(lastFieldId_);
|
||||
@ -508,19 +506,19 @@ namespace Thrift.Protocol
|
||||
return ANONYMOUS_STRUCT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't actually consume any wire data, just removes the last field for
|
||||
* this struct from the field stack.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Doesn't actually consume any wire data, just removes the last field for
|
||||
/// this struct from the field stack.
|
||||
/// </summary>
|
||||
public override void ReadStructEnd()
|
||||
{
|
||||
// consume the last field we Read off the wire.
|
||||
lastFieldId_ = lastField_.Pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a field header off the wire.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read a field header off the wire.
|
||||
/// </summary>
|
||||
public override TField ReadFieldBegin()
|
||||
{
|
||||
byte type = (byte)ReadByte();
|
||||
@ -560,11 +558,11 @@ namespace Thrift.Protocol
|
||||
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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public override TMap ReadMapBegin()
|
||||
{
|
||||
int size = (int)ReadVarint32();
|
||||
@ -572,12 +570,12 @@ namespace Thrift.Protocol
|
||||
return new TMap(getTType((byte)(keyAndValueType >> 4)), getTType((byte)(keyAndValueType & 0xf)), size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public override TList ReadListBegin()
|
||||
{
|
||||
byte size_and_type = (byte)ReadByte();
|
||||
@ -590,22 +588,22 @@ namespace Thrift.Protocol
|
||||
return new TList(type, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public override TSet ReadSetBegin()
|
||||
{
|
||||
return new TSet(ReadListBegin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a boolean off the wire. If this is a boolean field, the value should
|
||||
* already have been Read during ReadFieldBegin, so we'll just consume the
|
||||
* pre-stored value. Otherwise, Read a byte.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read a boolean off the wire. If this is a boolean field, the value should
|
||||
/// already have been Read during ReadFieldBegin, so we'll just consume the
|
||||
/// pre-stored value. Otherwise, Read a byte.
|
||||
/// </summary>
|
||||
public override Boolean ReadBool()
|
||||
{
|
||||
if (boolValue_ != null)
|
||||
@ -618,42 +616,42 @@ namespace Thrift.Protocol
|
||||
}
|
||||
|
||||
byte[] byteRawBuf = new byte[1];
|
||||
/**
|
||||
* Read a single byte off the wire. Nothing interesting here.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read a single byte off the wire. Nothing interesting here.
|
||||
/// </summary>
|
||||
public override sbyte ReadByte()
|
||||
{
|
||||
trans.ReadAll(byteRawBuf, 0, 1);
|
||||
return (sbyte)byteRawBuf[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an i16 from the wire as a zigzag varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read an i16 from the wire as a zigzag varint.
|
||||
/// </summary>
|
||||
public override short ReadI16()
|
||||
{
|
||||
return (short)zigzagToInt(ReadVarint32());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an i32 from the wire as a zigzag varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read an i32 from the wire as a zigzag varint.
|
||||
/// </summary>
|
||||
public override int ReadI32()
|
||||
{
|
||||
return zigzagToInt(ReadVarint32());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an i64 from the wire as a zigzag varint.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read an i64 from the wire as a zigzag varint.
|
||||
/// </summary>
|
||||
public override long ReadI64()
|
||||
{
|
||||
return zigzagToLong(ReadVarint64());
|
||||
}
|
||||
|
||||
/**
|
||||
* No magic here - just Read a double off the wire.
|
||||
*/
|
||||
/// <summary>
|
||||
/// No magic here - just Read a double off the wire.
|
||||
/// </summary>
|
||||
public override double ReadDouble()
|
||||
{
|
||||
byte[] longBits = new byte[8];
|
||||
@ -661,10 +659,10 @@ namespace Thrift.Protocol
|
||||
return BitConverter.Int64BitsToDouble(bytesToLong(longBits));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a byte[] (via ReadBinary), and then UTF-8 decodes it.
|
||||
*/
|
||||
public override String ReadString()
|
||||
/// <summary>
|
||||
/// Reads a byte[] (via ReadBinary), and then UTF-8 decodes it.
|
||||
/// </summary>
|
||||
public override string ReadString()
|
||||
{
|
||||
int length = (int)ReadVarint32();
|
||||
|
||||
@ -676,9 +674,9 @@ namespace Thrift.Protocol
|
||||
return Encoding.UTF8.GetString(ReadBinary(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a byte[] from the wire.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read a byte[] from the wire.
|
||||
/// </summary>
|
||||
public override byte[] ReadBinary()
|
||||
{
|
||||
int length = (int)ReadVarint32();
|
||||
@ -689,9 +687,9 @@ namespace Thrift.Protocol
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a byte[] of a known length from the wire.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read a byte[] of a known length from the wire.
|
||||
/// </summary>
|
||||
private byte[] ReadBinary(int length)
|
||||
{
|
||||
if (length == 0) return new byte[0];
|
||||
@ -715,10 +713,10 @@ namespace Thrift.Protocol
|
||||
// Internal Reading methods
|
||||
//
|
||||
|
||||
/**
|
||||
* Read an i32 from the wire as a varint. The MSB of each byte is set
|
||||
* if there is another byte to follow. This can Read up to 5 bytes.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read an i32 from the wire as a varint. The MSB of each byte is set
|
||||
/// if there is another byte to follow. This can Read up to 5 bytes.
|
||||
/// </summary>
|
||||
private uint ReadVarint32()
|
||||
{
|
||||
uint result = 0;
|
||||
@ -733,10 +731,10 @@ namespace Thrift.Protocol
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private ulong ReadVarint64()
|
||||
{
|
||||
int shift = 0;
|
||||
@ -758,27 +756,27 @@ namespace Thrift.Protocol
|
||||
// encoding helpers
|
||||
//
|
||||
|
||||
/**
|
||||
* Convert from zigzag int to int.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Convert from zigzag int to int.
|
||||
/// </summary>
|
||||
private int zigzagToInt(uint n)
|
||||
{
|
||||
return (int)(n >> 1) ^ (-(int)(n & 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from zigzag long to long.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Convert from zigzag long to long.
|
||||
/// </summary>
|
||||
private long zigzagToLong(ulong n)
|
||||
{
|
||||
return (long)(n >> 1) ^ (-(long)(n & 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private long bytesToLong(byte[] bytes)
|
||||
{
|
||||
return
|
||||
@ -802,10 +800,10 @@ namespace Thrift.Protocol
|
||||
return lowerNibble == Types.BOOLEAN_TRUE || lowerNibble == Types.BOOLEAN_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a TCompactProtocol.Types constant, convert it to its corresponding
|
||||
* TType value.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Given a TCompactProtocol.Types constant, convert it to its corresponding
|
||||
/// TType value.
|
||||
/// </summary>
|
||||
private TType getTType(byte type)
|
||||
{
|
||||
switch ((byte)(type & 0x0f))
|
||||
@ -840,9 +838,9 @@ namespace Thrift.Protocol
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a TType value, find the appropriate TCompactProtocol.Types constant.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Given a TType value, find the appropriate TCompactProtocol.Types constant.
|
||||
/// </summary>
|
||||
private byte getCompactType(TType ttype)
|
||||
{
|
||||
return ttypeToCompactType[(int)ttype];
|
||||
|
@ -29,18 +29,18 @@ namespace Thrift.Protocol
|
||||
{
|
||||
/// <summary>
|
||||
/// JSON protocol implementation for thrift.
|
||||
///
|
||||
/// <para/>
|
||||
/// This is a full-featured protocol supporting Write and Read.
|
||||
///
|
||||
/// <para/>
|
||||
/// Please see the C++ class header for a detailed description of the
|
||||
/// protocol's wire format.
|
||||
///
|
||||
/// <para/>
|
||||
/// Adapted from the Java version.
|
||||
/// </summary>
|
||||
public class TJSONProtocol : TProtocol
|
||||
{
|
||||
/// <summary>
|
||||
/// Factory for JSON protocol objects
|
||||
/// Factory for JSON protocol objects.
|
||||
/// </summary>
|
||||
public class Factory : TProtocolFactory
|
||||
{
|
||||
@ -486,7 +486,7 @@ namespace Thrift.Protocol
|
||||
private void WriteJSONInteger(long num)
|
||||
{
|
||||
context.Write();
|
||||
String str = num.ToString();
|
||||
string str = num.ToString();
|
||||
|
||||
bool escapeNum = context.EscapeNumbers();
|
||||
if (escapeNum)
|
||||
@ -505,7 +505,7 @@ namespace Thrift.Protocol
|
||||
private void WriteJSONDouble(double num)
|
||||
{
|
||||
context.Write();
|
||||
String str = num.ToString("G17", CultureInfo.InvariantCulture);
|
||||
string str = num.ToString("G17", CultureInfo.InvariantCulture);
|
||||
bool special = false;
|
||||
|
||||
switch (str[0])
|
||||
@ -698,7 +698,7 @@ namespace Thrift.Protocol
|
||||
WriteJSONDouble(dub);
|
||||
}
|
||||
|
||||
public override void WriteString(String str)
|
||||
public override void WriteString(string str)
|
||||
{
|
||||
byte[] b = utf8Encoding.GetBytes(str);
|
||||
WriteJSONString(b);
|
||||
@ -833,8 +833,8 @@ namespace Thrift.Protocol
|
||||
/// <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()
|
||||
/// </summary>
|
||||
private string ReadJSONNumericChars()
|
||||
{
|
||||
StringBuilder strbld = new StringBuilder();
|
||||
while (true)
|
||||
@ -859,7 +859,7 @@ namespace Thrift.Protocol
|
||||
{
|
||||
ReadJSONSyntaxChar(QUOTE);
|
||||
}
|
||||
String str = ReadJSONNumericChars();
|
||||
string str = ReadJSONNumericChars();
|
||||
if (context.EscapeNumbers())
|
||||
{
|
||||
ReadJSONSyntaxChar(QUOTE);
|
||||
@ -915,7 +915,7 @@ namespace Thrift.Protocol
|
||||
}
|
||||
}
|
||||
|
||||
//<summary>
|
||||
/// <summary>
|
||||
/// Read in a JSON string containing base-64 encoded data and decode it.
|
||||
/// </summary>
|
||||
private byte[] ReadJSONBase64()
|
||||
@ -1108,7 +1108,7 @@ namespace Thrift.Protocol
|
||||
return ReadJSONDouble();
|
||||
}
|
||||
|
||||
public override String ReadString()
|
||||
public override string ReadString()
|
||||
{
|
||||
var buf = ReadJSONString(false);
|
||||
return utf8Encoding.GetString(buf, 0, buf.Length);
|
||||
|
@ -29,42 +29,45 @@ using System.IO;
|
||||
|
||||
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,
|
||||
* as shown in the following example:
|
||||
*
|
||||
* TMultiplexedProcessor processor = new TMultiplexedProcessor();
|
||||
*
|
||||
* processor.registerProcessor(
|
||||
* "Calculator",
|
||||
* new Calculator.Processor(new CalculatorHandler()));
|
||||
*
|
||||
* processor.registerProcessor(
|
||||
* "WeatherReport",
|
||||
* new WeatherReport.Processor(new WeatherReportHandler()));
|
||||
*
|
||||
* TServerTransport t = new TServerSocket(9090);
|
||||
* TSimpleServer server = new TSimpleServer(processor, t);
|
||||
*
|
||||
* server.serve();
|
||||
*/
|
||||
/// <summary>
|
||||
/// <see cref="TMultiplexedProcessor"/> is a <see cref="TProcessor"/> allowing a single <see cref="Thrift.Server.TServer"/>
|
||||
/// to provide multiple services.
|
||||
/// <para/>
|
||||
/// To do so, you instantiate the processor and then register additional processors with it,
|
||||
/// as shown in the following example:
|
||||
/// <para/>
|
||||
/// <code>
|
||||
/// TMultiplexedProcessor processor = new TMultiplexedProcessor();
|
||||
///
|
||||
/// processor.registerProcessor(
|
||||
/// "Calculator",
|
||||
/// new Calculator.Processor(new CalculatorHandler()));
|
||||
///
|
||||
/// processor.registerProcessor(
|
||||
/// "WeatherReport",
|
||||
/// new WeatherReport.Processor(new WeatherReportHandler()));
|
||||
///
|
||||
/// TServerTransport t = new TServerSocket(9090);
|
||||
/// TSimpleServer server = new TSimpleServer(processor, t);
|
||||
///
|
||||
/// server.serve();
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public class TMultiplexedProcessor : TProcessor
|
||||
{
|
||||
private Dictionary<String,TProcessor> ServiceProcessorMap = new Dictionary<String,TProcessor>();
|
||||
private Dictionary<string, TProcessor> ServiceProcessorMap = new Dictionary<string, TProcessor>();
|
||||
|
||||
/**
|
||||
* '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:
|
||||
* - 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, usually referred to as "handlers",
|
||||
* e.g. WeatherReportHandler implementing WeatherReport.Iface.
|
||||
*/
|
||||
public void RegisterProcessor(String serviceName, TProcessor processor)
|
||||
/// <summary>
|
||||
/// '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:
|
||||
/// - 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, usually referred to as "handlers",
|
||||
/// e.g. WeatherReportHandler implementing WeatherReport.Iface.
|
||||
/// </summary>
|
||||
public void RegisterProcessor(string serviceName, TProcessor processor)
|
||||
{
|
||||
ServiceProcessorMap.Add(serviceName, processor);
|
||||
}
|
||||
@ -83,20 +86,20 @@ namespace Thrift.Protocol
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This implementation of process performs the following steps:
|
||||
*
|
||||
* - Read the beginning of the message.
|
||||
* - Extract the service name from the message.
|
||||
* - 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.
|
||||
*/
|
||||
/// <summary>
|
||||
/// This implementation of process performs the following steps:
|
||||
///
|
||||
/// - Read the beginning of the message.
|
||||
/// - Extract the service name from the message.
|
||||
/// - 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.
|
||||
/// <para/>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public bool Process(TProtocol iprot, TProtocol oprot)
|
||||
{
|
||||
/* Use the actual underlying protocol (e.g. TBinaryProtocol) to read the
|
||||
@ -155,11 +158,11 @@ namespace Thrift.Protocol
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Our goal was to work with any protocol. In order to do that, we needed
|
||||
* to allow them to call readMessageBegin() and get a TMessage in exactly
|
||||
* the standard format, without the service name prepended to TMessage.name.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Our goal was to work with any protocol. In order to do that, we needed
|
||||
/// to allow them to call readMessageBegin() and get a TMessage in exactly
|
||||
/// the standard format, without the service name prepended to TMessage.name.
|
||||
/// </summary>
|
||||
private class StoredMessageProtocol : TProtocolDecorator
|
||||
{
|
||||
TMessage MsgBegin;
|
||||
|
@ -29,60 +29,59 @@ using System.Collections.Generic;
|
||||
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
|
||||
* to the function name during function calls.
|
||||
*
|
||||
* 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");
|
||||
* Calculator.Client service = new Calculator.Client(mp);
|
||||
*
|
||||
* TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "WeatherReport");
|
||||
* WeatherReport.Client service2 = new WeatherReport.Client(mp2);
|
||||
*
|
||||
* System.out.println(service.add(2,2));
|
||||
* System.out.println(service2.getTemperature());
|
||||
*
|
||||
*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <para/>
|
||||
/// NOTE: THIS IS NOT TO BE USED BY SERVERS.
|
||||
/// On the server, use TMultiplexedProcessor to handle requests from a multiplexing client.
|
||||
/// <para/>
|
||||
/// This example uses a single socket transport to invoke two services:
|
||||
/// <code>
|
||||
/// TSocket transport = new TSocket("localhost", 9090);
|
||||
/// transport.open();
|
||||
///
|
||||
/// TBinaryProtocol protocol = new TBinaryProtocol(transport);
|
||||
///
|
||||
/// TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "Calculator");
|
||||
/// Calculator.Client service = new Calculator.Client(mp);
|
||||
///
|
||||
/// TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "WeatherReport");
|
||||
/// WeatherReport.Client service2 = new WeatherReport.Client(mp2);
|
||||
///
|
||||
/// System.out.println(service.add(2,2));
|
||||
/// System.out.println(service2.getTemperature());
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public class TMultiplexedProtocol : TProtocolDecorator
|
||||
{
|
||||
|
||||
/** Used to delimit the service name from the function name */
|
||||
public static String SEPARATOR = ":";
|
||||
/// <summary>
|
||||
/// Used to delimit the service name from the function name.
|
||||
/// </summary>
|
||||
public static string SEPARATOR = ":";
|
||||
|
||||
private String ServiceName;
|
||||
private string ServiceName;
|
||||
|
||||
/**
|
||||
* Wrap the specified protocol, allowing it to be used to communicate with a
|
||||
* multiplexing server. The <code>serviceName</code> is required as it is
|
||||
* prepended to the message header so that the multiplexing server can broker
|
||||
* the function call to the proper service.
|
||||
*
|
||||
* Args:
|
||||
* 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)
|
||||
/// <summary>
|
||||
/// Wrap the specified protocol, allowing it to be used to communicate with a
|
||||
/// multiplexing server. The <paramref name="serviceName"/> is required as it is
|
||||
/// prepended to the message header so that the multiplexing server can broker
|
||||
/// the function call to the proper service.
|
||||
/// </summary>
|
||||
/// <param name="protocol">Your communication protocol of choice, e.g. <see cref="TBinaryProtocol"/>.</param>
|
||||
/// <param name="serviceName">The service name of the service communicating via this protocol.</param>
|
||||
public TMultiplexedProtocol(TProtocol protocol, string serviceName)
|
||||
: base(protocol)
|
||||
{
|
||||
ServiceName = serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
|
||||
* Args:
|
||||
* tMessage The original message.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
|
||||
/// </summary>
|
||||
/// <param name="tMessage">The original message.</param>
|
||||
public override void WriteMessageBegin(TMessage tMessage)
|
||||
{
|
||||
switch (tMessage.Type)
|
||||
@ -101,5 +100,4 @@ namespace Thrift.Protocol
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -108,7 +108,8 @@ namespace Thrift.Protocol
|
||||
public abstract void WriteI32(int i32);
|
||||
public abstract void WriteI64(long i64);
|
||||
public abstract void WriteDouble(double d);
|
||||
public virtual void WriteString(string s) {
|
||||
public virtual void WriteString(string s)
|
||||
{
|
||||
WriteBinary(Encoding.UTF8.GetBytes(s));
|
||||
}
|
||||
public abstract void WriteBinary(byte[] b);
|
||||
@ -131,7 +132,8 @@ namespace Thrift.Protocol
|
||||
public abstract int ReadI32();
|
||||
public abstract long ReadI64();
|
||||
public abstract double ReadDouble();
|
||||
public virtual string ReadString() {
|
||||
public virtual string ReadString()
|
||||
{
|
||||
var buf = ReadBinary();
|
||||
return Encoding.UTF8.GetString(buf, 0, buf.Length);
|
||||
}
|
||||
|
@ -28,24 +28,23 @@ using System.Collections.Generic;
|
||||
|
||||
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,
|
||||
* it does not modify the behaviour of the enclosed TProtocol.
|
||||
*
|
||||
* See p.175 of Design Patterns (by Gamma et al.)
|
||||
* See TMultiplexedProtocol
|
||||
*/
|
||||
/// <summary>
|
||||
/// <see cref="TProtocolDecorator"/> forwards all requests to an enclosed <see cref="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 <see cref="TProtocol"/>.
|
||||
/// <para/>
|
||||
/// See p.175 of Design Patterns (by Gamma et al.)
|
||||
/// </summary>
|
||||
/// <seealso cref="TMultiplexedProtocol"/>
|
||||
public abstract class TProtocolDecorator : TProtocol
|
||||
{
|
||||
private TProtocol WrappedProtocol;
|
||||
|
||||
/**
|
||||
* Encloses the specified protocol.
|
||||
* @param protocol All operations will be forward to this protocol. Must be non-null.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Encloses the specified protocol.
|
||||
/// </summary>
|
||||
/// <param name="protocol">All operations will be forward to this protocol. Must be non-null.</param>
|
||||
public TProtocolDecorator(TProtocol protocol)
|
||||
: base(protocol.Transport)
|
||||
{
|
||||
@ -148,7 +147,7 @@ namespace Thrift.Protocol
|
||||
WrappedProtocol.WriteDouble(v);
|
||||
}
|
||||
|
||||
public override void WriteString(String s)
|
||||
public override void WriteString(string s)
|
||||
{
|
||||
WrappedProtocol.WriteString(s);
|
||||
}
|
||||
@ -248,7 +247,7 @@ namespace Thrift.Protocol
|
||||
return WrappedProtocol.ReadDouble();
|
||||
}
|
||||
|
||||
public override String ReadString()
|
||||
public override string ReadString()
|
||||
{
|
||||
return WrappedProtocol.ReadString();
|
||||
}
|
||||
|
@ -48,13 +48,13 @@ namespace Thrift.Protocol
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
public TProtocolException(int type, String message)
|
||||
public TProtocolException(int type, string message)
|
||||
: base(message)
|
||||
{
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
public TProtocolException(String message)
|
||||
public TProtocolException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
@ -98,7 +98,6 @@ namespace Thrift.Protocol
|
||||
default:
|
||||
throw new TProtocolException(TProtocolException.INVALID_DATA, "Unknown data type " + type.ToString("d"));
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -26,25 +26,28 @@ using System;
|
||||
namespace Thrift.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface implemented by server users to handle events from the server
|
||||
/// Interface implemented by server users to handle events from the server.
|
||||
/// </summary>
|
||||
public interface TServerEventHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Called before the server begins */
|
||||
/// Called before the server begins.
|
||||
/// </summary>
|
||||
void preServe();
|
||||
|
||||
/// <summary>
|
||||
/// Called when a new client has connected and is about to being processing */
|
||||
/// Called when a new client has connected and is about to being processing.
|
||||
/// </summary>
|
||||
Object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output);
|
||||
object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a client has finished request-handling to delete server context */
|
||||
/// Called when a client has finished request-handling to delete server context.
|
||||
/// </summary>
|
||||
void deleteContext(Object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output);
|
||||
void deleteContext(object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a client is about to call the processor */
|
||||
/// Called when a client is about to call the processor.
|
||||
/// </summary>
|
||||
void processContext(Object serverContext, Thrift.Transport.TTransport transport);
|
||||
void processContext(object serverContext, Thrift.Transport.TTransport transport);
|
||||
};
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ using Thrift.Protocol;
|
||||
namespace Thrift.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple single-threaded server for testing
|
||||
/// Simple single-threaded server for testing.
|
||||
/// </summary>
|
||||
public class TSimpleServer : TServer
|
||||
{
|
||||
@ -112,7 +112,7 @@ namespace Thrift.Server
|
||||
TTransport outputTransport = null;
|
||||
TProtocol inputProtocol = null;
|
||||
TProtocol outputProtocol = null;
|
||||
Object connectionContext = null;
|
||||
object connectionContext = null;
|
||||
try
|
||||
{
|
||||
using (client = serverTransport.Accept())
|
||||
|
@ -29,7 +29,7 @@ using Thrift.Transport;
|
||||
namespace Thrift.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Server that uses C# built-in ThreadPool to spawn threads when handling requests
|
||||
/// Server that uses C# built-in ThreadPool to spawn threads when handling requests.
|
||||
/// </summary>
|
||||
public class TThreadPoolServer : TServer
|
||||
{
|
||||
@ -154,7 +154,7 @@ namespace Thrift.Server
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Use new ThreadPool thread for each new client connection
|
||||
/// Use new ThreadPool thread for each new client connection.
|
||||
/// </summary>
|
||||
public override void Serve()
|
||||
{
|
||||
@ -210,7 +210,7 @@ namespace Thrift.Server
|
||||
/// threadContext will be a TTransport instance
|
||||
/// </summary>
|
||||
/// <param name="threadContext"></param>
|
||||
private void Execute(Object threadContext)
|
||||
private void Execute(object threadContext)
|
||||
{
|
||||
using (TTransport client = (TTransport)threadContext)
|
||||
{
|
||||
@ -219,7 +219,7 @@ namespace Thrift.Server
|
||||
TTransport outputTransport = null;
|
||||
TProtocol inputProtocol = null;
|
||||
TProtocol outputProtocol = null;
|
||||
Object connectionContext = null;
|
||||
object connectionContext = null;
|
||||
try
|
||||
{
|
||||
try
|
||||
|
@ -27,7 +27,7 @@ using Thrift.Transport;
|
||||
namespace Thrift.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Server that uses C# threads (as opposed to the ThreadPool) when handling requests
|
||||
/// Server that uses C# threads (as opposed to the ThreadPool) when handling requests.
|
||||
/// </summary>
|
||||
public class TThreadedServer : TServer
|
||||
{
|
||||
@ -40,7 +40,8 @@ namespace Thrift.Server
|
||||
private object clientLock;
|
||||
private Thread workerThread;
|
||||
|
||||
public int ClientThreadsCount {
|
||||
public int ClientThreadsCount
|
||||
{
|
||||
get { return clientThreads.Count; }
|
||||
}
|
||||
|
||||
@ -99,7 +100,7 @@ namespace Thrift.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use new Thread for each new client connection. block until numConnections < maxThreads
|
||||
/// Use new Thread for each new client connection. block until numConnections < maxThreads.
|
||||
/// </summary>
|
||||
public override void Serve()
|
||||
{
|
||||
@ -159,9 +160,7 @@ namespace Thrift.Server
|
||||
|
||||
/// <summary>
|
||||
/// Loops on processing a client forever
|
||||
/// threadContext will be a TTransport instance
|
||||
/// </summary>
|
||||
/// <param name="threadContext"></param>
|
||||
private void Execute()
|
||||
{
|
||||
while (!stop)
|
||||
@ -190,7 +189,7 @@ namespace Thrift.Server
|
||||
}
|
||||
}
|
||||
|
||||
private void ClientWorker(Object context)
|
||||
private void ClientWorker(object context)
|
||||
{
|
||||
using (TTransport client = (TTransport)context)
|
||||
{
|
||||
@ -199,7 +198,7 @@ namespace Thrift.Server
|
||||
TTransport outputTransport = null;
|
||||
TProtocol inputProtocol = null;
|
||||
TProtocol outputProtocol = null;
|
||||
Object connectionContext = null;
|
||||
object connectionContext = null;
|
||||
try
|
||||
{
|
||||
try
|
||||
|
@ -103,7 +103,7 @@ namespace Thrift
|
||||
|
||||
oprot.WriteStructBegin(struc);
|
||||
|
||||
if (!String.IsNullOrEmpty(Message))
|
||||
if (!string.IsNullOrEmpty(Message))
|
||||
{
|
||||
field.Name = "message";
|
||||
field.Type = TType.String;
|
||||
|
@ -30,7 +30,6 @@ using System.IO.Compression;
|
||||
|
||||
namespace Thrift.Transport
|
||||
{
|
||||
|
||||
public class THttpClient : TTransport, IDisposable
|
||||
{
|
||||
private readonly Uri uri;
|
||||
@ -43,7 +42,7 @@ namespace Thrift.Transport
|
||||
|
||||
private int readTimeout = 30000;
|
||||
|
||||
private IDictionary<String, String> customHeaders = new Dictionary<string, string>();
|
||||
private IDictionary<string, string> customHeaders = new Dictionary<string, string>();
|
||||
|
||||
#if !SILVERLIGHT
|
||||
private IWebProxy proxy = WebRequest.DefaultWebProxy;
|
||||
@ -76,7 +75,7 @@ namespace Thrift.Transport
|
||||
}
|
||||
}
|
||||
|
||||
public IDictionary<String, String> CustomHeaders
|
||||
public IDictionary<string, string> CustomHeaders
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -338,7 +337,8 @@ namespace Thrift.Transport
|
||||
{
|
||||
throw flushAsyncResult.AsyncException;
|
||||
}
|
||||
} finally
|
||||
}
|
||||
finally
|
||||
{
|
||||
outputStream = new MemoryStream();
|
||||
}
|
||||
@ -387,9 +387,9 @@ namespace Thrift.Transport
|
||||
private volatile Boolean _isCompleted;
|
||||
private ManualResetEvent _evt;
|
||||
private readonly AsyncCallback _cbMethod;
|
||||
private readonly Object _state;
|
||||
private readonly object _state;
|
||||
|
||||
public FlushAsyncResult(AsyncCallback cbMethod, Object state)
|
||||
public FlushAsyncResult(AsyncCallback cbMethod, object state)
|
||||
{
|
||||
_cbMethod = cbMethod;
|
||||
_state = state;
|
||||
@ -415,7 +415,7 @@ namespace Thrift.Transport
|
||||
{
|
||||
get { return _isCompleted; }
|
||||
}
|
||||
private readonly Object _locker = new Object();
|
||||
private readonly object _locker = new object();
|
||||
private ManualResetEvent GetEvtHandle()
|
||||
{
|
||||
lock (_locker)
|
||||
|
@ -22,45 +22,56 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using Thrift.Protocol;
|
||||
|
||||
namespace Thrift.Transport {
|
||||
public class TMemoryBuffer : TTransport {
|
||||
namespace Thrift.Transport
|
||||
{
|
||||
public class TMemoryBuffer : TTransport
|
||||
{
|
||||
|
||||
private readonly MemoryStream byteStream;
|
||||
|
||||
public TMemoryBuffer() {
|
||||
public TMemoryBuffer()
|
||||
{
|
||||
byteStream = new MemoryStream();
|
||||
}
|
||||
|
||||
public TMemoryBuffer(byte[] buf) {
|
||||
public TMemoryBuffer(byte[] buf)
|
||||
{
|
||||
byteStream = new MemoryStream(buf);
|
||||
}
|
||||
|
||||
public override void Open() {
|
||||
public override void Open()
|
||||
{
|
||||
/** do nothing **/
|
||||
}
|
||||
|
||||
public override void Close() {
|
||||
public override void Close()
|
||||
{
|
||||
/** do nothing **/
|
||||
}
|
||||
|
||||
public override int Read(byte[] buf, int off, int 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) {
|
||||
public override void Write(byte[] buf, int off, int len)
|
||||
{
|
||||
byteStream.Write(buf, off, len);
|
||||
}
|
||||
|
||||
public byte[] GetBuffer() {
|
||||
public byte[] GetBuffer()
|
||||
{
|
||||
return byteStream.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public override bool IsOpen {
|
||||
public override bool IsOpen
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public static byte[] Serialize(TAbstractBase s) {
|
||||
public static byte[] Serialize(TAbstractBase s)
|
||||
{
|
||||
var t = new TMemoryBuffer();
|
||||
var p = new TBinaryProtocol(t);
|
||||
|
||||
@ -69,15 +80,19 @@ namespace Thrift.Transport {
|
||||
return t.GetBuffer();
|
||||
}
|
||||
|
||||
public static T DeSerialize<T>(byte[] buf) where T : TAbstractBase {
|
||||
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))) {
|
||||
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 {
|
||||
}
|
||||
else
|
||||
{
|
||||
var method = typeof(T).GetMethod("Read", BindingFlags.Static | BindingFlags.Public);
|
||||
return (T)method.Invoke(null, new object[] { p });
|
||||
}
|
||||
@ -86,9 +101,12 @@ namespace Thrift.Transport {
|
||||
private bool _IsDisposed;
|
||||
|
||||
// IDisposable
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (!_IsDisposed) {
|
||||
if (disposing) {
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!_IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (byteStream != null)
|
||||
byteStream.Dispose();
|
||||
}
|
||||
|
@ -29,54 +29,54 @@ namespace Thrift.Transport
|
||||
{
|
||||
public class TServerSocket : TServerTransport
|
||||
{
|
||||
/**
|
||||
* Underlying server with socket
|
||||
*/
|
||||
/// <summary>
|
||||
/// Underlying server with socket.
|
||||
/// </summary>
|
||||
private TcpListener server = null;
|
||||
|
||||
/**
|
||||
* Port to listen on
|
||||
*/
|
||||
/// <summary>
|
||||
/// Port to listen on.
|
||||
/// </summary>
|
||||
private int port = 0;
|
||||
|
||||
/**
|
||||
* Timeout for client sockets from accept
|
||||
*/
|
||||
/// <summary>
|
||||
/// Timeout for client sockets from accept.
|
||||
/// </summary>
|
||||
private int clientTimeout = 0;
|
||||
|
||||
/**
|
||||
* Whether or not to wrap new TSocket connections in buffers
|
||||
*/
|
||||
/// <summary>
|
||||
/// Whether or not to wrap new TSocket connections in buffers.
|
||||
/// </summary>
|
||||
private bool useBufferedSockets = false;
|
||||
|
||||
/**
|
||||
* Creates a server socket from underlying socket object
|
||||
*/
|
||||
/// <summary>
|
||||
/// Creates a server socket from underlying socket object.
|
||||
/// </summary>
|
||||
public TServerSocket(TcpListener listener)
|
||||
: this(listener, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a server socket from underlying socket object
|
||||
*/
|
||||
/// <summary>
|
||||
/// Creates a server socket from underlying socket object.
|
||||
/// </summary>
|
||||
public TServerSocket(TcpListener listener, int clientTimeout)
|
||||
{
|
||||
this.server = listener;
|
||||
this.clientTimeout = clientTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates just a port listening server socket
|
||||
*/
|
||||
/// <summary>
|
||||
/// Creates just a port listening server socket.
|
||||
/// </summary>
|
||||
public TServerSocket(int port)
|
||||
: this(port, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates just a port listening server socket
|
||||
*/
|
||||
/// <summary>
|
||||
/// Creates just a port listening server socket.
|
||||
/// </summary>
|
||||
public TServerSocket(int port, int clientTimeout)
|
||||
: this(port, clientTimeout, false)
|
||||
{
|
||||
|
@ -34,7 +34,8 @@ namespace Thrift.Transport
|
||||
public TTransport Accept()
|
||||
{
|
||||
TTransport transport = AcceptImpl();
|
||||
if (transport == null) {
|
||||
if (transport == null)
|
||||
{
|
||||
throw new TTransportException("accept() may not return NULL");
|
||||
}
|
||||
return transport;
|
||||
|
@ -112,7 +112,7 @@ namespace Thrift.Transport
|
||||
throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(host))
|
||||
if (string.IsNullOrEmpty(host))
|
||||
{
|
||||
throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
|
||||
}
|
||||
@ -282,9 +282,9 @@ namespace Thrift.Transport
|
||||
private volatile Boolean _isCompleted;
|
||||
private ManualResetEvent _evt;
|
||||
private readonly AsyncCallback _cbMethod;
|
||||
private readonly Object _state;
|
||||
private readonly object _state;
|
||||
|
||||
public FlushAsyncResult(AsyncCallback cbMethod, Object state)
|
||||
public FlushAsyncResult(AsyncCallback cbMethod, object state)
|
||||
{
|
||||
_cbMethod = cbMethod;
|
||||
_state = state;
|
||||
@ -314,7 +314,7 @@ namespace Thrift.Transport
|
||||
get { return _isCompleted; }
|
||||
}
|
||||
|
||||
private readonly Object _locker = new Object();
|
||||
private readonly object _locker = new object();
|
||||
|
||||
private ManualResetEvent GetEvtHandle()
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ namespace Thrift.Transport
|
||||
throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(host))
|
||||
if (string.IsNullOrEmpty(host))
|
||||
{
|
||||
throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
|
||||
}
|
||||
@ -184,14 +184,18 @@ namespace Thrift.Transport
|
||||
|
||||
if (hlp.DoCleanup)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
asyncres.AsyncWaitHandle.Close();
|
||||
} catch (Exception) {}
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
if (hlp.Client is IDisposable)
|
||||
((IDisposable)hlp.Client).Dispose();
|
||||
} catch (Exception) {}
|
||||
}
|
||||
catch (Exception) { }
|
||||
hlp.Client = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,27 @@
|
||||
using System;
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Contains some contributions under the Thrift Software License.
|
||||
* Please see doc/old-thrift-license.txt in the Thrift distribution for
|
||||
* details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
@ -10,16 +33,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Thrift.Transport
|
||||
{
|
||||
/**
|
||||
* PropertyInfo for the DualMode property of the System.Net.Sockets.Socket class. Used to determine if the sockets are capable of
|
||||
* automatic IPv4 and IPv6 handling. If DualMode is present the sockets automatically handle IPv4 and IPv6 connections.
|
||||
* If the DualMode is not available the system configuration determines whether IPv4 or IPv6 is used.
|
||||
*/
|
||||
/// <summary>
|
||||
/// PropertyInfo for the DualMode property of the System.Net.Sockets.Socket class. Used to determine if the sockets are capable of
|
||||
/// automatic IPv4 and IPv6 handling. If DualMode is present the sockets automatically handle IPv4 and IPv6 connections.
|
||||
/// If the DualMode is not available the system configuration determines whether IPv4 or IPv6 is used.
|
||||
/// </summary>
|
||||
internal static class TSocketVersionizer
|
||||
{
|
||||
/*
|
||||
* Creates a TcpClient according to the capabilitites of the used framework
|
||||
*/
|
||||
/// <summary>
|
||||
/// Creates a TcpClient according to the capabilitites of the used framework
|
||||
/// </summary>
|
||||
internal static TcpClient CreateTcpClient()
|
||||
{
|
||||
TcpClient client = null;
|
||||
@ -34,9 +57,9 @@ namespace Thrift.Transport
|
||||
return client;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a TcpListener according to the capabilitites of the used framework
|
||||
*/
|
||||
/// <summary>
|
||||
/// Creates a TcpListener according to the capabilitites of the used framework.
|
||||
/// </summary>
|
||||
internal static TcpListener CreateTcpListener(Int32 port)
|
||||
{
|
||||
TcpListener listener = null;
|
||||
|
@ -263,7 +263,7 @@ namespace Thrift.Transport
|
||||
/// <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>
|
||||
/// <param name="sslValidationErrors">An enum, which lists all the errors from the .NET certificate check.</param>
|
||||
/// <returns></returns>
|
||||
private bool DefaultCertificateValidator(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslValidationErrors)
|
||||
{
|
||||
@ -280,7 +280,7 @@ namespace Thrift.Transport
|
||||
throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(host))
|
||||
if (string.IsNullOrEmpty(host))
|
||||
{
|
||||
throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ using System;
|
||||
namespace Thrift.Transport
|
||||
{
|
||||
/// <summary>
|
||||
/// From Mark Slee & Aditya Agarwal of Facebook:
|
||||
/// 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
|
||||
|
Loading…
Reference in New Issue
Block a user