Created
April 10, 2014 00:10
-
-
Save takekazuomi/10332165 to your computer and use it in GitHub Desktop.
Message Pack CLI issue #27 reproducible code
This file contains 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.Linq; | |
using MsgPack.Serialization; | |
namespace TestMsgpackCli001 | |
{ | |
using System.Collections.Generic; | |
namespace TestMsgpackCli001 | |
{ | |
public class SomeOne | |
{ | |
public string Target; | |
public IDictionary<string, string> Data; | |
} | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
var h = new SomeOne | |
{ | |
Target = "boo", | |
Data = new Dictionary<string, string>() | |
}; | |
h.Data.Add(new KeyValuePair<string, string>("foo", "woo")); | |
var b = h.Pack(); | |
var h2 = b.UnPack<SomeOne>(); | |
Console.WriteLine("{0},{1}", h2.Target, string.Join(",", h2.Data.Select(pair => string.Format("{0}=>{1}", pair.Key, pair.Value)))); | |
} | |
} | |
public static class Extentions | |
{ | |
public static byte[] Pack<T>(this T data) | |
{ | |
var serializer = MessagePackSerializer.Create<T>(); | |
var stream = new MemoryStream(); | |
serializer.Pack(stream, data); | |
return stream.ToArray(); | |
} | |
public static T UnPack<T>(this byte[] data) | |
{ | |
var serializer = MessagePackSerializer.Create<T>(); | |
var stream = new MemoryStream(data); | |
return serializer.Unpack(stream); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment