code: func (cp *Connack) Decode(src []byte) (int, error) {
  	total := 0
  
  	// decode header
  	hl, _, rl, err := headerDecode(src, CONNACK)
  	total += hl
  	if err != nil {
  		return total, err
  	}
  
  	// check remaining length
  	if rl != 2 {
  		return total, makeError(cp.Type(), "expected remaining length to be 2")
  	}
  
  	// read connack flags
  	connackFlags := src[total]
  	cp.SessionPresent = connackFlags&0x1 == 1
  	total++
  
  	// check flags
  	if connackFlags&254 != 0 {
  		return 0, makeError(cp.Type(), "bits 7-1 in acknowledge flags are not 0")
  	}
  
  	// read return code
  	cp.ReturnCode = ConnackCode(src[total])
  	total++
  
  	// check return code
  	if !cp.ReturnCode.Valid() {
  		return 0, makeError(cp.Type(), "invalid return code (%d)", cp.ReturnCode)
  	}
  
  	return total, nil
  }
docs: // Decode reads from the byte slice argument. It returns the total number of
  // bytes decoded, and whether there have been any errors during the process.