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.1
    License
    Apache-2.0
    Last updated
    3 hours ago
    Downloads
    51

    Dependencies

    #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. This package re-exports it with ErrorKind, Limit and Resource, so it is the only import a consumer needs to name them. In a catch on a codec's step, CodecError(kind, message) and the kinds match unqualified; elsewhere, qualify a constructor by its type, as in @codec_bytes.CodecError::CodecError(kind, _). The rules every codec keeps, streams that never end among them, are in the repository's CONTRACT.md.

    CodecError

    using @gaato/codec { type CodecError }

    The error every codec raises, its kinds, and the limits a stream can exceed, from gaato/codec, so that a caller of a codec can name them with this package as its only import. A constructor is matched unqualified, as in CodecError(Corrupt, _), where the type is known (a catch on a codec's step), or qualified by its type, as in @codec_bytes.CodecError::CodecError(kind, _).

    ErrorKind

    using @gaato/codec { type ErrorKind }

    The error every codec raises, its kinds, and the limits a stream can exceed, from gaato/codec, so that a caller of a codec can name them with this package as its only import. A constructor is matched unqualified, as in CodecError(Corrupt, _), where the type is known (a catch on a codec's step), or qualified by its type, as in @codec_bytes.CodecError::CodecError(kind, _).

    Limit

    using @gaato/codec { type Limit }

    The error every codec raises, its kinds, and the limits a stream can exceed, from gaato/codec, so that a caller of a codec can name them with this package as its only import. A constructor is matched unqualified, as in CodecError(Corrupt, _), where the type is known (a catch on a codec's step), or qualified by its type, as in @codec_bytes.CodecError::CodecError(kind, _).

    Resource

    using @gaato/codec { type Resource }

    The error every codec raises, its kinds, and the limits a stream can exceed, from gaato/codec, so that a caller of a codec can name them with this package as its only import. A constructor is matched unqualified, as in CodecError(Corrupt, _), where the type is known (a catch on a codec's step), or qualified by its type, as in @codec_bytes.CodecError::CodecError(kind, _).

    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, a step that raises first writes all the output the input determines before the error (answering NeedMoreOutput if the slice fills first) and reports what it consumed and wrote, errors stick until reset, and the output and the error do 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