private byte[] serialize(TestStruct data) { ObjectPacker packer = new MsgPack.ObjectPacker(); var packedData = packer.Pack(data); return(packedData); }
IEnumerator MsgTest() { string url = "msg_test"; // テストデータ var sendData = new RecvMsg(); sendData.Id = 12345; sendData.AddScore = -9876; sendData.Text = "hoge"; Dictionary <string, string> headers = new Dictionary <string, string>(); headers["Content-Type"] = "application/x-msgpack"; var packer = new MsgPack.ObjectPacker(); byte[] body = packer.Pack(sendData); using (WWW www = new WWW(HOST + url, body, headers)) { yield return(www); if (!string.IsNullOrEmpty(www.error)) { Debug.Log("error:" + www.error); yield break; } var unpacker = new MsgPack.ObjectPacker(); // unpack var result = unpacker.Unpack <RecvMsg>(www.bytes); Debug.Log("id : " + result.Id + " score : " + result.AddScore + " text : " + result.Text); } }
private byte[] makeData(int no, object obj) { ObjectPacker packer = new MsgPack.ObjectPacker(); var data = packer.Pack(obj); var info = BitConverter.GetBytes(no); byte[] result = new byte[info.Length + data.Length]; // first : command Buffer.BlockCopy(info, 0, result, 0, info.Length); // second : data Buffer.BlockCopy(data, 0, result, info.Length, data.Length); return(result); }
private static void XorFloatPacker(ObjectPacker packer, MsgPackWriter writer, object o) { packer.Pack(writer, (float)(XorFloat)o, typeof(float)); }
private static void XorUIntPacker(ObjectPacker packer, MsgPackWriter writer, object o) { packer.Pack(writer, (uint)(XorUInt)o, typeof(uint)); }