All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.ditchoom.mqtt3.controlpacket.PublishRelease.kt Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package com.ditchoom.mqtt3.controlpacket

import com.ditchoom.buffer.ReadBuffer
import com.ditchoom.buffer.WriteBuffer
import com.ditchoom.mqtt.controlpacket.IPublishRelease
import com.ditchoom.mqtt.controlpacket.format.ReasonCode
import com.ditchoom.mqtt.controlpacket.format.fixed.DirectionOfFlow

/**
 * 3.6 PUBREL – Publish release (QoS 2 delivery part 2)
 *
 * A PUBREL packet is the response to a PUBREC packet. It is the third packet of the QoS 2 protocol exchange.
 */
data class PublishRelease(override val packetIdentifier: Int) :
    ControlPacketV4(IPublishRelease.controlPacketValue, DirectionOfFlow.BIDIRECTIONAL, 0b10),
    IPublishRelease {
    override fun variableHeader(writeBuffer: WriteBuffer) {
        writeBuffer.writeUShort(packetIdentifier.toUShort())
    }

    override fun remainingLength() = 2

    override fun expectedResponse(
        reasonCode: ReasonCode,
        reasonString: String?,
        userProperty: List>
    ) = PublishComplete(packetIdentifier)

    companion object {
        fun from(buffer: ReadBuffer) = PublishRelease(buffer.readUnsignedShort().toInt())
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy