pubcomp.go 938 B

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