Exemplo n.º 1
0
    private byte[] serialize(TestStruct data)
    {
        ObjectPacker packer     = new MsgPack.ObjectPacker();
        var          packedData = packer.Pack(data);

        return(packedData);
    }
Exemplo n.º 2
0
    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);
        }
    }
Exemplo n.º 3
0
    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);
    }
Exemplo n.º 4
0
 private static void XorFloatPacker(ObjectPacker packer, MsgPackWriter writer, object o)
 {
     packer.Pack(writer, (float)(XorFloat)o, typeof(float));
 }
Exemplo n.º 5
0
 private static void XorUIntPacker(ObjectPacker packer, MsgPackWriter writer, object o)
 {
     packer.Pack(writer, (uint)(XorUInt)o, typeof(uint));
 }