Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DefaultSerializer now supports bytes.

  • Loading branch information...
commit 993b61dca7a4ab92103ed88c8037de2e0390ec9d 1 parent 278d842
@xero-admin xero-admin authored committed
View
20 Enyim.Caching.Tests/MemcachedClientGetTests.cs
@@ -78,6 +78,26 @@ public void When_Getting_Multiple_Keys_Result_Is_Successful()
Assert.That(dict[key].Success, Is.True, "Get failed for key: " + key);
}
}
+
+ [Test]
+ public void When_Getting_Byte_Result_Is_Successful()
+ {
+ var key = GetUniqueKey("Get");
+ const byte expectedValue = 1;
+ Store(key: key, value: expectedValue);
+ var getResult = _Client.ExecuteGet(key);
+ GetAssertPass(getResult, expectedValue);
+ }
+
+ [Test]
+ public void When_Getting_SByte_Result_Is_Successful()
+ {
+ var key = GetUniqueKey("Get");
+ const sbyte expectedValue = 1;
+ Store(key: key, value: expectedValue);
+ var getResult = _Client.ExecuteGet(key);
+ GetAssertPass(getResult, expectedValue);
+ }
}
}
View
2  Enyim.Caching.Tests/MemcachedClientTestsBase.cs
@@ -49,7 +49,7 @@ protected string GetRandomString()
return "unit_test_value_" + rand;
}
- protected IStoreOperationResult Store(StoreMode mode = StoreMode.Set, string key = null, string value = null)
+ protected IStoreOperationResult Store(StoreMode mode = StoreMode.Set, string key = null, object value = null)
{
if (string.IsNullOrEmpty(key))
{
View
14 Enyim.Caching/Memcached/Transcoders/DefaultTranscoder.cs
@@ -133,6 +133,8 @@ protected virtual object Deserialize(CacheItem item)
case TypeCode.DateTime: return this.DeserializeDateTime(data);
case TypeCode.Double: return this.DeserializeDouble(data);
case TypeCode.Single: return this.DeserializeSingle(data);
+ case TypeCode.Byte: return this.DeserializeByte(data);
+ case TypeCode.SByte: return this.DeserializeSByte(data);
// backward compatibility
// earlier versions serialized decimals with TypeCode.Decimal
@@ -143,6 +145,8 @@ protected virtual object Deserialize(CacheItem item)
}
}
+
+
#region [ Typed serialization ]
protected virtual ArraySegment<byte> SerializeNull()
@@ -293,6 +297,16 @@ protected virtual Single DeserializeSingle(ArraySegment<byte> value)
return BitConverter.ToSingle(value.Array, value.Offset);
}
+ protected virtual Byte DeserializeByte(ArraySegment<byte> data)
+ {
+ return data.Array[data.Offset];
+ }
+
+ protected virtual SByte DeserializeSByte(ArraySegment<byte> data)
+ {
+ return (SByte)data.Array[data.Offset];
+ }
+
protected virtual object DeserializeObject(ArraySegment<byte> value)
{
using (var ms = new MemoryStream(value.Array, value.Offset, value.Count))
Please sign in to comment.
Something went wrong with that request. Please try again.