maeqtt/mqtt/packets/Ping.go

39 lines
678 B
Go
Raw Normal View History

2021-08-26 15:08:24 +02:00
package packets
import (
"bytes"
"errors"
"io"
)
2021-10-01 22:18:48 +02:00
type PingreqPacket struct{}
2021-08-26 15:08:24 +02:00
2021-09-28 12:30:32 +02:00
func parsePingreq(control controlPacket) (PingreqPacket, error) {
2021-08-26 15:08:24 +02:00
packet := PingreqPacket{}
if control.packetType != PacketTypePingreq {
panic("Wrong packet type for parsePingreq")
}
if control.flags != 0 {
return packet, errors.New("Malformed connect packet")
}
2021-10-01 22:18:48 +02:00
2021-08-26 15:08:24 +02:00
return packet, nil
}
2021-09-28 12:30:32 +02:00
func (r PingreqPacket) Visit(p PacketVisitor) {
p.VisitPing(r)
}
2021-10-01 22:18:48 +02:00
type PingrespPacket struct{}
2021-08-26 15:08:24 +02:00
func (p PingrespPacket) Write(w io.Writer) error {
2021-10-01 22:18:48 +02:00
control := controlPacket{
2021-08-26 15:08:24 +02:00
packetType: PacketTypePingresp,
2021-10-01 22:18:48 +02:00
flags: 0,
reader: bytes.NewReader([]byte{}),
2021-08-26 15:08:24 +02:00
}
return control.write(w)
}