Example #1
0
 public static byte[] SerializeObject(lib.Net.Sockets.ITransferableObject obj)
 {
     if (obj == null)
     {
         return(null);
     }
     byte[] namebuff = Encoding.UTF8.GetBytes(obj.GetType().FullName);
     byte[] buff     = BitConverter.GetBytes((int)namebuff.Length)
                       .Concat(namebuff)
                       .Concat(obj.GetData()).ToArray();
     return(buff);
 }
Example #2
0
        public static lib.Net.Sockets.ITransferableObject DeserializeObject(byte[] bytes)
        {
            lib.Net.Sockets.ITransferableObject obj = null;
            if (bytes == null)
            {
                return(null);
            }
            int    len      = BitConverter.ToInt32(bytes, 0);
            string fullName = Encoding.UTF8.GetString(bytes, 4, len);
            Type   type     = Type.GetType(fullName);

            obj = Activator.CreateInstance(type) as lib.Net.Sockets.ITransferableObject;
            if (obj != null)
            {
                obj.ReadData(bytes, 4 + len, bytes.Length - 4 - len);
            }
            return(obj);
        }