42 lines
742 B
Go
42 lines
742 B
Go
package packets
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"badat.dev/maeqtt/v2/mqtt/properties"
|
|
"badat.dev/maeqtt/v2/mqtt/types"
|
|
)
|
|
|
|
// Boilerplate struct for de/serializing various ack packets
|
|
type pubRespPacket struct {
|
|
PacketType PacketType
|
|
PacketID uint16
|
|
Properties []properties.Property
|
|
Reason byte
|
|
}
|
|
|
|
func (p pubRespPacket) Write(w io.Writer) error {
|
|
buf := bytes.NewBuffer([]byte{})
|
|
err := types.WriteUint16(buf, p.PacketID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = buf.WriteByte(byte(p.Reason))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = properties.WriteProps(buf, p.Properties)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
conPack := controlPacket{
|
|
packetType: PacketTypePuback,
|
|
flags: 0,
|
|
reader: buf,
|
|
}
|
|
return conPack.write(w)
|
|
}
|