rayforce-sys 1.3.0

Raw FFI bindings to the RayforceDB v2 core (librayforce)
Documentation
//! Raw FFI bindings to the RayforceDB v2 core (`librayforce`).
//!
//! Generated by `bindgen` from the core's own headers: the public
//! `rayforce.h`, plus the private ones declaring the handful of internal
//! symbols the safe crate needs (`INTERNAL_FNS` in `build.rs` is the full
//! list). This crate is `unsafe` and 1:1 with the C ABI; use the safe
//! `rayforce` crate instead.
//!
//! The header's function-like macros (`ray_type`, `ray_len`, `ray_data`,
//! `RAY_IS_ERR`, `RAY_IS_NULL`, …) are not emitted by bindgen — the safe crate
//! reimplements them in Rust against the generated [`ray_t`] layout.
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(clippy::all)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

// Q IPC wire-format client from the shared `rayforce-q` repo (q.c/q.h). Not
// part of the engine bindings; hand-declared here to match `q.h`.
extern "C" {
    /// Open a TCP connection to a Q server and perform the login handshake.
    /// Returns a connection fd (>= 0), or a negative `Q_ERR_*` code.
    pub fn q_connect(
        host: *const ::std::os::raw::c_char,
        port: ::std::os::raw::c_int,
        user: *const ::std::os::raw::c_char,
        password: *const ::std::os::raw::c_char,
        timeout_ms: ::std::os::raw::c_int,
    ) -> ::std::os::raw::c_int;
    /// Close a connection fd. Returns 0 on success, -1 on an invalid fd.
    pub fn q_close(fd: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
    /// Encode + exchange + decode: send `msg` and return the decoded response
    /// (possibly a `RAY_ERROR`), or null on a transport/serialization failure
    /// with a short reason written to `err`.
    pub fn q_send(
        fd: ::std::os::raw::c_int,
        msg: *mut ray_t,
        err: *mut ::std::os::raw::c_char,
        errlen: usize,
    ) -> *mut ray_t;
    /// Decompress (if needed) and deserialize a response *body* (wire header
    /// already stripped) into a freshly-owned object — possibly a `RAY_ERROR`
    /// carrying a Q server-side error. Touches the symbol table: engine thread
    /// only. Returns null on a decode failure with a short reason in `err`.
    pub fn q_decode(
        resp: *mut u8,
        resp_len: i64,
        compressed: ::std::os::raw::c_int,
        err: *mut ::std::os::raw::c_char,
        errlen: usize,
    ) -> *mut ray_t;
    /// Serialize `msg` into a complete Q wire request (8-byte header + body).
    /// The buffer is malloc'd by C and must be released with `libc::free`.
    /// `q_encode` always stamps the header's message-type byte as SYNC; a
    /// publisher retypes `req[1]` in place to send ASYNC or RESPONSE.
    /// Touches the symbol table: engine thread only.
    pub fn q_encode(
        msg: *mut ray_t,
        req: *mut *mut u8,
        req_len: *mut i64,
        err: *mut ::std::os::raw::c_char,
        errlen: usize,
    ) -> ::std::os::raw::c_int;
    /// Send a pre-encoded request on `fd` and read the raw response *body*.
    /// Pure socket I/O — the half of `q_send` that a runtime with a global lock
    /// can perform with that lock released.
    pub fn q_exchange(
        fd: ::std::os::raw::c_int,
        req: *const u8,
        req_len: i64,
        resp: *mut *mut u8,
        resp_len: *mut i64,
        compressed: *mut ::std::os::raw::c_int,
        err: *mut ::std::os::raw::c_char,
        errlen: usize,
    ) -> ::std::os::raw::c_int;
}

// Q wire-format *server* from `rayforce-q` (q_server.c/q_server.h), available
// since rayforce-q 2.1.0. Where the client above lets you call a Q server, this
// lets you receive from one.
//
// `q_send` is request/response over a blocking socket, so a frame the peer
// pushes unsolicited would be read as the answer to the next call — which makes
// a subscription impossible with the client alone. Attaching the fd to a
// rayforce poll fixes that: the event loop owns the reads and routes each frame
// by message type, waking a parked `q_conn_send` on a RESPONSE and dispatching
// anything else to the function the publisher named.
extern "C" {
    /// Register a Q-protocol *listener* on `poll`, bound to TCP `port`.
    /// Returns the poll selector id (>= 0), or -1 on failure.
    pub fn q_serve(poll: *mut ray_poll_t, port: ::std::os::raw::c_int) -> i64;
    /// Put an already-connected, already-handshaken `q_connect` fd under
    /// `poll`'s rx machine. Returns a poll selector id (>= 0) — the handle for
    /// the two calls below — or -1. **The fd is owned by the poll from here on;
    /// do not `q_close` it.**
    pub fn q_conn_attach(poll: *mut ray_poll_t, fd: ::std::os::raw::c_int) -> i64;
    /// Sync round-trip on an attached connection: write a SYNC frame, then pump
    /// this connection until its RESPONSE arrives — dispatching, not swallowing,
    /// any frame that arrives in between. So a bound handler can fire before
    /// this returns. Returns a freshly-owned object, possibly a `RAY_ERROR`.
    /// Refuses a nested call from inside a handler.
    pub fn q_conn_send(poll: *mut ray_poll_t, id: i64, msg: *mut ray_t) -> *mut ray_t;
    /// Close an attached connection and release its state. Illegal once the rx
    /// machine has already deregistered the selector — check `ray_poll_get`.
    pub fn q_conn_close(poll: *mut ray_poll_t, id: i64);
}

/// `q_connect` failure codes (mirrors `q.h`).
pub const Q_ERR_SOCKET: ::std::os::raw::c_int = -1;
pub const Q_ERR_HANDSHAKE: ::std::os::raw::c_int = -2;
pub const Q_ERR_TIMEOUT: ::std::os::raw::c_int = -3;

/// `ray_ipc_connect` failure codes.
///
/// The public header declares the function with no contract at all
/// (`include/rayforce.h`); this mirrors the comment on the private
/// `src/core/ipc.h` declaration and, for [`RAY_IPC_ERR_OS`], the
/// `connect_fail_code()` classifier in `src/core/ipc.c` that the header's
/// comment predates. Hand-maintained against a core bump, like `Q_ERR_*`.
///
/// [`RAY_IPC_ERR_REFUSED`] is the documented name for -1, but the core also
/// returns it for a missing poll, a credential buffer overflow and a failed
/// poll registration — treat it as the catch-all it is.
pub const RAY_IPC_ERR_REFUSED: i64 = -1;
/// The server demands credentials and the caller supplied no password.
pub const RAY_IPC_ERR_AUTH_REQUIRED: i64 = -2;
/// The server rejected the credentials.
pub const RAY_IPC_ERR_AUTH_FAILED: i64 = -3;
/// The peer speaks a different serialization wire version.
pub const RAY_IPC_ERR_WIRE_VERSION: i64 = -4;
/// No answer within the connect/handshake budget. The core folds `EAGAIN` and
/// `EWOULDBLOCK` in here too, so this also covers a live server that is busy
/// inside a long evaluation.
pub const RAY_IPC_ERR_TIMEOUT: i64 = -5;
/// Some other OS error; the core leaves `errno` holding it.
pub const RAY_IPC_ERR_OS: i64 = -6;

/// Function attribute flags for `ray_fn_unary` / `ray_fn_vary`, from the core's
/// `src/lang/eval.h:33-40`. They are `#define`s in a header `wrapper.h` does
/// not include, so bindgen never sees them.
///
/// `RAY_FN_NONE` is what a plain callback wants: no auto-mapping over vectors,
/// no aggregation, args evaluated normally.
pub const RAY_FN_NONE: u8 = 0x00;
pub const RAY_FN_LEFT_ATOMIC: u8 = 0x01;
pub const RAY_FN_RIGHT_ATOMIC: u8 = 0x02;
pub const RAY_FN_ATOMIC: u8 = 0x04;
pub const RAY_FN_AGGR: u8 = 0x08;
pub const RAY_FN_SPECIAL_FORM: u8 = 0x10;
pub const RAY_FN_RESTRICTED: u8 = 0x20;
pub const RAY_FN_LAZY_AWARE: u8 = 0x80;