/// <summary> /// Initializes a new instance of the <see cref="MqttSubscribePayload" /> class. /// </summary> /// <param name="header">The header to use for the message.</param> /// <param name="variableHeader">The variable header to use for the message.</param> /// <param name="payloadStream">The payload stream.</param> public MqttSubscribePayload(MqttHeader header, MqttSubscribeVariableHeader variableHeader, Stream payloadStream) { this.header = header; this.variableHeader = variableHeader; ReadFrom(payloadStream); }
/// <summary> /// Gets an instance of an MqttMessage based on the message type requested. /// </summary> /// <param name="header">The message header.</param> /// <param name="messageStream">The content of the message, including variable header where applicable.</param> /// <returns>An instance of the desired message type.</returns> public static MqttMessage GetMessage(MqttHeader header, Stream messageStream) { switch (header.MessageType) { /*case MqttMessageType.Connect: * return new MqttConnectMessage(header, messageStream); * case MqttMessageType.ConnectAck: * return new MqttConnectAckMessage(header, messageStream); * case MqttMessageType.PingRequest: * return new MqttPingRequestMessage(header); * case MqttMessageType.PingResponse: * return new MqttPingResponseMessage(header); * case MqttMessageType.Disconnect: * return new MqttDisconnectMessage(header); */ case MqttMessageType.Publish: return(new MqttPublishMessage(header, messageStream)); case MqttMessageType.PublishAck: return(new MqttPublishAckMessage(header, messageStream)); case MqttMessageType.PublishComplete: return(new MqttPublishCompleteMessage(header, messageStream)); case MqttMessageType.PublishReceived: return(new MqttPublishReceivedMessage(header, messageStream)); case MqttMessageType.PublishRelease: return(new MqttPublishReleaseMessage(header, messageStream)); case MqttMessageType.Subscribe: return(new MqttSubscribeMessage(header, messageStream)); case MqttMessageType.SubscribeAck: return(new MqttSubscribeAckMessage(header, messageStream)); case MqttMessageType.Unsubscribe: return(new MqttUnsubscribeMessage(header, messageStream)); case MqttMessageType.UnsubscribeAck: return(new MqttUnsubscribeAckMessage(header, messageStream)); default: throw new InvalidHeaderException( String.Format( "The Message Type specified ({0}) is not a valid MQTT Message type or currently not supported.", (int)header.MessageType)); } }
/// <summary> /// Creates a new instance of an MQTT Message based on a raw message stream. /// </summary> /// <param name="messageStream">The message stream.</param> /// <returns>An MqttMessage containing details of the message.</returns> public static MqttMessage CreateFrom(Stream messageStream) { try { var header = new MqttHeader(); // pass the input stream sequentially through the component deserialization(create) methods // to build a full MqttMessage. header = new MqttHeader(messageStream); MqttMessage message = MqttMessageFactory.GetMessage(header, messageStream); return(message); } catch (InvalidHeaderException ex) { throw new InvalidMessageException( "The data provided in the message stream was not a valid MQTT Message", ex); } }
/// <summary> /// Initializes a new instance of the <see cref="MqttConnectMessage" /> class. /// </summary> /// <param name="header">The header to use for the message.</param> /// <param name="messageStream">The message stream positioned after the header.</param> internal MqttUnsubscribeAckMessage(MqttHeader header, Stream messageStream) { this.Header = header; ReadFrom(messageStream); }
/// <summary> /// Initializes a new instance of the <see cref="MqttMessage" /> class. /// </summary> /// <param name="header">The header of the message.</param> public MqttMessage(MqttHeader header) { Header = header; }
/// <summary> /// Initializes a new instance of the <see cref="MqttConnectVariableHeader" /> class. /// </summary> /// <param name="header">The messages header.</param> /// <param name="variableHeaderStream">A stream containing the header of the message.</param> public MqttPublishVariableHeader(MqttHeader header, Stream variableHeaderStream) : this(header) { ReadFrom(variableHeaderStream); }
/// <summary> /// Initializes a new instance of the <see cref="MqttConnectVariableHeader" /> class. /// </summary> public MqttPublishVariableHeader(MqttHeader header) { this.header = header; }
/// <summary> /// Initializes a new instance of the <see cref="MqttPublishReceivedMessage" /> class. /// </summary> /// <param name="header">The header to use for the message.</param> /// <param name="messageStream">The message stream positioned after the header.</param> internal MqttPublishReceivedMessage(MqttHeader header, Stream messageStream) { this.Header = header; this.VariableHeader = new MqttPublishReceivedVariableHeader(messageStream); }
/// <summary> /// Initializes a new instance of the <see cref="MqttConnectPayload" /> class. /// </summary> /// <param name="header">The header of the message being process.</param> /// <param name="variableHeader">The variable header of the message being processed.</param> /// <param name="payloadStream">The payload stream.</param> public MqttPublishPayload(MqttHeader header, MqttPublishVariableHeader variableHeader, Stream payloadStream) { this.header = header; this.variableHeader = variableHeader; ReadFrom(payloadStream); }
/// <summary> /// Initializes a new instance of the <see cref="MqttPublishCompleteMessage" /> class. /// </summary> /// <param name="header">The header to use for the message.</param> /// <param name="messageStream">The message stream positioned after the header.</param> internal MqttPublishCompleteMessage(MqttHeader header, Stream messageStream) { this.Header = header; this.VariableHeader = new MqttPublishCompleteVariableHeader(messageStream); }
/// <summary> /// Initializes a new instance of the <see cref="MqttConnectMessage" /> class. /// </summary> /// <param name="header">The header to use for the message.</param> /// <param name="messageStream">The message stream positioned after the header.</param> internal MqttPublishMessage(MqttHeader header, Stream messageStream) { this.Header = header; ReadFrom(messageStream); }