public static byte[] SerializeCreateDiceParams(object obj) { CreateDiceParams cdp = (CreateDiceParams)obj; byte[] result = new byte[16]; BitConverter.GetBytes(cdp.stage).CopyTo(result, 0); BitConverter.GetBytes(cdp.kind).CopyTo(result, 4); BitConverter.GetBytes(cdp.pos.x).CopyTo(result, 8); BitConverter.GetBytes(cdp.pos.y).CopyTo(result, 12); return(result); }
public static object DeserializeCreateDiceParams(byte[] data) { CreateDiceParams result = new CreateDiceParams { stage = BitConverter.ToInt32(data, 0), kind = BitConverter.ToInt32(data, 4), pos = new Vector2 { x = BitConverter.ToSingle(data, 8), y = BitConverter.ToSingle(data, 12), } }; return(result); }