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); } }
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); } }
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); } }