How to use the xxhash._cffi.lib 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 __del__(self):
        lib.XXH32_freeState(self.xxhash_state)
github ifduyue / python-xxhash / xxhash / cffi.py View on Github external
import sys
import struct
import binascii

from xxhash._cffi import ffi, lib

PY3 = sys.version_info[0] == 3

XXHASH_VERSION = "%d.%d.%d" % (lib.XXH_VERSION_MAJOR,
                               lib.XXH_VERSION_MINOR,
                               lib.XXH_VERSION_RELEASE)


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)