maeqtt/mqtt/packets/PubAckRecRel.go

92 lines
2.2 KiB
Go
Raw Permalink Normal View History

2021-08-26 15:08:24 +02:00
package packets
import (
"badat.dev/maeqtt/v2/mqtt/properties"
2021-10-01 22:18:48 +02:00
"io"
2021-08-26 15:08:24 +02:00
)
type PubackReasonCode byte
const (
PubackReasonCodeSuccess PubackReasonCode = 0
2021-10-17 21:09:44 +02:00
PubackReasonCodeNoMatchingSubscribers PubackReasonCode = 16
PubackReasonCodeUnspecifiedError PubackReasonCode = 128
PubackReasonCodeImplementationSpecyficEror PubackReasonCode = 131
PubackReasonCodeNotAuthorized PubackReasonCode = 135
PubackReasonCodeTopicNameInvalid PubackReasonCode = 144
PubackReasonCodePacketIDInUse PubackReasonCode = 145
PubackReasonCodeQuotaExceeded PubackReasonCode = 151
PubackReasonCodePayloadFormatInvalid PubackReasonCode = 153
2021-08-26 15:08:24 +02:00
)
type PubackPacket struct {
PacketID uint16
Properties properties.PubackPacketProperties
Reason PubackReasonCode
}
func (p PubackPacket) Write(w io.Writer) error {
resp := pubRespPacket{
PacketType: PacketTypePuback,
PacketID: p.PacketID,
Properties: p.Properties.ArrayOf(),
Reason: byte(p.Reason),
}
return resp.Write(w)
}
type PubrecPacket struct {
PacketID uint16
Properties properties.PubrecPacketProperties
Reason PubackReasonCode
}
func (p PubrecPacket) Write(w io.Writer) error {
resp := pubRespPacket{
PacketType: PacketTypePubrec,
PacketID: p.PacketID,
Properties: p.Properties.ArrayOf(),
Reason: byte(p.Reason),
}
return resp.Write(w)
}
type PubrelReasonCode byte
const (
PubrelReasonCodeSuccess PubackReasonCode = 0
2021-10-17 21:09:44 +02:00
PubrelReasonPacketIDNotFound PubackReasonCode = 146
2021-08-26 15:08:24 +02:00
)
type PubrelPacket struct {
PacketID uint16
Properties properties.PubrecPacketProperties
Reason PubrelReasonCode
}
func (p PubrelPacket) Write(w io.Writer) error {
resp := pubRespPacket{
PacketType: PacketTypePubrel,
PacketID: p.PacketID,
Properties: p.Properties.ArrayOf(),
Reason: byte(p.Reason),
}
return resp.Write(w)
}
type PubcompPacket struct {
PacketID uint16
Properties properties.PubcompPacketProperties
Reason PubrelReasonCode
}
func (p PubcompPacket) Write(w io.Writer) error {
resp := pubRespPacket{
PacketType: PacketTypePubrel,
PacketID: p.PacketID,
Properties: p.Properties.ArrayOf(),
Reason: byte(p.Reason),
}
return resp.Write(w)
}