public void PackAndUnpack() { var obj = new UserType { Name = "hoge" , Position = new Vector3 { x = 1, y = 2, z = 3 } #if USE_FORM , Color = System.Drawing.Color.FromArgb(255, 128, 128, 255) #endif }; #if USE_FORM // register pack System.Drawing.Color MsgPackUtil.Packer.Factory.GetInstance().AddType(typeof(System.Drawing.Color), (Packer p, Object o) => { var color = (System.Drawing.Color)o; p.Pack_Array(4); p.Pack(color.A); p.Pack(color.R); p.Pack(color.G); p.Pack(color.B); }); MsgPackUtil.Unpacker.Factory.GetInstance().AddArrayType(typeof(System.Drawing.Color), (Unpacker u, out Object o, UInt32 size) => { // check map size if (size != 4) { throw new ArgumentException("invalid map size"); } Byte a; u.PipelineUnpack(out a); Byte r; u.PipelineUnpack(out r); Byte g; u.PipelineUnpack(out g); Byte b; u.PipelineUnpack(out b); o = System.Drawing.Color.FromArgb(a, r, g, b); }); #endif // pack var bytes = m_r.SerializeToMessagePack(obj); // unpack var newObj = default(UserType); m_r.Deserialize(bytes.ParseAsMessagePack(), ref newObj); Assert.AreEqual(obj.Name, newObj.Name); #if USE_FORM Assert.AreEqual(obj.Color, newObj.Color); #endif Assert.AreEqual(obj.Position, newObj.Position); }
public void fix_raw() { var src = new Byte[] { 0, 1, 2 }; var bytes = m_r.SerializeToMessagePack(src); var v = default(Byte[]); m_r.Deserialize(MessagePackParser.Parse(bytes), ref v); Assert.AreEqual(src, v); }
public void str() { var bytes = m_r.SerializeToMessagePack("文字列"); var v = default(String); m_r.Deserialize(MessagePackParser.Parse(bytes), ref v); Assert.AreEqual("文字列", v); }
public void positive_fixnum() { for (Byte i = 0; i < 128; ++i) { var bytes = m_r.SerializeToMessagePack(i); Assert.AreEqual(new Byte[] { i }, bytes.ToEnumerable()); var j = default(Byte); m_r.Deserialize(MessagePackParser.Parse(bytes), ref j); Assert.AreEqual(i, j); } }