| Crates.io | endurox-sys |
| lib.rs | endurox-sys |
| version | 0.1.1 |
| created_at | 2025-11-08 19:39:44.171535+00 |
| updated_at | 2025-11-08 21:16:03.097159+00 |
| description | Low-level FFI bindings for Enduro/X middleware |
| homepage | https://github.com/serdzz/endurox-rust |
| repository | https://github.com/serdzz/endurox-rust |
| max_upload_size | |
| id | 1923206 |
| size | 74,976 |
Low-level Rust FFI bindings for Enduro/X middleware.
Enduro/X is a high-performance, open-source middleware platform that implements the XATMI API. This crate provides safe and unsafe Rust bindings to the Enduro/X C API, enabling you to build distributed transaction processing applications in Rust.
tpcall(), tpacall(), tpreturn(), etc.Bchg(), Bget(), etc.atmisrvnomain()tpinit(), tpterm()#[derive(UbfStructDerive)] for automatic serializationAdd this to your Cargo.toml:
[dependencies]
endurox-sys = { version = "0.1", features = ["ubf", "server"] }
NDRX_HOME (Required)Points to the Enduro/X installation directory. Used by the build script to locate Enduro/X libraries and headers.
export NDRX_HOME=/opt/endurox
The build script uses this to:
libatmi, libubf, libnstd, etc.)NDRX_APPHOME (Optional)Points to your application's home directory. Used by the build script to locate UBF field table definitions (ubftab/ directory) for generating Rust constants.
export NDRX_APPHOME=/path/to/your/app
When set, the build script looks for *.fd.h files in $NDRX_APPHOME/ubftab/ and generates Rust constants for UBF field IDs. This allows you to use field constants like T_NAME_FLD directly in your code.
Build-time behavior:
NDRX_APPHOME is set: looks for $NDRX_APPHOME/ubftab/*.fd.h../ubftab/*.fd.h (relative to crate directory, for local development)Example:
use endurox_sys::*;
unsafe {
// Use generated field constants
Bchg(buffer, T_NAME_FLD, 0, name.as_ptr() as *mut i8, 0);
Bchg(buffer, T_AMOUNT_FLD, 0, &amount as *const _ as *mut i8, 0);
}
use endurox_sys::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
unsafe {
// Initialize connection
tpinit(std::ptr::null_mut())?;
// Allocate UBF buffer
let buf = tpalloc(b"UBF\0".as_ptr() as *mut i8, std::ptr::null_mut(), 1024);
// Call service
let mut len = 1024;
tpcall(
b"MYSERVICE\0".as_ptr() as *mut i8,
buf,
0,
&mut buf,
&mut len,
0
)?;
// Free buffer and disconnect
tpfree(buf);
tpterm();
}
Ok(())
}
use endurox_sys::*;
#[derive(UbfStructDerive)]
struct Request {
#[ubf_field(1000)]
transaction_id: String,
#[ubf_field(1001)]
amount: i64,
}
#[derive(UbfStructDerive)]
struct Response {
#[ubf_field(2000)]
status: String,
#[ubf_field(2001)]
message: String,
}
#[no_mangle]
pub extern "C" fn MYSERVICE(p_svc: *mut TPSVCINFO) {
unsafe {
let svc = &*p_svc;
// Deserialize request
let req = match Request::from_ubf(svc.data as *mut UBFH) {
Ok(r) => r,
Err(_) => {
tpreturn(TPFAIL, 0, std::ptr::null_mut(), 0, 0);
return;
}
};
// Process request
let resp = Response {
status: "SUCCESS".to_string(),
message: format!("Processed {}", req.transaction_id),
};
// Serialize response
if resp.to_ubf(svc.data as *mut UBFH).is_ok() {
tpreturn(TPSUCCESS, 0, svc.data, 0, 0);
} else {
tpreturn(TPFAIL, 0, std::ptr::null_mut(), 0, 0);
}
}
}
ubfEnables UBF buffer API bindings:
Bchg(), Bget(), Badd(), Bdel()serverEnables server-side bindings:
atmisrvnomain() - Main server entry pointtpsvrinit(), tpsvrdone() - Server lifecycle hookstpadvertise(), tpunadvertise() - Service advertisementclientEnables client-side bindings:
tpinit(), tpterm() - Connection managementtpcall(), tpacall(), tpgetrply() - Service callsderiveEnables #[derive(UbfStructDerive)] macro for automatic UBF serialization.
Requires the endurox-derive crate.
Most functions in this crate are marked unsafe as they interact with C FFI and raw pointers. Safe wrappers can be found in higher-level crates built on top of endurox-sys.
Always ensure:
tpinit() is called before any XATMI operationstpfree() and tpterm()Use tperrno() and tpstrerror() to get error information:
use endurox_sys::*;
unsafe {
if tpcall(...).is_err() {
let errno = tperrno();
let error = std::ffi::CStr::from_ptr(tpstrerror(errno))
.to_string_lossy();
eprintln!("Error: {}", error);
}
}
For complete API documentation, see docs.rs/endurox-sys.
For Enduro/X documentation, visit www.endurox.org/dokuwiki.
Licensed under the MIT license. See LICENSE for details.
endurox-derive - Derive macros for UBF serializationendurox - High-level safe API (coming soon)