unity : messagepack
messagepack http://msgpack.org/
他の物はunsafeが利用出来なかったり、ビルド手順が必要だったので
https://github.com/masharada/msgpack-unity
こちらを利用させていただきます。
string test = "unity test";
MsgPack.ObjectPacker bp = new MsgPack.ObjectPacker ();
byte[] packed = bp.Pack (test);
// print binary
Debug.Log (Encoding.Unicode.GetString (packed));
string unpackedText = (string)bp.Unpack
// pring "unity test"
Debug.Log(unpackedText);
クラスとリスト
public class TestData{
public int score;
public string playerName;
public Dictionary
public TestData( int s, string n ){
score = s;
playerName = n;
myDict = new Dictionary
myDict.Add("poteto","apple");
}
}
Dictionary
test.Add (1, new TestData( 999, "unity" ));
test.Add (2, new TestData( 777, "seven" ));
MsgPack.ObjectPacker bp = new MsgPack.ObjectPacker ();
byte[] packed = bp.Pack (test);
Dictionary
// pring "unity"
Debug.Log (unpacked[1].playerName);
Debug.Log (unpacked[1].myDict["poteto"]);
適当に動きました。
実際にはobjectPackerではなくboxingPackerを利用しました。