maeqtt/mqtt/packets/ack.go

43 lines
738 B
Go
Raw Normal View History

2021-08-26 15:08:24 +02:00
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{
2021-10-01 22:18:48 +02:00
packetType: p.PacketType,
2021-08-26 15:08:24 +02:00
flags: 0,
reader: buf,
}
return conPack.write(w)
}