commonMain.com.ditchoom.mqtt3.controlpacket.PublishReceived.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mqtt-4-models Show documentation
Show all versions of mqtt-4-models Show documentation
Defines the MQTT 3 and 4 control packets
@file:Suppress("EXPERIMENTAL_API_USAGE")
package com.ditchoom.mqtt3.controlpacket
import com.ditchoom.buffer.ReadBuffer
import com.ditchoom.buffer.WriteBuffer
import com.ditchoom.mqtt.controlpacket.IPublishReceived
import com.ditchoom.mqtt.controlpacket.format.fixed.DirectionOfFlow
/**
* 3.5 PUBREC – Publish received (QoS 2 delivery part 1)
*
* A PUBREC packet is the response to a PUBLISH packet with QoS 2. It is the second packet of the QoS 2 protocol exchange.
*/
data class PublishReceived(override val packetIdentifier: Int) : ControlPacketV4(5, DirectionOfFlow.BIDIRECTIONAL),
IPublishReceived {
override fun variableHeader(writeBuffer: WriteBuffer) {
writeBuffer.write(packetIdentifier.toUShort())
}
override fun remainingLength() = 2u
override fun expectedResponse() = PublishRelease(packetIdentifier.toUShort().toInt())
companion object {
fun from(buffer: ReadBuffer) = PublishReceived(buffer.readUnsignedShort().toInt())
}
}