Sign in

    codec_bytes

    The streaming contract of byte-stream codecs: step through input chunks into bounded output slices, with bounded memory.

    codec
    compression
    streaming
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    3 days ago
    Downloads
    200

    #gaato/codec_bytes

    The contract of streaming byte-stream codecs in codecs.mbt: a decoder or an encoder is driven step by step, takes input in chunks of any size, writes into output slices of any size, and keeps its memory within the limits it was given. Code written against Decode and Encode works with every codec that implements them, such as gaato/zstd and gaato/brotli.

    Errors are gaato/codec's CodecError. The rules every codec keeps are in the repository's CONTRACT.md.

    Decode

    pub(open) trait Decode {
    fn step(Self, BytesView, MutArrayView[Byte], end~ : Bool) -> Status raise
    CodecError

    fn last_consumed(Self) -> Int
    fn last_produced(Self) -> Int
    fn reset(Self) -> Unit
    fn memory_usage(Self) -> Int
    }

    A decoder of a byte stream, driven step by step.

    A step consumes a prefix of input and writes a prefix of output (last_consumed and last_produced say how much), and returns why it stopped. end says whether input reaches the end of the data. The rules every decoder keeps are in the repository's CONTRACT.md: among them, errors stick until reset, and the result does not depend on how input and output are split.

    Encode

    pub(open) trait Encode {
    fn step(Self, BytesView, MutArrayView[Byte], action~ : EncodeAction) -> Status raise
    CodecError

    fn last_consumed(Self) -> Int
    fn last_produced(Self) -> Int
    fn reset(Self) -> Unit
    fn memory_usage(Self) -> Int
    }

    An encoder of a byte stream, driven step by step, with the same rules as Decode; action takes the place of end.

    EncodeAction

    pub(all) enum EncodeAction {
    Continue
    Flush
    Finish
    } derive(Eq,
    Debug
    )

    What an encoder's step should do with the input it has.

    EncodeAction::equal

    EncodeAction::not_equal

    fn EncodeAction::not_equal(x : EncodeAction, y : EncodeAction) -> Bool

    Status

    pub(all) enum Status {
    Done
    NeedMoreInput
    NeedMoreOutput
    } derive(Eq,
    Debug
    )

    Why a step stopped without an error.

    Status::equal

    fn Status::equal(Status, Status) -> Bool

    Status::not_equal

    fn Status::not_equal(x : Status, y : Status) -> Bool

    Status::to_repr

    Until

    pub(all) enum Until {
    EndOfInput
    EndOfMember
    } derive(Eq,
    Debug
    )

    Where a decoder stops, for formats whose streams can follow one another.

    Until::equal

    fn Until::equal(Until, Until) -> Bool

    Until::not_equal

    fn Until::not_equal(x : Until, y : Until) -> Bool

    Until::to_repr

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io