def _a_encode_dictionary(values, mapping):
    """
    {'foo':'bar', 'moo':'milk'} --> ['2', 'd', '3', 's', 'foo', '3', 's', 'bar', '3', 's', 'moo', '4', 's', 'milk']
    """
    assert isinstance(values, dict), 'VALUE has invalid type: %s' % type(values
        )
    encoded = [str(len(values)).encode('UTF-8'), b'd']
    extend = encoded.extend
    for key, value in values.items():
        assert type(key).__name__ in mapping, (key, values)
        assert type(value).__name__ in mapping, (value, values)
        extend(mapping[type(key).__name__](key, mapping))
        extend(mapping[type(value).__name__](value, mapping))
    return encoded
