code: func (sp *Suback) Encode(dst []byte) (int, error) {
  	total := 0
  
  	// check return codes
  	for i, code := range sp.ReturnCodes {
  		if !code.Successful() && code != QOSFailure {
  			return total, makeError(sp.Type(), "invalid return code %d for topic %d", code, i)
  		}
  	}
  
  	// check packet id
  	if !sp.ID.Valid() {
  		return total, makeError(sp.Type(), "packet id must be grater than zero")
  	}
  
  	// encode header
  	n, err := headerEncode(dst[total:], 0, sp.len(), sp.Len(), SUBACK)
  	total += n
  	if err != nil {
  		return total, err
  	}
  
  	// write packet id
  	binary.BigEndian.PutUint16(dst[total:], uint16(sp.ID))
  	total += 2
  
  	// write return codes
  	for i, rc := range sp.ReturnCodes {
  		dst[total+i] = byte(rc)
  	}
  	total += len(sp.ReturnCodes)
  
  	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.