コード例 #1
0
ファイル: ICDDefines.cs プロジェクト: sando87/IWAS
            public override void Deserialize(ref byte[] data)
            {
                int headSize = HEADER.HeaderSize();
                int bodySize = data.Length - headSize;

                byte[] headBuf = new byte[headSize];
                Array.Copy(data, 0, headBuf, 0, headSize);
                HEADER head = new HEADER();

                head.Deserialize(ref headBuf);

                msgID   = head.msgID;
                msgSize = head.msgSize;
                msgSOF  = head.msgSOF;
                msgType = head.msgType;
                msgErr  = head.msgErr;
                msgUser = head.msgUser;
                msgTime = head.msgTime;
                ext1    = head.ext1;
                ext2    = head.ext2;

                byte[] bodyBuf = new byte[bodySize];
                Array.Copy(data, headSize, bodyBuf, 0, bodySize);
                BinaryFormatter bf = new BinaryFormatter();

                using (MemoryStream ms = new MemoryStream(bodyBuf))
                {
                    workHistory = (WorkHistory[])bf.Deserialize(ms);
                }
            }
コード例 #2
0
ファイル: ICDDefines.cs プロジェクト: sando87/IWAS
            static public HEADER ConvertBytesToICDMessage(byte[] buf)
            {
                long nRecvLen = buf.Length;
                int  headSize = ICD.HEADER.HeaderSize();

                if (nRecvLen < headSize)
                {
                    return(null);
                }

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

                head.Deserialize(ref headBuf);
                if (head.msgSOF != ICD.DEF.MAGIC_SOF)
                {
                    LOG.warn();
                    return(null);
                }

                int msgSize = head.msgSize;

                if (nRecvLen < msgSize)
                {
                    return(null);
                }

                byte[] msgBuf  = new byte[msgSize];
                HEADER realMsg = CreateRealMessage(head);

                realMsg.Deserialize(ref msgBuf);
                return(realMsg);
            }
コード例 #3
0
ファイル: ICDPacketMgr.cs プロジェクト: sando87/IWAS
        private void procData(NetworkMgr.QueuePack pack)
        {
            while (true)
            {
                long nRecvLen = pack.buf.GetSize();
                int  headSize = ICD.HEADER.HeaderSize();
                if (nRecvLen < headSize)
                {
                    break;
                }

                byte[] headBuf = pack.buf.readSize(headSize);
                HEADER head    = new HEADER();
                head.Deserialize(ref headBuf);
                if (head.msgSOF != ICD.DEF.MAGIC_SOF)
                {
                    pack.buf.Clear();
                    break;
                }

                int msgSize = head.msgSize;
                if (nRecvLen < msgSize)
                {
                    break;
                }

                byte[] msgBuf = pack.buf.Pop(msgSize);

                HEADER msg = null;
                if (head.msgType == DEF.TYPE_REQ)
                {
                    msg = CreateICD_onServer(head);
                }
                else if (head.msgType == DEF.TYPE_REP)
                {
                    msg = CreateICD_onClient(head);
                }
                else
                {
                    LOG.warn();
                }

                msg.Deserialize(ref msgBuf);
                OnRecv?.Invoke(pack.ClientID, msg);
            }
        }
コード例 #4
0
        private void OnRecvPacket(object sender, EventArgs e)
        {
            var queue = (ConcurrentQueue <NetworkMgr.QueuePack>)sender;

            while (true)
            {
                NetworkMgr.QueuePack pack = null;
                if (queue.TryDequeue(out pack))
                {
                    HEADER head = HEADER.GetHeaderInfo(pack.buf);
                    HEADER obj  = CreateIcdObject((COMMAND)head.id);
                    HEADER.Deserialize(obj, ref pack.buf);
                    OnRecv.Invoke(pack.ClientID, obj);
                }

                if (queue.IsEmpty)
                {
                    break;
                }
            }
        }