public static byte[] Serialize(object o)
    {
        CT_PlayerDeckUpdate customType = o as CT_PlayerDeckUpdate;

        if (customType == null)
        {
            return(null);
        }
        using (var s = new MemoryStream())
        {
            using (var bw = new BinaryWriter(s))
            {
                bw.Write(customType.actorNr);
                bw.Write(customType.cards_length);
                bw.Write(customType.ranks_length);
                bw.Write(customType.higherCards_length);
                bw.Write(customType.cards);
                bw.Write(customType.ranks);
                bw.Write(customType.higherCards);
                bw.Write(customType.swapCard);
                bw.Write(customType.isRule);
                return(s.ToArray());
            }
        }
    }
    public static object Deserialize(byte[] bytes)
    {
        CT_PlayerDeckUpdate customObject = new CT_PlayerDeckUpdate();

        using (var s = new MemoryStream(bytes))
        {
            using (var br = new BinaryReader(s))
            {
                customObject.actorNr            = br.ReadInt32();
                customObject.cards_length       = br.ReadInt32();
                customObject.ranks_length       = br.ReadInt32();
                customObject.higherCards_length = br.ReadInt32();
                customObject.cards       = br.ReadBytes(customObject.cards_length);
                customObject.ranks       = br.ReadBytes(customObject.ranks_length);
                customObject.higherCards = br.ReadBytes(customObject.higherCards_length);
                customObject.swapCard    = br.ReadBytes(2);
                customObject.isRule      = br.ReadBoolean();
            }
        }
        return(customObject);
    }