Created
September 4, 2015 06:53
-
-
Save neuecc/1172fd9c3d7ae3d34ed3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Text; | |
namespace CloudStructures | |
{ | |
public class JsonNetRedisValueConverter : ObjectRedisValueConverterBase | |
{ | |
protected override object DeserializeCore(Type type, byte[] value) | |
{ | |
using (var ms = new MemoryStream(value)) | |
using (var sr = new StreamReader(ms, Encoding.UTF8)) | |
{ | |
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(sr, type); | |
return result; | |
} | |
} | |
protected override byte[] SerializeCore(object value, out long resultSize) | |
{ | |
using (var ms = new MemoryStream()) | |
{ | |
using (var sw = new StreamWriter(ms, Encoding.UTF8)) | |
{ | |
var serializedObject = Newtonsoft.Json.JsonConvert.SerializeObject(value); | |
sw.Write(serializedObject); | |
} | |
var result = ms.ToArray(); | |
resultSize = result.Length; | |
return result; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment