Created
December 14, 2013 02:17
-
-
Save tsubaki/7954893 to your computer and use it in GitHub Desktop.
msgpack with unity sample. used msgpack_cli(project=MsgPack.compats.Net.3.5 ,target framework=mono3.5). builded binary https://www.dropbox.com/s/rbnamvknbvwx58h/MsgPack.dll
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 MsgPack; | |
public class DataClass : IPackable, IUnpackable{ | |
public string data; | |
public int count; | |
public void UnpackFromMessage (Unpacker unpacker) | |
{ | |
unpacker.ReadInt32(out count); | |
unpacker.ReadString(out data); | |
} | |
public void PackToMessage (Packer packer, PackingOptions options) | |
{ | |
packer.Pack(count); | |
packer.PackString(data); | |
} | |
} |
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 MsgPack; | |
using UnityEngine; | |
public class Test : MonoBehaviour { | |
void Start () { | |
byte[] bytes = null; | |
// pack | |
var data = new DataClass() | |
{ | |
count = 120, | |
data = "hoge", | |
}; | |
using ( MemoryStream mem = new MemoryStream()) | |
{ | |
Packer packer = Packer.Create(mem); | |
data.PackToMessage(packer, null); | |
bytes = mem.ToArray(); | |
} | |
// unpack | |
DataClass unpackData = new DataClass(); | |
using (MemoryStream mem = new MemoryStream(bytes)) | |
{ | |
Unpacker unpacker = Unpacker.Create(mem); | |
unpackData.UnpackFromMessage(unpacker); | |
} | |
Debug.Log(unpackData.count); | |
Debug.Log(unpackData.data); | |
} | |
} |
You're welcome. douitashimashite.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for making a Unity version for MsgPack. I will test it out.
Cheers. Arigato.