Exemplo n.º 1
0
        /// <summary>
        ///     Gets the length of the write data when WriteTo will be called.
        /// </summary>
        /// <returns>The length of data witten by the call to GetWriteLength</returns>
        public virtual int GetWriteLength()
        {
            int headerLength = 0;
            var enc          = new MqttEncoding();

            if ((WriteFlags & ReadWriteFlags.ProtocolName) == ReadWriteFlags.ProtocolName)
            {
                headerLength += enc.GetByteCount(ProtocolName);
            }
            if ((WriteFlags & ReadWriteFlags.ProtocolVersion) == ReadWriteFlags.ProtocolVersion)
            {
                headerLength += sizeof(byte);
            }
            if ((WriteFlags & ReadWriteFlags.ConnectFlags) == ReadWriteFlags.ConnectFlags)
            {
                headerLength += MqttConnectFlags.GetWriteLength();
            }
            if ((WriteFlags & ReadWriteFlags.KeepAlive) == ReadWriteFlags.KeepAlive)
            {
                headerLength += sizeof(short);
            }
            if ((WriteFlags & ReadWriteFlags.ReturnCode) == ReadWriteFlags.ReturnCode)
            {
                headerLength += sizeof(byte);
            }
            if ((WriteFlags & ReadWriteFlags.TopicName) == ReadWriteFlags.TopicName)
            {
                headerLength += enc.GetByteCount(TopicName.ToString());
            }
            if ((WriteFlags & ReadWriteFlags.MessageIdentifier) == ReadWriteFlags.MessageIdentifier)
            {
                headerLength += sizeof(short);
            }

            return(headerLength);
        }
Exemplo n.º 2
0
 protected void ReadConnectFlags(Stream stream)
 {
     ConnectFlags = new MqttConnectFlags(stream);
     length      += 1;
 }