pubcomp.go 1.2 KB

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