def _a_decode_dictionary(stream, offset, count, mapping):
    """
    'a2d3sfoo3sbar3smoo4smilk',3,2 -> 24,{'foo':'bar', 'moo':'milk'}
    """
    container = {}
    for _ in range(count):
        index = offset
        while 48 <= ord(stream[index:index + 1]) <= 57:
            index += 1
        offset, key = mapping[stream[index:index + 1]](stream, index + 1,
            int(stream[offset:index]), mapping)
        index = offset
        while 48 <= ord(stream[index:index + 1]) <= 57:
            index += 1
        offset, value = mapping[stream[index:index + 1]](stream, index + 1,
            int(stream[offset:index]), mapping)
        container[key] = value
    if len(container) < count:
        raise ValueError('Duplicate key in dictionary')
    return offset, container
