package packets import ( "bytes" "io" "badat.dev/maeqtt/v2/mqtt/types" ) type controlPacket struct { packetType PacketType flags uint reader io.Reader } func (c controlPacket) write(w io.Writer) error { buf := bytes.NewBuffer([]byte{}) var fixedHeader byte = (byte(c.packetType) << 4 & 0b11110000) + (byte(c.flags) & 0b1111) _, err := buf.Write([]byte{fixedHeader}) if err != nil { return err } data, err := io.ReadAll(c.reader) if err != nil { return err } err = types.WriteDataWithVarIntLen(buf, data) if err != nil { return err } _, err = w.Write(buf.Bytes()) if err != nil { return err } return nil }