1package packets
2
3import (
4	"fmt"
5	"io"
6)
7
8//PubcompPacket is an internal representation of the fields of the
9//Pubcomp MQTT packet
10type PubcompPacket struct {
11	FixedHeader
12	MessageID uint16
13}
14
15func (pc *PubcompPacket) String() string {
16	str := fmt.Sprintf("%s", pc.FixedHeader)
17	str += " "
18	str += fmt.Sprintf("MessageID: %d", pc.MessageID)
19	return str
20}
21
22func (pc *PubcompPacket) Write(w io.Writer) error {
23	var err error
24	pc.FixedHeader.RemainingLength = 2
25	packet := pc.FixedHeader.pack()
26	packet.Write(encodeUint16(pc.MessageID))
27	_, err = packet.WriteTo(w)
28
29	return err
30}
31
32//Unpack decodes the details of a ControlPacket after the fixed
33//header has been read
34func (pc *PubcompPacket) Unpack(b io.Reader) error {
35	pc.MessageID = decodeUint16(b)
36
37	return nil
38}
39
40//Details returns a Details struct containing the Qos and
41//MessageID of this ControlPacket
42func (pc *PubcompPacket) Details() Details {
43	return Details{Qos: pc.Qos, MessageID: pc.MessageID}
44}
45