예제 #1
0
        /// <summary>
        /// Parse bytes for a PUBREL message
        /// </summary>
        /// <param name="fixedHeaderFirstByte">First fixed header byte</param>
        /// <param name="channel">Channel connected to the broker</param>
        /// <returns>PUBREL message instance</returns>
        public static MQTTMsgPubrel Parse(byte fixedHeaderFirstByte, IMQTTNetworkChannel channel)
        {
            byte[]        buffer;
            int           index = 0;
            MQTTMsgPubrel msg   = new MQTTMsgPubrel();

            // get remaining length and allocate buffer
            int remainingLength = MQTTMsgBase.decodeRemainingLength(channel);

            buffer = new byte[remainingLength];

            // read bytes from socket...
            channel.Receive(buffer);

            // read QoS level from fixed header (would be QoS Level 1)
            msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
            // read DUP flag from fixed header
            msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);

            // message id
            msg.messageId  = (ushort)((buffer[index++] << 8) & 0xFF00);
            msg.messageId |= (buffer[index++]);

            return(msg);
        }
예제 #2
0
        /// <summary>
        /// Parse bytes for a PINGREQ message
        /// </summary>
        /// <param name="fixedHeaderFirstByte">First fixed header byte</param>
        /// <param name="channel">Channel connected to the broker</param>
        /// <returns>PINGREQ message instance</returns>
        public static MQTTMsgPingReq Parse(byte fixedHeaderFirstByte, IMQTTNetworkChannel channel)
        {
            MQTTMsgPingReq msg = new MQTTMsgPingReq();

            // already know remaininglength is zero (MQTT specification),
            // so it isn't necessary to read other data from socket
            int remainingLength = MQTTMsgBase.decodeRemainingLength(channel);

            return(msg);
        }
예제 #3
0
        /// <summary>
        /// Parse bytes for a DISCONNECT message
        /// </summary>
        /// <param name="fixedHeaderFirstByte">First fixed header byte</param>
        /// <param name="channel">Channel connected to the broker</param>
        /// <returns>DISCONNECT message instance</returns>
        public static MQTTMsgDisconnect Parse(byte fixedHeaderFirstByte, IMQTTNetworkChannel channel)
        {
            MQTTMsgDisconnect msg = new MQTTMsgDisconnect();

            // get remaining length and allocate buffer
            int remainingLength = MQTTMsgBase.decodeRemainingLength(channel);

            // NOTE : remainingLength must be 0

            return(msg);
        }
        /// <summary>
        /// Parse bytes for a PUBREC message
        /// </summary>
        /// <param name="fixedHeaderFirstByte">First fixed header byte</param>
        /// <param name="channel">Channel connected to the broker</param>
        /// <returns>PUBREC message instance</returns>
        public static MQTTMsgPubrec Parse(byte fixedHeaderFirstByte, IMQTTNetworkChannel channel)
        {
            byte[]        buffer;
            int           index = 0;
            MQTTMsgPubrec msg   = new MQTTMsgPubrec();

            // get remaining length and allocate buffer
            int remainingLength = MQTTMsgBase.decodeRemainingLength(channel);

            buffer = new byte[remainingLength];

            // read bytes from socket...
            channel.Receive(buffer);

            // message id
            msg.messageId  = (ushort)((buffer[index++] << 8) & 0xFF00);
            msg.messageId |= (buffer[index++]);

            return(msg);
        }