未实现php和FFI返回结构/联合
我想将rust库绑定到php。 我有一个.h文件,其中包含一些函数和结构声明:未实现php和FFI返回结构/联合,php,c,ffi,php-ffi,Php,C,Ffi,Php Ffi,我想将rust库绑定到php。 我有一个.h文件,其中包含一些函数和结构声明: typedef struct { const char* content; //char content; uint32_t len; } tc_string_t; typedef struct { tc_string_t result_json; tc_string_t error_json; } tc_response_t; typedef struct { } t
typedef struct {
const char* content;
//char content;
uint32_t len;
} tc_string_t;
typedef struct {
tc_string_t result_json;
tc_string_t error_json;
} tc_response_t;
typedef struct {
} tc_response_handle_t;
enum tc_response_flags_t {
tc_response_finished = 1,
};
typedef void (*tc_on_response_t)(
int32_t request_id,
tc_string_t result_json,
tc_string_t error_json,
int32_t flags);
void tc_json_request_async(
uint32_t context,
tc_string_t method,
tc_string_t params_json,
int32_t request_id,
tc_on_response_t on_result);
tc_response_handle_t* tc_json_request(
uint32_t context,
tc_string_t method,
tc_string_t params_json);
tc_response_t tc_read_json_response(const tc_response_handle_t* handle);
void tc_destroy_json_response(const tc_response_handle_t* handle);
当我从PHP调用时:
$ffi->tc_read_json_response($handle);
我得到了一个错误:
FFI return struct/union is not implemented
如何实现返回?我认为PHP还不支持将嵌套结构或联合映射到
FFI\CData
。基本上不可能调用将返回这些类型数据的C API
您可以从这里的PHPSRC中看到:PHP结构中唯一受支持的属性类型本质上是标量或指针。此时会在此处触发您看到的错误:
我认为唯一的选择是编写自己的C包装器,提供返回更简单数据类型的函数。我认为PHP还不支持将嵌套结构或联合映射到
FFI\CData
。基本上不可能调用将返回这些类型数据的C API
您可以从这里的PHPSRC中看到:PHP结构中唯一受支持的属性类型本质上是标量或指针。此时会在此处触发您看到的错误:
我认为唯一的选择是编写自己的C包装器,它提供返回更简单数据类型的函数