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 ByteOrder {
BigEndian
LittleEndian
}pub struct DelimiterDecoder {
buffer : Array[Byte]
delimiter : Bytes
strip_delimiter : Bool
max_frame_size : Int
max_buffer_size : Int
}fn DelimiterDecoder::feed(self : DelimiterDecoder, chunk : Bytes) -> Result[Array[Bytes], FrameError]fn DelimiterDecoder::new(delimiter : Bytes, strip_delimiter? : Bool, max_frame_size? : Int, max_buffer_size? : Int) -> Result[DelimiterDecoder, FrameError]pub enum FrameError {
NeedMore
MalformedVarint
InvalidConfiguration(String)
LengthFieldOverflow(Int, Int)
InvalidLengthAdjustment(Int)
FrameTooLarge(Int, Int)
MissingChecksum
ChecksumMismatch(UInt, UInt)
BufferLimitExceeded(Int, Int)
}fn LengthDelimitedCodec::encode(self : LengthDelimitedCodec, payload : Bytes) -> Result[Bytes, FrameError]fn LengthDelimitedCodec::feed(self : LengthDelimitedCodec, chunk : Bytes) -> Result[Array[Bytes], FrameError]fn LengthDelimitedCodec::new(length_field_offset? : Int, length_field_length? : Int, length_adjustment? : Int, num_skip? : Int, byte_order? : ByteOrder, max_frame_size? : Int, max_buffer_size? : Int) -> Result[LengthDelimitedCodec, FrameError]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