Skip to main content

rayforce_sys/
lib.rs

1//! Raw FFI bindings to the RayforceDB v2 core (`librayforce`).
2//!
3//! Generated by `bindgen` from the core's own headers: the public
4//! `rayforce.h`, plus the private ones declaring the handful of internal
5//! symbols the safe crate needs (`INTERNAL_FNS` in `build.rs` is the full
6//! list). This crate is `unsafe` and 1:1 with the C ABI; use the safe
7//! `rayforce` crate instead.
8//!
9//! The header's function-like macros (`ray_type`, `ray_len`, `ray_data`,
10//! `RAY_IS_ERR`, `RAY_IS_NULL`, …) are not emitted by bindgen — the safe crate
11//! reimplements them in Rust against the generated [`ray_t`] layout.
12#![allow(non_upper_case_globals)]
13#![allow(non_camel_case_types)]
14#![allow(non_snake_case)]
15#![allow(dead_code)]
16#![allow(clippy::all)]
17
18include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
19
20// Q IPC wire-format client from the shared `rayforce-q` repo (q.c/q.h). Not
21// part of the engine bindings; hand-declared here to match `q.h`.
22extern "C" {
23    /// Open a TCP connection to a Q server and perform the login handshake.
24    /// Returns a connection fd (>= 0), or a negative `Q_ERR_*` code.
25    pub fn q_connect(
26        host: *const ::std::os::raw::c_char,
27        port: ::std::os::raw::c_int,
28        user: *const ::std::os::raw::c_char,
29        password: *const ::std::os::raw::c_char,
30        timeout_ms: ::std::os::raw::c_int,
31    ) -> ::std::os::raw::c_int;
32    /// Close a connection fd. Returns 0 on success, -1 on an invalid fd.
33    pub fn q_close(fd: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
34    /// Encode + exchange + decode: send `msg` and return the decoded response
35    /// (possibly a `RAY_ERROR`), or null on a transport/serialization failure
36    /// with a short reason written to `err`.
37    pub fn q_send(
38        fd: ::std::os::raw::c_int,
39        msg: *mut ray_t,
40        err: *mut ::std::os::raw::c_char,
41        errlen: usize,
42    ) -> *mut ray_t;
43    /// Decompress (if needed) and deserialize a response *body* (wire header
44    /// already stripped) into a freshly-owned object — possibly a `RAY_ERROR`
45    /// carrying a Q server-side error. Touches the symbol table: engine thread
46    /// only. Returns null on a decode failure with a short reason in `err`.
47    pub fn q_decode(
48        resp: *mut u8,
49        resp_len: i64,
50        compressed: ::std::os::raw::c_int,
51        err: *mut ::std::os::raw::c_char,
52        errlen: usize,
53    ) -> *mut ray_t;
54}
55
56/// `q_connect` failure codes (mirrors `q.h`).
57pub const Q_ERR_SOCKET: ::std::os::raw::c_int = -1;
58pub const Q_ERR_HANDSHAKE: ::std::os::raw::c_int = -2;
59pub const Q_ERR_TIMEOUT: ::std::os::raw::c_int = -3;
60
61/// `ray_ipc_connect` failure codes.
62///
63/// The public header declares the function with no contract at all
64/// (`include/rayforce.h`); this mirrors the comment on the private
65/// `src/core/ipc.h` declaration and, for [`RAY_IPC_ERR_OS`], the
66/// `connect_fail_code()` classifier in `src/core/ipc.c` that the header's
67/// comment predates. Hand-maintained against a core bump, like `Q_ERR_*`.
68///
69/// [`RAY_IPC_ERR_REFUSED`] is the documented name for -1, but the core also
70/// returns it for a missing poll, a credential buffer overflow and a failed
71/// poll registration — treat it as the catch-all it is.
72pub const RAY_IPC_ERR_REFUSED: i64 = -1;
73/// The server demands credentials and the caller supplied no password.
74pub const RAY_IPC_ERR_AUTH_REQUIRED: i64 = -2;
75/// The server rejected the credentials.
76pub const RAY_IPC_ERR_AUTH_FAILED: i64 = -3;
77/// The peer speaks a different serialization wire version.
78pub const RAY_IPC_ERR_WIRE_VERSION: i64 = -4;
79/// No answer within the connect/handshake budget. The core folds `EAGAIN` and
80/// `EWOULDBLOCK` in here too, so this also covers a live server that is busy
81/// inside a long evaluation.
82pub const RAY_IPC_ERR_TIMEOUT: i64 = -5;
83/// Some other OS error; the core leaves `errno` holding it.
84pub const RAY_IPC_ERR_OS: i64 = -6;