Deterministic length-prefixed binary framing for MoonBit
MW magic | version | kind | 3 字节大端 payload 长度 | checksum | payloadlet frame = @moonwire.Frame::new(1, 7, b"hello").unwrap()
let wire = @moonwire.encode(frame)
let same = @moonwire.decode(wire).unwrap()moon fmt --check
moon check --target wasm-gc --deny-warn
moon check --target wasm --deny-warn
moon check --target js --deny-warn
moon check --target native --deny-warn
moon test --target wasm-gcpub struct Frame {
version : Int
kind : Int
payload : Bytes
}pub struct Header {
version : Int
kind : Int
payload_length : Int
checksum : Int
}fn checksum_matches(data : Bytes) -> Result[Bool, String]fn encode_checked(version : Int, kind : Int, payload : Bytes) -> Result[Bytes, String]fn encoded_size(payload_length : Int) -> Result[Int, String]fn frame_checksum(version : Int, kind : Int, payload : Bytes) -> Result[Int, String]fn header_kind(data : Bytes) -> Result[Int, String]fn header_version(data : Bytes) -> Result[Int, String]fn max_payload_length() -> Intfn payload_length(data : Bytes) -> Result[Int, String]fn validate(data : Bytes) -> Result[Unit, String]Install
Download zipDeterministic length-prefixed binary framing for MoonBit