Lines
0 %
Functions
Branches
100 %
//! Host function wrappers for WASM scripts.
//!
//! These functions are safe to call from within the Nomisync WASM runtime.
//! The WASM environment guarantees:
//! - Host functions are always linked
//! - Memory access is bounds-checked (traps on OOB)
//! - No undefined behavior, only traps on errors
unsafe extern "C" {
fn get_input_offset() -> u32;
fn get_output_offset() -> u32;
fn get_strings_offset() -> u32;
fn generate_uuid(out_ptr: u32);
fn write_string(ptr: u32, len: u32) -> u32;
fn log(level: u32, msg_ptr: u32, msg_len: u32);
fn get_timestamp() -> i64;
}
#[must_use]
pub fn input_offset() -> u32 {
unsafe { get_input_offset() }
pub fn output_offset() -> u32 {
unsafe { get_output_offset() }
pub fn strings_offset() -> u32 {
unsafe { get_strings_offset() }
pub fn new_uuid() -> [u8; 16] {
let mut uuid = [0u8; 16];
unsafe { generate_uuid(uuid.as_mut_ptr() as u32) };
uuid
pub fn write_output_string(s: &str) -> u32 {
unsafe { write_string(s.as_ptr() as u32, s.len() as u32) }
pub fn timestamp() -> i64 {
unsafe { get_timestamp() }
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum LogLevel {
Debug = 0,
Info = 1,
Warn = 2,
Error = 3,
pub fn log_message(level: LogLevel, msg: &str) {
unsafe { log(level as u32, msg.as_ptr() as u32, msg.len() as u32) }
pub fn log_debug(msg: &str) {
log_message(LogLevel::Debug, msg);
pub fn log_info(msg: &str) {
log_message(LogLevel::Info, msg);
pub fn log_warn(msg: &str) {
log_message(LogLevel::Warn, msg);
pub fn log_error(msg: &str) {
log_message(LogLevel::Error, msg);