Files
mochi-mqtt/packets/pubcomp.go
2019-10-09 08:30:57 +01:00

36 lines
750 B
Go

package packets
import (
"bytes"
)
// PubcompPacket contains the values of an MQTT PUBCOMP packet.
type PubcompPacket struct {
FixedHeader
PacketID uint16
}
// Encode encodes and writes the packet data values to the buffer.
func (pk *PubcompPacket) Encode(buf *bytes.Buffer) error {
pk.FixedHeader.Remaining = 2
pk.FixedHeader.Encode(buf)
buf.Write(encodeUint16(pk.PacketID))
return nil
}
// Decode extracts the data values from the packet.
func (pk *PubcompPacket) Decode(buf []byte) error {
var err error
pk.PacketID, _, err = decodeUint16(buf, 0)
if err != nil {
return ErrMalformedPacketID
}
return nil
}
// Validate ensures the packet is compliant.
func (pk *PubcompPacket) Validate() (byte, error) {
return Accepted, nil
}