'Group results by subject and convert to ScanAttribute output format.'

def _GroupSubjects(self, collection, max_records):

    record_count = 0
    current_subject = None
    current_results = {}
    for (subject, attribute, timestamp, value) in collection:
        if (not current_subject):
            current_subject = subject
        if (current_subject != subject):
            (yield (current_subject, current_results))
            record_count += 1
            if (max_records and (record_count >= max_records)):
                return
            current_results = {}
            current_subject = subject
        current_results[attribute] = (timestamp, self._Decode(attribute, value))
    if current_results:
        (yield (current_subject, current_results))
