LCOV - code coverage report
Current view: top level - src/messages/unsubscribe - mqtt_client_mqtt_unsubscribe_message.dart (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 24 24 100.0 %
Date: 2017-10-09 Functions: 0 0 -

          Line data    Source code
       1             : /*
       2             :  * Package : mqtt_client
       3             :  * Author : S. Hamblett <steve.hamblett@linux.com>
       4             :  * Date   : 19/06/2017
       5             :  * Copyright :  S.Hamblett
       6             :  */
       7             : 
       8             : part of mqtt_client;
       9             : 
      10             : /// Implementation of an MQTT Unsubscribe Message.
      11             : class MqttUnsubscribeMessage extends MqttMessage {
      12             :   /// Gets or sets the variable header contents. Contains extended metadata about the message
      13             :   MqttUnsubscribeVariableHeader variableHeader;
      14             : 
      15             :   /// Gets or sets the payload of the Mqtt Message.
      16             :   MqttUnsubscribePayload payload;
      17             : 
      18             :   /// Initializes a new instance of the MqttUnsubscribeMessage class.
      19           2 :   MqttUnsubscribeMessage() {
      20           6 :     this.header = new MqttHeader().asType(MqttMessageType.unsubscribe);
      21           4 :     this.variableHeader = new MqttUnsubscribeVariableHeader();
      22           4 :     this.payload = new MqttUnsubscribePayload();
      23             :   }
      24             : 
      25             :   /// Initializes a new instance of the MqttUnsubscribeMessage class.
      26             :   MqttUnsubscribeMessage.fromByteBuffer(MqttHeader header,
      27           1 :       MqttByteBuffer messageStream) {
      28           1 :     this.header = header;
      29           1 :     readFrom(messageStream);
      30             :   }
      31             : 
      32             :   /// Writes the message to the supplied stream.
      33             :   void writeTo(MqttByteBuffer messageStream) {
      34           2 :     this.header.writeTo(
      35           5 :         this.variableHeader.getWriteLength() + this.payload.getWriteLength(),
      36             :         messageStream);
      37           2 :     this.variableHeader.writeTo(messageStream);
      38           2 :     this.payload.writeTo(messageStream);
      39             :   }
      40             : 
      41             :   /// Reads a message from the supplied stream.
      42             :   void readFrom(MqttByteBuffer messageStream) {
      43           1 :     this.variableHeader =
      44           1 :     new MqttUnsubscribeVariableHeader.fromByteBuffer(messageStream);
      45           2 :     this.payload = new MqttUnsubscribePayload.fromByteBuffer(
      46           2 :         header, variableHeader, messageStream);
      47             :   }
      48             : 
      49             :   /// Adds a topic to the list of topics to unsubscribe from.
      50             :   MqttUnsubscribeMessage fromTopic(String topic) {
      51           4 :     this.payload.addSubscription(topic);
      52             :     return this;
      53             :   }
      54             : 
      55             :   /// Sets the message identifier on the subscribe message.
      56             :   MqttUnsubscribeMessage withMessageIdentifier(int messageIdentifier) {
      57           4 :     this.variableHeader.messageIdentifier = messageIdentifier;
      58             :     return this;
      59             :   }
      60             : 
      61             :   /// Sets the message up to request acknowledgement from the broker for each topic subscription.
      62             :   MqttUnsubscribeMessage expectAcknowledgement() {
      63           2 :     this.header.withQos(MqttQos.atLeastOnce);
      64             :     return this;
      65             :   }
      66             : 
      67             :   /// Sets the duplicate flag for the message to indicate its a duplicate of a previous message type
      68             :   /// with the same message identifier.
      69             :   MqttUnsubscribeMessage isDuplicate() {
      70           2 :     this.header.isDuplicate();
      71             :     return this;
      72             :   }
      73             : 
      74             :   String toString() {
      75           2 :     final StringBuffer sb = new StringBuffer();
      76           4 :     sb.write(super.toString());
      77           6 :     sb.writeln(variableHeader.toString());
      78           6 :     sb.writeln(payload.toString());
      79           2 :     return sb.toString();
      80             :   }
      81             : }

Generated by: LCOV version 1.10