Example #1
0
        protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length)
        {
            //length为头部(包含两字节的length)长度
            //获取高位
            byte high = header[offset + length - 1];
            //获取低位
            byte low = header[offset + length - 2];

            return(MQTools.GetBodyLengthFromHeader(high, low));
        }
Example #2
0
        //ArraySegment

        public static ArraySegment <byte> GetResAckMessage(MQDataInfo mQDataInfo)
        {
            byte[] msg = new byte[16];
            MQTools.CharToByte(mQDataInfo.Head, msg);
            msg[2] = mQDataInfo.PID;
            msg[3] = (byte)MessageType.ResAck;
            MQTools.ConvertIntToByteArray(mQDataInfo.MID, msg, 4);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Code, msg, 8);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Reserved, msg, 10);

            MQTools.CharToByte(mQDataInfo.End, msg, 14);

            return(new ArraySegment <byte>(msg));
        }
Example #3
0
        public static byte[] GetSendMessageByte(MQDataInfo mQDataInfo)
        {
            byte[] msg = new byte[14 + mQDataInfo.Length + 2];
            MQTools.CharToByte(mQDataInfo.Head, msg);
            msg[2] = mQDataInfo.PID;
            msg[3] = mQDataInfo.Type;
            MQTools.ConvertIntToByteArray(mQDataInfo.MID, msg, 4);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Code, msg, 8);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Reserved, msg, 10);
            MQTools.ConvertUShortToByteArray((ushort)mQDataInfo.Length, msg, 12);
            Array.Copy(mQDataInfo.Body, 0, msg, 14, mQDataInfo.Length);

            MQTools.CharToByte(mQDataInfo.End, msg, mQDataInfo.Length + 14);

            return(msg);
        }
Example #4
0
        protected override MQDataInfo ResolveRequestInfo(ArraySegment <byte> header, byte[] bodyBuffer, int offset, int length)
        {
            //MQDataInfo mQData = new MQDataInfo();
            //mQData.Head = MQTools.ByteToChar(header.Array);
            //mQData.PID = header.Array[2];
            //mQData.Type = header.Array[3];
            //mQData.MID = BitConverter.ToInt32(header.Array, 4);
            //mQData.Code = BitConverter.ToUInt16(header.Array, 8);
            //mQData.Reserved = BitConverter.ToUInt16(header.Array, 10);
            //mQData.Length = BitConverter.ToUInt16(header.Array, 12);

            //mQData.Data = bodyBuffer.CloneRange(offset, length - 3);
            //mQData.CS = bodyBuffer[offset + mQData.Length];
            //mQData.End = MQTools.ByteToChar(bodyBuffer, offset + mQData.Length + 1);
            return(MQTools.ResolveMQDataInfo(header.Array, bodyBuffer, offset, length));

            //MQProtocolRequestInfo res = new MQProtocolRequestInfo(mQData);
        }
Example #5
0
        public static byte[] GetSendMessageByte(ushort mqCode, byte[] data, int mqId, byte sendPid, byte mqType, ushort Reserved, char head, char end)
        {
            byte[] msg = new byte[14 + data.Length + 2];
            MQTools.CharToByte(head, msg);
            msg[2] = sendPid;
            msg[3] = mqType;
            MQTools.ConvertIntToByteArray(mqId, msg, 4);
            MQTools.ConvertUShortToByteArray(mqCode, msg, 8);
            MQTools.ConvertUShortToByteArray(Reserved, msg, 10);
            MQTools.ConvertUShortToByteArray((ushort)data.Length, msg, 12);
            Array.Copy(data, 0, msg, 14, data.Length);
            //校验
            //msg[data.Length + 14] = 0;

            MQTools.CharToByte(end, msg, data.Length + 14);

            return(msg);
        }
Example #6
0
        public bool GetSendByte(out byte[] buffer)
        {
            buffer = new byte[14 + Length + 2];
            MQTools.CharToByte(Head, buffer);
            buffer[2] = PID;
            buffer[3] = Type;
            MQTools.ConvertIntToByteArray(MID, buffer, 4);
            MQTools.ConvertUShortToByteArray(Code, buffer, 8);
            MQTools.ConvertUShortToByteArray(Reserved, buffer, 10);
            MQTools.ConvertUShortToByteArray((ushort)Length, buffer, 12);

            if (Length > 0)
            {
                Array.Copy(Body, 0, buffer, 14, Length);
            }
            MQTools.CharToByte(End, buffer, Length + 14);

            return(true);
        }
Example #7
0
        public static MQDataInfo ResolveMQDataInfo(byte[] header, byte[] bodyBuffer, int offset, int length)
        {
            MQDataInfo mQData = new MQDataInfo();

            mQData.Head     = MQTools.ByteToChar(header[0], header[1]);
            mQData.PID      = header[2];
            mQData.Type     = header[3];
            mQData.MID      = BitConverter.ToInt32(header, 4);
            mQData.Code     = BitConverter.ToUInt16(header, 8);
            mQData.Reserved = BitConverter.ToUInt16(header, 10);
            mQData.Length   = BitConverter.ToUInt16(header, 12);
            if (mQData.Length > 0)
            {
                mQData.Body = bodyBuffer.CloneRange(offset, mQData.Length);
            }
            //mQData.CS = bodyBuffer[offset + mQData.Length];
            mQData.End = MQTools.ByteToChar(bodyBuffer[offset + mQData.Length], bodyBuffer[offset + mQData.Length + 1]);

            return(mQData);
        }
Example #8
0
        public static MQDataInfo ResolveMQDataInfo(byte[] buffer)
        {
            MQDataInfo mQData = new MQDataInfo();

            mQData.Head     = MQTools.ByteToChar(buffer[0], buffer[1]);
            mQData.PID      = buffer[2];
            mQData.Type     = buffer[3];
            mQData.MID      = BitConverter.ToInt32(buffer, 4);
            mQData.Code     = BitConverter.ToUInt16(buffer, 8);
            mQData.Reserved = BitConverter.ToUInt16(buffer, 10);
            mQData.Length   = BitConverter.ToUInt16(buffer, 12);
            if (mQData.Length > 0)
            {
                mQData.Body = buffer.CloneRange(14, mQData.Length);
            }
            // mQData.CS = buffer[14 + mQData.Length];
            mQData.End = MQTools.ByteToChar(buffer[14 + mQData.Length], buffer[14 + mQData.Length + 1]);

            return(mQData);
        }