human
Complete this python program:
def StringDecoder(field_number, is_repeated, is_packed, key, new_default):
assistant
#Here is the Python program you requested.

    """Returns a decoder for a string field.
    """
    local_DecodeVarint = _DecodeVarint
    local_unicode = unicode
    def _ConvertToUnicode(byte_str):
        try:
            return local_unicode(byte_str, 'utf-8')
        except UnicodeDecodeError as e:
            e.reason = ('%s    in    field:    %s' % (e, key.full_name))
            raise
    assert (not is_packed)
    if is_repeated:
        tag_bytes = encoder.TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
        tag_len = len(tag_bytes)
        def DecodeRepeatedField(buffer, pos, end, message, field_dict):
            value = field_dict.get(key)
            if (value is None):
                value = field_dict.setdefault(key, new_default(message))
            while 1:
                (size, pos) = local_DecodeVarint(buffer, pos)
                new_pos = (pos + size)
                if (new_pos > end):
                    raise _DecodeError('Truncated    string.')
                value.append(_ConvertToUnicode(buffer[pos:new_pos]))
                pos = (new_pos + tag_len)
                if ((buffer[new_pos:pos] != tag_bytes) or (new_pos == end)):
                    return new_pos
        return DecodeRepeatedField
    else:
        def DecodeField(buffer, pos, end, message, field_dict):
            (size, pos) = local_DecodeVarint(buffer, pos)
            new_pos = (pos + size)
            if (new_pos > end):
                raise _DecodeError('Truncated    string.')
            field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
            return new_pos
        return DecodeField