qos-sdk Reference
qos_sdk::input::read
Reads the JSON payload provided by the host environment (typically passed from the guest's Micro-UI upon scanning the QR code).
#Signature
pub fn read() -> Option<Vec<u8>>
#Usage
Because Q-OS WASM modules execute in a #[no_std] environment, this function returns a raw byte vector. You will typically use a lightweight JSON parser like serde-json-core or microserde to deserialize the bytes into a Rust struct.
src/lib.rs
use qos_sdk::input;
#[no_mangle]
pub extern "C" fn run() -> i32 {
// 1. Read input bytes from host
if let Some(bytes) = input::read() {
// 2. Convert to string (if expecting UTF-8)
if let Ok(json_str) = core::str::from_utf8(&bytes) {
qos_sdk::log_msg(qos_sdk::LogLevel::Info, "Received payload");
// 3. Parse JSON...
}
}
0
}#Under the Hood
This wrapper calls the raw ABI function __qos_input_len() to determine the buffer size, allocates a Vec<u8>, and then calls __qos_input_read(*mut u8) to instruct the host to write the payload directly into the WASM sandbox's linear memory.