forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMsgPackExtensions.cs
More file actions
31 lines (27 loc) · 830 Bytes
/
MsgPackExtensions.cs
File metadata and controls
31 lines (27 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) ServiceStack, Inc. All Rights Reserved.
// License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
using System.IO;
using ServiceStack.Text;
namespace ServiceStack.MsgPack
{
public static class MsgPackExtensions
{
public static byte[] ToMsgPack<T>(this T obj)
{
using (var ms = MemoryStreamFactory.GetStream())
{
MsgPackFormat.Serialize(obj, ms);
var bytes = ms.ToArray();
return bytes;
}
}
public static T FromMsgPack<T>(this byte[] bytes)
{
using (var ms = MemoryStreamFactory.GetStream(bytes))
{
var obj = (T)MsgPackFormat.Deserialize(typeof(T), ms);
return obj;
}
}
}
}