#[repr(C)]pub struct NrosTransportOps {
pub abi_version: u32,
pub _reserved: u32,
pub user_data: *mut c_void,
pub open: unsafe extern "C" fn(user_data: *mut c_void, params: *const c_void) -> i32,
pub close: unsafe extern "C" fn(user_data: *mut c_void),
pub write: unsafe extern "C" fn(user_data: *mut c_void, buf: *const u8, len: usize) -> i32,
pub read: unsafe extern "C" fn(user_data: *mut c_void, buf: *mut u8, len: usize, timeout_ms: u32) -> i32,
}Expand description
Phase 115.A — runtime-pluggable custom transport. Caller fills in
the four fn pointers, hands the struct to set_custom_transport,
and the active backend treats it as the read / write surface for
every wire frame.
#[repr(C)] so this is the SAME struct that
nros_transport_ops_t (C) and nros::TransportOps (C++) point at
— single layout, no parallel definitions to drift.
§Return-code conventions
open / write return NROS_RMW_RET_OK (== 0) on success and
a negative nros_ret_t (see nros-rmw-cffi) on failure. read
returns the non-negative byte count on success or a negative
nros_ret_t on error / timeout.
§Safety contract for the four fn pointers
- All callbacks receive
user_dataas their first argument. The pointer is whatever the caller stored at registration time; the runtime never dereferences it. buf/lendescribe a contiguous byte region the callback may read (write) or write (read). The callback must NOT retain pointers across the call.params(inopen) is opaque per-transport metadata threaded through fromset_custom_transport. May beNULL.
Fields§
§abi_version: u32Phase 115.A.2 — ABI version. Consumers MUST fill in
NROS_TRANSPORT_OPS_ABI_VERSION_V1; mismatched values are
rejected at registration time with
TransportError::IncompatibleAbi (NROS_RMW_RET_INCOMPATIBLE_ABI
at the C boundary). Reserved for future minor-version
detection — see the const’s doc-comment.
_reserved: u32Phase 115.A.2 — reserved padding to keep the struct alignment-stable across appends. Must be zero.
user_data: *mut c_voidOpaque caller context, threaded back into every callback as
the first argument. Lifetime: must outlive the transport’s
active period (i.e. until close returns).
open: unsafe extern "C" fn(user_data: *mut c_void, params: *const c_void) -> i32Open the underlying medium. params is opaque per-transport
metadata (e.g. UART baud rate, USB-CDC endpoint id) supplied
at registration time.
close: unsafe extern "C" fn(user_data: *mut c_void)Tear the transport down. Complement of open. After close
returns, the runtime will not invoke read or write on this
transport unless set_custom_transport is called again.
write: unsafe extern "C" fn(user_data: *mut c_void, buf: *const u8, len: usize) -> i32Send len bytes from buf. Returns 0 on success, negative
nros_ret_t on failure. Must NOT block beyond a brief
hardware retry; long blocking should surface as
NROS_RMW_RET_TIMEOUT (-2).
read: unsafe extern "C" fn(user_data: *mut c_void, buf: *mut u8, len: usize, timeout_ms: u32) -> i32Receive up to len bytes into buf within timeout_ms.
Returns the non-negative byte count on success (may be less
than len), or a negative nros_ret_t on error / timeout.
Trait Implementations§
Source§impl Clone for NrosTransportOps
impl Clone for NrosTransportOps
Source§fn clone(&self) -> NrosTransportOps
fn clone(&self) -> NrosTransportOps
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more