Beispiel #1
0
        public static MqttMessage DecodeMessage(Stream stream)
        {
            var header = new FixedHeader(stream);
            var msg    = CreateMessage(header.MessageType);

            msg.FixedHeader = header;
            msg.Decode(stream);
            return(msg);
        }
Beispiel #2
0
        public override void Encode(Stream stream)
        {
            using (var body = new MemoryStream())
            {
                body.WriteString(TopicName);
                //body.WriteShort(MessageIdentifier);
                body.Write(Payload, 0, Payload.Length);

                FixedHeader.RemaingLength = (int)body.Length;
                FixedHeader.WriteTo(stream);
                body.WriteTo(stream);
            }
        }
Beispiel #3
0
        public override void Encode(Stream stream)
        {
            using (var body = new MemoryStream())
            {
                body.WriteShort(MessageIdentifier);

                foreach (var item in topics)
                {
                    body.WriteString(item);
                }

                FixedHeader.RemaingLength = (int)body.Length;
                FixedHeader.WriteTo(stream);
                body.WriteTo(stream);
            }
        }
Beispiel #4
0
        public override void Encode(Stream stream)
        {
            using (var body = new MemoryStream())
            {
                //variable header
                body.WriteString(ProtocolName);       //byte 1 - 8
                body.WriteByte(ProtocolVersion);      //byte 9

                //ConnectFlags.WriteTo(body);         //byte 10
                var flags = UsernameFlag.ToByte() << 7;
                flags |= PasswordFlag.ToByte() << 6;
                flags |= WillRetain.ToByte() << 5;
                flags |= ((byte)WillQos) << 3;
                flags |= WillFlag.ToByte() << 2;
                flags |= CleanSession.ToByte() << 1;
                body.WriteByte((byte)flags);

                //keep alive
                body.WriteShort(KeepAlive);      //byte 11 - 12

                //payload
                body.WriteString(ClientId);
                if (WillFlag)
                {
                    body.WriteString(WillTopic);
                    body.WriteString(WillMessage);
                }
                if (UsernameFlag)
                {
                    body.WriteString(Username);
                }
                if (PasswordFlag)
                {
                    body.WriteString(Password);
                }

                FixedHeader.RemaingLength = (int)body.Length;
                FixedHeader.WriteTo(stream);
                body.WriteTo(stream);
            }
        }
Beispiel #5
0
 public MqttMessage(MessageType msgType)
 {
     FixedHeader = new FixedHeader(msgType);
 }
Beispiel #6
0
 public static MqttMessage DecodeMessage(Stream stream)
 {
     var header = new FixedHeader(stream);
     var msg = NewMessage(header.MessageType);
     msg.FixedHeader = header;
     msg.Decode(stream);
     return msg;
 }
Beispiel #7
0
 public MqttMessage(MessageType msgType)
 {
     FixedHeader = new FixedHeader(msgType);
 }