Example #1
0
        public stHeader Copy()
        {
            byte[]   copyMsg   = Serialize();
            Type     type      = GetType();
            stHeader copiedMsg = (stHeader)Activator.CreateInstance(type);

            copiedMsg.Deserialize(copyMsg);
            return(copiedMsg);
        }
Example #2
0
        static public stHeader Parse(byte[] buf, ref bool isError)
        {
            isError = false;
            int headSize = HeaderSize();

            if (buf.Length < headSize)
            {
                return(null);
            }

            byte[] headBuf = new byte[headSize];
            Array.Copy(buf, 0, headBuf, 0, headSize);
            stHeader header = new stHeader();

            header.Deserialize(headBuf);
            int msgSize = (int)header.head.len;

            if (!header.IsValid())
            {
                isError = true;
                return(null);
            }

            if (buf.Length < msgSize)
            {
                return(null);
            }

            if (!CmdTable.Pairs.ContainsKey(header.head.cmd))
            {
                isError = true;
                return(null);
            }

            Type     objType = CmdTable.Pairs[header.head.cmd].GetType();
            stHeader obj     = (stHeader)Activator.CreateInstance(objType);

            obj.Deserialize(buf);

            return(obj);
        }