Backend-neutral incremental byte-stream framing for MoonBit
moon test --deny-warn
moon run cmd/main///|
test {
let decoder = @moonframing.Decoder::new(max_frame_size=4096)
let wire = @moonframing.encode_frame(b"hello")
match decoder.feed(wire) {
Ok(frames) => assert_true(frames[0] == b"hello")
Err(_) => fail("valid frame")
}
}pub enum FrameError {
NeedMore
MalformedVarint
FrameTooLarge(Int, Int)
MissingChecksum
ChecksumMismatch(UInt, UInt)
BufferLimitExceeded(Int, Int)
}fn crc32(data : Bytes) -> UIntfn decode_varint(data : Bytes, offset? : Int) -> (Int, Int)?fn encode_checked_frame(payload : Bytes) -> Bytesfn encode_frame(payload : Bytes) -> Bytesfn encode_varint(value : Int) -> BytesInstall
Download zipBackend-neutral incremental byte-stream framing for MoonBit