public override T Deserialize <T>(CacheItem item) { return((T)base.Deserialize(item)); }
public GetResponse(string key, ushort flags, ulong casValue, byte[] data, int offset, int count) { Key = key; CasValue = casValue; Item = new CacheItem(flags, new ArraySegment<byte>(data, offset, count)); }
object ITranscoder.Deserialize(CacheItem item) { if (item.Flag == RawDataFlag) { ArraySegment<byte> tmp = item.Data; if (tmp.Count == tmp.Array.Length) return tmp.Array; // we should never arrive here, but it's better to be safe than sorry byte[] retval = new byte[tmp.Count]; Array.Copy(tmp.Array, tmp.Offset, retval, 0, tmp.Count); return retval; } TypeCode code = (TypeCode)(item.Flag & 0x00ff); if (code == TypeCode.Empty) return null; byte[] data = item.Data.Array; int offset = item.Data.Offset; int count = item.Data.Count; switch (code) { case TypeCode.String: return Encoding.UTF8.GetString(data, offset, count); case TypeCode.Boolean: return BitConverter.ToBoolean(data, offset); case TypeCode.Int16: return BitConverter.ToInt16(data, offset); case TypeCode.Int32: return BitConverter.ToInt32(data, offset); case TypeCode.Int64: return BitConverter.ToInt64(data, offset); case TypeCode.UInt16: return BitConverter.ToUInt64(data, offset); case TypeCode.UInt32: return BitConverter.ToUInt32(data, offset); case TypeCode.UInt64: return BitConverter.ToUInt64(data, offset); case TypeCode.Char: return BitConverter.ToChar(data, offset); case TypeCode.DateTime: return DateTime.FromBinary(BitConverter.ToInt64(data, offset)); case TypeCode.Double: return BitConverter.ToDouble(data, offset); case TypeCode.Single: return BitConverter.ToSingle(data, offset); case TypeCode.Object: using (MemoryStream ms = new MemoryStream(data, offset, count)) { return new BinaryFormatter().Deserialize(ms); } default: throw new InvalidOperationException("Unknown TypeCode was returned: " + code); } }