示例#1
0
def on_transaction_get_range(fdb_future, aio_future):
    aio_future = ffi.from_handle(aio_future)
    kvs = ffi.new("FDBKeyValue **")
    count = ffi.new("int *")
    more = ffi.new("fdb_bool_t *")
    error = lib.fdb_future_get_keyvalue_array(fdb_future, kvs, count, more)
    if error == 0:
        out = list()
        # XXX: Because ffi.gc doens't work this time and because
        # downstream the code expect a real bytes object; for the time
        # being we do a copy of the whole range iteration

        # total count of buffers for this key-value array
        copy = kvs[0][0:count[0]]

        for kv in copy:
            # XXX: manual unpacking because cffi doesn't known about packing
            # https://bitbucket.org/cffi/cffi/issues/364/make-packing-configureable
            memory = ffi.buffer(ffi.addressof(kv), 24)
            key_ptr, key_length, value_ptr, value_length = struct.unpack(
                "=qiqi", memory)
            key = ffi.buffer(ffi.cast("char *", key_ptr), key_length)
            value = ffi.buffer(ffi.cast("char *", value_ptr), value_length)
            # XXX: make a copy again
            out.append((key[:], value[:]))

        _loop.call_soon_threadsafe(aio_future.set_result,
                                   (out, count[0], more[0]))
        # since we make copies of the fdb_future result we don't need
        # to keep it around
        lib.fdb_future_destroy(fdb_future)
    else:
        _loop.call_soon_threadsafe(aio_future.set_exception,
                                   FoundException(error))
        lib.fdb_future_destroy(fdb_future)
示例#2
0
def _on_error_callback(fdb_future, aio_future):
    aio_future = ffi.from_handle(aio_future)
    error = lib.fdb_future_get_error(fdb_future)
    if error == 0:
        _loop.call_soon_threadsafe(aio_future.set_result, None)
    else:
        _loop.call_soon_threadsafe(aio_future.set_exception,
                                   FoundException(error))
    lib.fdb_future_destroy(fdb_future)
示例#3
0
def _on_transaction_get_read_version(fdb_future, aio_future):
    aio_future = ffi.from_handle(aio_future)
    pointer = ffi.new("int64_t *")
    error = lib.fdb_future_get_int64(fdb_future, pointer)
    if error == 0:
        _loop.call_soon_threadsafe(aio_future.set_result, pointer[0])
    else:
        _loop.call_soon_threadsafe(aio_future.set_exception,
                                   FoundException(error))
    lib.fdb_future_destroy(fdb_future)
示例#4
0
def _estimated_size_bytes_callback(fdb_future, aio_future):
    aio_future = ffi.from_handle(aio_future)
    pointer = ffi.new("int64_t *")
    error = lib.fdb_future_get_int64(fdb_future, pointer)
    if error == 0:
        _loop.call_soon_threadsafe(aio_future.set_result, pointer[0])
        lib.fdb_future_destroy(fdb_future)
    else:
        _loop.call_soon_threadsafe(aio_future.set_exception,
                                   FoundException(error))
        lib.fdb_future_destroy(fdb_future)
示例#5
0
def _on_transaction_get(fdb_future, aio_future):
    aio_future = ffi.from_handle(aio_future)
    present = ffi.new("fdb_bool_t *")
    value = ffi.new("uint8_t **")
    value_length = ffi.new("int *")
    error = lib.fdb_future_get_value(fdb_future, present, value, value_length)
    if error == 0:
        if present[0] == 0:
            _loop.call_soon_threadsafe(aio_future.set_result, None)
            lib.fdb_future_destroy(fdb_future)
        else:
            # XXX: https://bitbucket.org/cffi/cffi/issues/380/ffibuffer-position-returns-a-buffer
            out = bytes(ffi.buffer(value[0], value_length[0]))
            _loop.call_soon_threadsafe(aio_future.set_result, out)
            lib.fdb_future_destroy(fdb_future)
    else:
        _loop.call_soon_threadsafe(aio_future.set_exception,
                                   FoundException(error))
        lib.fdb_future_destroy(fdb_future)