How to use the xxhash._cffi.ffi.from_buffer function in xxhash

To help you get started, we’ve selected a few xxhash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ifduyue / python-xxhash / xxhash / cffi.py View on Github external
def _get_buffer(val):
    """
    Best-effort function to get the pointer and byte length of a buffer-like
    object.
    """
    if PY3 and isinstance(val, str):
        return val.encode('utf8'), len(val)
    if isinstance(val, bytes):
        return val, len(val)
    cdata = ffi.from_buffer(val)
    return cdata, len(cdata)