code: func (cp *Connect) len() int {
  	total := 0
  
  	if cp.Version == Version31 {
  		// 2 bytes protocol name length
  		// 6 bytes protocol name
  		// 1 byte protocol version
  		total += 2 + 6 + 1
  	} else {
  		// 2 bytes protocol name length
  		// 4 bytes protocol name
  		// 1 byte protocol version
  		total += 2 + 4 + 1
  	}
  
  	// 1 byte connect flags
  	// 2 bytes keep alive timer
  	total += 1 + 2
  
  	// add the clientID length
  	total += 2 + len(cp.ClientID)
  
  	// add the will topic and will message length
  	if cp.Will != nil {
  		total += 2 + len(cp.Will.Topic) + 2 + len(cp.Will.Payload)
  	}
  
  	// add the username length
  	if len(cp.Username) > 0 {
  		total += 2 + len(cp.Username)
  	}
  
  	// add the password length
  	if len(cp.Password) > 0 {
  		total += 2 + len(cp.Password)
  	}
  
  	return total
  }
docs: // Returns the payload length.