def _encode_datetime(obj):
    """Encode a msgpck'ed datetime."""

    if isinstance(obj, datetime.datetime):
        obj = {'__datetime__': True, 'as_str': obj.strftime("%Y%m%dT%H:%M:%S.%f").encode()}
    return obj
Encode a msgpck'ed datetime.