Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
updated to thrift 0.9.0
  • Loading branch information
nberardi committed Oct 22, 2012
1 parent ca6f2d4 commit 4cd5b26
Show file tree
Hide file tree
Showing 18 changed files with 1,331 additions and 115 deletions.
27 changes: 22 additions & 5 deletions src/Thrift/Collections/THashSet.cs
Expand Up @@ -21,13 +21,24 @@
using System.Collections;
using System.Collections.Generic;

#if SILVERLIGHT
using System.Runtime.Serialization;
#endif

namespace Thrift.Collections
{
[Serializable]
#if SILVERLIGHT
[DataContract]
#else
[Serializable]
#endif
public class THashSet<T> : ICollection<T>
{
#if NET_2_0
TDictSet<T> set = new TDictSet<T>();
#if NET_2_0 || SILVERLIGHT
#if SILVERLIGHT
[DataMember]
#endif
TDictSet<T> set = new TDictSet<T>();
#else
HashSet<T> set = new HashSet<T>();
#endif
Expand Down Expand Up @@ -76,9 +87,15 @@ public bool Remove(T item)
return set.Remove(item);
}

#if NET_2_0
private class TDictSet<V> : ICollection<V>
#if NET_2_0 || SILVERLIGHT
#if SILVERLIGHT
[DataContract]
#endif
private class TDictSet<V> : ICollection<V>
{
#if SILVERLIGHT
[DataMember]
#endif
Dictionary<V, TDictSet<V>> dict = new Dictionary<V, TDictSet<V>>();

public int Count
Expand Down
10 changes: 5 additions & 5 deletions src/Thrift/Protocol/TBase64Utils.cs
Expand Up @@ -34,26 +34,26 @@ internal static class TBase64Utils
{
dst[dstOff + 1] =
(byte)ENCODE_TABLE[
((src[srcOff] << 4) + (src[srcOff + 1] >> 4)) & 0x3F];
((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)];
dst[dstOff + 2] =
(byte)ENCODE_TABLE[
((src[srcOff + 1] << 2) + (src[srcOff + 2] >> 6)) & 0x3F];
((src[srcOff + 1] << 2) & 0x3C) | ((src[srcOff + 2] >> 6) & 0x03)];
dst[dstOff + 3] =
(byte)ENCODE_TABLE[src[srcOff + 2] & 0x3F];
}
else if (len == 2)
{
dst[dstOff + 1] =
(byte)ENCODE_TABLE[
((src[srcOff] << 4) + (src[srcOff + 1] >> 4)) & 0x3F];
((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)];
dst[dstOff + 2] =
(byte)ENCODE_TABLE[(src[srcOff + 1] << 2) & 0x3F];
(byte)ENCODE_TABLE[(src[srcOff + 1] << 2) & 0x3C];

}
else
{ // len == 1) {
dst[dstOff + 1] =
(byte)ENCODE_TABLE[(src[srcOff] << 4) & 0x3F];
(byte)ENCODE_TABLE[(src[srcOff] << 4) & 0x30];
}
}

Expand Down
26 changes: 22 additions & 4 deletions src/Thrift/Protocol/TBinaryProtocol.cs
Expand Up @@ -201,7 +201,12 @@ public override void WriteI64(long i64)

public override void WriteDouble(double d)
{
#if !SILVERLIGHT
WriteI64(BitConverter.DoubleToInt64Bits(d));
#else
var bytes = BitConverter.GetBytes(d);
WriteI64(BitConverter.ToInt64(bytes, 0));
#endif
}

public override void WriteBinary(byte[] b)
Expand Down Expand Up @@ -342,13 +347,26 @@ public override int ReadI32()
public override long ReadI64()
{
ReadAll(i64in, 0, 8);
return (long)(((long)(i64in[0] & 0xff) << 56) | ((long)(i64in[1] & 0xff) << 48) | ((long)(i64in[2] & 0xff) << 40) | ((long)(i64in[3] & 0xff) << 32) |
((long)(i64in[4] & 0xff) << 24) | ((long)(i64in[5] & 0xff) << 16) | ((long)(i64in[6] & 0xff) << 8) | ((long)(i64in[7] & 0xff)));
}
return (long)(
(ulong)((ulong)(i64in[0] & 0xff) << 56) |
(ulong)((ulong)(i64in[1] & 0xff) << 48) |
(ulong)((ulong)(i64in[2] & 0xff) << 40) |
(ulong)((ulong)(i64in[3] & 0xff) << 32) |
(ulong)((ulong)(i64in[4] & 0xff) << 24) |
(ulong)((ulong)(i64in[5] & 0xff) << 16) |
(ulong)((ulong)(i64in[6] & 0xff) << 8) |
(ulong)((ulong)(i64in[7] & 0xff)));
}

public override double ReadDouble()
{
#if !SILVERLIGHT
return BitConverter.Int64BitsToDouble(ReadI64());
#else
var value = ReadI64();
var bytes = BitConverter.GetBytes(value);
return BitConverter.ToDouble(bytes, 0);
#endif
}

public void SetReadLength(int readLength)
Expand Down Expand Up @@ -382,7 +400,7 @@ private string ReadStringBody(int size)
CheckReadLength(size);
byte[] buf = new byte[size];
trans.ReadAll(buf, 0, size);
return Encoding.UTF8.GetString(buf);
return Encoding.UTF8.GetString(buf, 0, buf.Length);
}

private int ReadAll(byte[] buf, int off, int len)
Expand Down

0 comments on commit 4cd5b26

Please sign in to comment.