def GetFlagNames(bitmask, bitmask_dict, default_key=None):
  """Returns a list based on bitmask_dict corresponding to set bits in bitmask.

  Args:
    bitmask: Integer containing a bitmask of desired fields.
    bitmask_dict: Dictionary with power-of-two integer keys and values
        containing names of the corresponding bits.
    default_key: Key to use if bitmask == 0. Set to None to return [].

  Returns:
    A list with the values of bitmask_dict specified by bitmask.
  """
  if bitmask:
    return [name for bit, name in bitmask_dict.iteritems() if bit & bitmask]
  else:
    if default_key is None:
      return []
    else:
      return [bitmask_dict[default_key]]