How to handle 64 MiB encoded JSON to Rust Native Messaging host?
โ Rust ๐ 2026-01-01 ๐ค surdeus ๐๏ธ 2I'm working on implementing 64 MiB input support for the Native Messaging hosts I've written, and gotten a bunch of help writing.
So far I've completed JavaScript that works using node, deno, and bun; Bytecode Alliance's javy which depends on QuickJS (Rust crate) to compile JavaScript source to WASM; and AssemblyScript (see Parsing JSON manually - #11 by guest271314).
This is the protocol Native messaging | Chrome for Developers
Chrome starts each native messaging host in a separate process and communicates with it using standard input (
stdin) and standard output (stdout). The same format is used to send messages in both directions; each message is serialized using JSON, UTF-8 encoded and is preceded with 32-bit message length in native byte order. The maximum size of a single message from the native messaging host is 1 MB, mainly to protect Chrome from misbehaving native applications. The maximum size of the message sent to the native messaging host is 64 MiB.
What I'm working wiith right now NativeMessagingHosts/nm_rust.rs at main ยท guest271314/NativeMessagingHosts ยท GitHub.
I am not a Rustacean; I don't write Rust everyday. I think getMessage() doesn't have to change; only sendMessage() needs to be modified to parse, extract, and send valid JSON (encoded as u8 in the working code I've got) back to the browser
pub fn sendMessage(message: &[u8]) -> io::Result<()> {
let mut stdout = io::stdout();
let length = message.len() as u32;
stdout.write_all(&length.to_ne_bytes())?;
stdout.write_all(message)?;
stdout.flush()?;
Ok(())
}
How would you go about doing that?
Related: How to implement a Native Messaging host using only Rust standard library?
1 post - 1 participant
๐ท๏ธ Rust_feed