package packets import ( "bytes" "io" "badat.dev/maeqtt/v2/mqtt/properties" "badat.dev/maeqtt/v2/mqtt/types" ) type ConnectReasonCode byte const ( ConnectReasonCodeSuccess ConnectReasonCode = 0 ConnectReasonCodeUnspecified ConnectReasonCode = 128 ConnectReasonCodeMalformedPacket ConnectReasonCode = 129 ConnectReasonCodeProtocolError ConnectReasonCode = 130 ConnectReasonCodeImplErorr ConnectReasonCode = 131 ConnectReasonCodeUnsupportedProtoVer ConnectReasonCode = 132 ConnectReasonCodeClientIDNotValid ConnectReasonCode = 133 ConnectReasonCodeBadUsernameOrPassword ConnectReasonCode = 134 ConnectReasonCodeNotAuthorized ConnectReasonCode = 135 ConnectReasonCodeServerUnavaliable ConnectReasonCode = 136 ConnectReasonCodeServerBusy ConnectReasonCode = 137 ConnectReasonCodeBanned ConnectReasonCode = 138 ConnectReasonCodeBadAuthenticationMethod ConnectReasonCode = 140 ConnectReasonCodeTopicNameInvalid ConnectReasonCode = 144 ConnectReasonCodePacketTooLarge ConnectReasonCode = 149 ConnectReasonCodeQuotaExceeded ConnectReasonCode = 151 ConnectReasonCodePayloadFormatInvalid ConnectReasonCode = 153 ConnectReasonCodeRetainNotSupported ConnectReasonCode = 154 ConnectReasonCodeQoSNotSupported ConnectReasonCode = 155 ConnectReasonCodeUseAnotherServer ConnectReasonCode = 156 ConnectReasonCodeServerMoved ConnectReasonCode = 157 ConnectReasonCodeConnectionRateExceeded ConnectReasonCode = 159 ) type ConnackPacket struct { ResonCode ConnectReasonCode SessionPresent bool Properties properties.ConnackPacketProperties } func (p ConnackPacket) Write(w io.Writer) error { buf := bytes.NewBuffer([]byte{}) var ackFlags [8]bool ackFlags[0] = p.SessionPresent err := types.WriteBits(buf, ackFlags) if err != nil { return err } err = buf.WriteByte(byte(p.ResonCode)) if err != nil { return err } err = properties.WriteProps(buf, p.Properties.ArrayOf()) if err != nil { return err } conPack := controlPacket{ packetType: PacketTypeConnack, flags: 0, reader: buf, } return conPack.write(w) }