Last active
June 2, 2017 06:41
-
-
Save st0326s/501be81de024516e15e6b51a95d6db33 to your computer and use it in GitHub Desktop.
MsgPackの検証 ref: http://qiita.com/satotin/items/2c1b131e093a1eb32c09
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.IO; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using MsgPack; | |
using MsgPack.Serialization; | |
public class test : MonoBehaviour { | |
public class ABC | |
{ | |
public int aaaaa; | |
public int bbbbb; | |
} | |
// Use this for initialization | |
void Start () { | |
Debug.Log ("***********************"); | |
MessagePackSerializer.PrepareType<object> (); | |
Debug.Log ("?????????????????????????"); | |
} | |
public void OnClickButton() | |
{ | |
Debug.Log ("0"); | |
var test = new ABC (); | |
test.aaaaa = 0; | |
test.bbbbb = 1; | |
var stream = new MemoryStream(); | |
Debug.Log ("1"); | |
// --- シリアライズ | |
var memoryStream = new MemoryStream(); | |
Debug.Log ("2"); | |
var context = new SerializationContext(); | |
context.SerializationMethod = SerializationMethod.Map; | |
Debug.Log ("3"); | |
// シリアライズした結果をMemoryStreamに書き込み | |
var serializer = MessagePackSerializer.Get<object>(context); | |
Debug.Log ("4"); | |
serializer.Pack(memoryStream, test); | |
Debug.Log ("abcde"); | |
} | |
} | |
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
void Start () | |
{ | |
Debug.Log ("***********************"); | |
MessagePackSerializer.PrepareType<ABC> (); | |
Debug.Log ("?????????????????????????"); | |
} | |
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
void Start () | |
{ | |
Debug.Log ("***********************"); | |
MessagePackSerializer.PrepareType<int> (); | |
Debug.Log ("?????????????????????????"); | |
} | |
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
void Start () | |
{ | |
Debug.Log ("***********************"); | |
MessagePackSerializer.PrepareType<object> (); | |
Debug.Log ("?????????????????????????"); | |
} | |
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
var serializer = MessagePackSerializer.Get<ABC>(context); | |
↓ | |
var serializer = MessagePackSerializer.Get<object>(context); |
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
serializer.Pack(memoryStream, test); | |
↓ | |
serializer.Pack(memoryStream, (object)test); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment