faiss/c_api/impl/io_c.h
Kaival Parikh a4401c13d8 Allow using custom index readers and writers (#4180)
Summary:
### Description

- Create custom readers and writers for index IO, which take function pointers as input
- Also expose these from the C_API

This is helpful for FFI use, where calling processes would pass upcall stubs for streamlined IO

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4180

Reviewed By: gtwang01

Differential Revision: D71208266

Pulled By: mnorris11

fbshipit-source-id: ab82397d4780a2a07c7bfdc52329968377f42af4
2025-04-01 11:05:29 -07:00

51 lines
1.1 KiB
C

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// -*- c -*-
#ifndef FAISS_IO_C_H
#define FAISS_IO_C_H
#include <stddef.h>
#include "../faiss_c.h"
#ifdef __cplusplus
extern "C" {
#endif
FAISS_DECLARE_CLASS(IOReader)
FAISS_DECLARE_DESTRUCTOR(IOReader)
FAISS_DECLARE_CLASS(IOWriter)
FAISS_DECLARE_DESTRUCTOR(IOWriter)
/*******************************************************
* Custom reader + writer
*
* Reader and writer which wraps a function pointer,
* primarily for FFI use.
*******************************************************/
FAISS_DECLARE_CLASS(CustomIOReader)
FAISS_DECLARE_DESTRUCTOR(CustomIOReader)
int faiss_CustomIOReader_new(
FaissCustomIOReader** p_out,
size_t (*func_in)(void* ptr, size_t size, size_t nitems));
FAISS_DECLARE_CLASS(CustomIOWriter)
FAISS_DECLARE_DESTRUCTOR(CustomIOWriter)
int faiss_CustomIOWriter_new(
FaissCustomIOWriter** p_out,
size_t (*func_in)(const void* ptr, size_t size, size_t nitems));
#ifdef __cplusplus
}
#endif
#endif