Skip to content

Instantly share code, notes, and snippets.

@st0326s
Last active June 2, 2017 06:41
Show Gist options
  • Save st0326s/501be81de024516e15e6b51a95d6db33 to your computer and use it in GitHub Desktop.
Save st0326s/501be81de024516e15e6b51a95d6db33 to your computer and use it in GitHub Desktop.
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");
}
}
void Start ()
{
Debug.Log ("***********************");
MessagePackSerializer.PrepareType<ABC> ();
Debug.Log ("?????????????????????????");
}
void Start ()
{
Debug.Log ("***********************");
MessagePackSerializer.PrepareType<int> ();
Debug.Log ("?????????????????????????");
}
void Start ()
{
Debug.Log ("***********************");
MessagePackSerializer.PrepareType<object> ();
Debug.Log ("?????????????????????????");
}
 var serializer = MessagePackSerializer.Get<ABC>(context);
 ↓
 var serializer = MessagePackSerializer.Get<object>(context);
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