code: func (c *ConnectPacket) Validate() byte {
  	if c.PasswordFlag && !c.UsernameFlag {
  		return ErrRefusedBadUsernameOrPassword
  	}
  	if c.ReservedBit != 0 {
  		//Bad reserved bit
  		return ErrProtocolViolation
  	}
  	if (c.ProtocolName == "MQIsdp" && c.ProtocolVersion != 3) || (c.ProtocolName == "MQTT" && c.ProtocolVersion != 4) {
  		//Mismatched or unsupported protocol version
  		return ErrRefusedBadProtocolVersion
  	}
  	if c.ProtocolName != "MQIsdp" && c.ProtocolName != "MQTT" {
  		//Bad protocol name
  		return ErrProtocolViolation
  	}
  	if len(c.ClientIdentifier) > 65535 || len(c.Username) > 65535 || len(c.Password) > 65535 {
  		//Bad size field
  		return ErrProtocolViolation
  	}
  	if len(c.ClientIdentifier) == 0 && !c.CleanSession {
  		//Bad client identifier
  		return ErrRefusedIDRejected
  	}
  	return Accepted
  }
docs: //Validate performs validation of the fields of a Connect packet