public stHeader Copy() { byte[] copyMsg = Serialize(); Type type = GetType(); stHeader copiedMsg = (stHeader)Activator.CreateInstance(type); copiedMsg.Deserialize(copyMsg); return(copiedMsg); }
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); }