DEV Community

Discussion on: Pushing Native Messaging to the limits! - C vs Rust

Collapse
 
onkelt2 profile image
onkelT2

Nice article, thanks for putting this out there! The bare-bones example helped me do a quick sanity check whilst developing my own native messaging host in Rust.

However, there is currently a problem with the code in write_output as it exists on Github at the time of posting this comment:

let len = msg.len();
if len > 1024 * 1024 {
panic!("Message was too large, length: {}", len)
}
outstream.write(&len.to_ne_bytes())?;

This breaks the native messaging protocol when compiling on a 64-bit platform, because len is of type usize, which will be 8 bytes in length. The protocol expects only a 4 byte header denoting the message size. This is fixed easily enough with:

let len = msg.len() as u32;

Thanks again!