code: func (cp *Connack) Encode(dst []byte) (int, error) {
  	total := 0
  
  	// encode header
  	n, err := headerEncode(dst[total:], 0, 2, cp.Len(), CONNACK)
  	total += n
  	if err != nil {
  		return total, err
  	}
  
  	// set session present flag
  	if cp.SessionPresent {
  		dst[total] = 1 // 00000001
  	} else {
  		dst[total] = 0 // 00000000
  	}
  	total++
  
  	// check return code
  	if !cp.ReturnCode.Valid() {
  		return total, makeError(cp.Type(), "invalid return code (%d)", cp.ReturnCode)
  	}
  
  	// set return code
  	dst[total] = byte(cp.ReturnCode)
  	total++
  
  	return total, nil
  }
docs: // Encode writes the packet bytes into the byte slice from the argument. It
  // returns the number of bytes encoded and whether there's any errors along
  // the way. If there is an error, the byte slice should be considered invalid.