pubrec.go 931 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package packets
  2. import (
  3. "fmt"
  4. "io"
  5. )
  6. // PubrecPacket is an internal representation of the fields of the
  7. // Pubrec MQTT packet
  8. type PubrecPacket struct {
  9. FixedHeader
  10. MessageID uint16
  11. }
  12. func (pr *PubrecPacket) String() string {
  13. return fmt.Sprintf("%s MessageID: %d", pr.FixedHeader, pr.MessageID)
  14. }
  15. func (pr *PubrecPacket) Write(w io.Writer) error {
  16. var err error
  17. pr.FixedHeader.RemainingLength = 2
  18. packet := pr.FixedHeader.pack()
  19. packet.Write(encodeUint16(pr.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 (pr *PubrecPacket) Unpack(b io.Reader) error {
  26. var err error
  27. pr.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 (pr *PubrecPacket) Details() Details {
  33. return Details{Qos: pr.Qos, MessageID: pr.MessageID}
  34. }