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

commonMain.com.ditchoom.mqtt.controlpacket.ControlPacketFactory.kt Maven / Gradle / Ivy

@file:Suppress("EXPERIMENTAL_API_USAGE")

package com.ditchoom.mqtt.controlpacket

import com.ditchoom.buffer.ReadBuffer
import com.ditchoom.mqtt.controlpacket.ControlPacket.Companion.readVariableByteInteger

interface ControlPacketFactory {
    fun from(buffer: ReadBuffer): ControlPacket {
        val byte1 = buffer.readUnsignedByte()
        val remainingLength = buffer.readVariableByteInteger()
        return from(buffer, byte1, remainingLength)
    }

    fun from(buffer: ReadBuffer, byte1: UByte, remainingLength: UInt): ControlPacket

    fun pingRequest(): IPingRequest
    fun pingResponse(): IPingResponse

    fun publish(
        dup: Boolean = false,
        qos: QualityOfService = QualityOfService.EXACTLY_ONCE,
        packetIdentifier: Int? = null,
        retain: Boolean = false,
        topicName: CharSequence,
        payload: String? = null,
        // MQTT 5 Properties
        payloadFormatIndicator: Boolean = false,
        messageExpiryInterval: Long? = null,
        topicAlias: Int? = null,
        responseTopic: CharSequence? = null,
        correlationData: String? = null,
        userProperty: List> = emptyList(),
        subscriptionIdentifier: Set = emptySet(),
        contentType: CharSequence? = null
    ): IPublishMessage {
        return publish(
            dup,
            qos,
            packetIdentifier,
            retain,
            topicName,
            payload?.let { GenericType(it, String::class) },
            payloadFormatIndicator,
            messageExpiryInterval,
            topicAlias,
            responseTopic,
            correlationData?.let { GenericType(it, String::class) },
            userProperty,
            subscriptionIdentifier,
            contentType
        )
    }

    fun  publish(
        dup: Boolean = false,
        qos: QualityOfService = QualityOfService.EXACTLY_ONCE,
        packetIdentifier: Int? = null,
        retain: Boolean = false,
        topicName: CharSequence,
        payload: GenericType? = null,
        // MQTT 5 Properties
        payloadFormatIndicator: Boolean = false,
        messageExpiryInterval: Long? = null,
        topicAlias: Int? = null,
        responseTopic: CharSequence? = null,
        correlationData: GenericType? = null,
        userProperty: List> = emptyList(),
        subscriptionIdentifier: Set = emptySet(),
        contentType: CharSequence? = null
    ): IPublishMessage

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy