Expand description
§qubit-codec
Domain-neutral codec traits and buffer conversion primitives.
qubit-codec is the foundation shared by the Qubit binary, text, misc, and
I/O codec crates. It defines the small contracts that concrete format crates
build on, without shipping concrete binary or text formats itself.
§Overview
The crate provides:
Codecfor low-level single-value codecs over caller-managed buffers.CodecValueEncoderandCodecValueDecoderfor owned one-value convenience APIs.CodecTranscodeEncoder,CodecTranscodeDecoder, andCodecTranscodeConverterfor strict streaming adapters around aCodec.engine::TranscodeEncodeEngine,engine::TranscodeDecodeEngine, andengine::TranscodeConvertEnginefor policy-aware buffered loops.engine::TranscodeEncodeHooksandengine::TranscodeDecodeHooksfor replacement, skip, report, finish, and reset policy decisions.Transcoder,TranscodeProgress, andTranscodeStatusfor caller-managed streaming conversion.ValueEncoderandValueDecoderfor whole-value convenience APIs.ByteOrder,ByteOrderSpec,BigEndian,LittleEndian, andNativeEndianfor shared byte-order metadata.qubit_utils::nonzero()for checkedNonZeroUsizeconstruction shared by codec implementations.
Concrete codecs live in sibling crates such as qubit-codec-binary,
qubit-codec-text, and qubit-codec-misc.
§Choosing an Abstraction
Pick the smallest layer that matches the shape of the problem:
What are you writing?
+-- A codec for one logical value
| (UTF-8 char, LEB128 integer, fixed-width scalar, ...)
| -> implement Codec
|
+-- A whole-value codec where a single-value quantum is not useful
| (Base64 text, percent encoding, escaped strings, ...)
| -> implement ValueEncoder<Input> / ValueDecoder<Input>
|
+-- A strict streaming wrapper around an existing Codec
| -> use CodecTranscodeDecoder<C> / CodecTranscodeEncoder<C>
| / CodecTranscodeConverter<D, E>
|
+-- An owned-output wrapper around an existing Codec
| -> use CodecValueEncoder<C> / CodecValueDecoder<C>
|
+-- A streaming codec with policy decisions
(skip, replace, count, report, finish output, ...)
-> implement engine::TranscodeDecodeHooks<C>
/ engine::TranscodeEncodeHooks<C>
and use engine::TranscodeDecodeEngine<C, H>
/ engine::TranscodeEncodeEngine<C, H>Unit-to-unit conversions, such as UTF-8 bytes to UTF-16 units, compose a
decode side and an encode side. Use CodecTranscodeConverter for a strict
pipeline and engine::TranscodeConvertEngine when either side needs
policy hooks.
§Layer Overview
concrete I/O crates
|
TranscodeDecodeInput / TranscodeEncodeOutput [feature = "io"]
|
Transcode*Engine + Transcode*Hooks
CodecTranscodeDecoder / Encoder / Converter
|
Transcoder + TranscodeProgress + TranscodeStatus
ValueEncoder / ValueDecoder
|
CodecImplementing further up the stack does not require rewriting the lower
layers. The adapter types turn any suitable Codec into owned-value or
streaming APIs. Drop down to the engine and hook layer when the codec needs
continuous-stream semantics or policy decisions.
Modules§
- engine
- Policy-aware transcode engines, hooks, contexts, and policy actions.
Macros§
- register_
value_ codec - Registers a default-constructible bidirectional string codec.
Structs§
- Async
Transcode Decode Input - Decodes an asynchronous unit stream into values.
- Async
Transcode Encode Output - Buffers asynchronous transcoder output while preserving pending units.
- BigEndian
- Type-level marker for big-endian byte order.
- Codec
Transcode Converter - Converts source units to target units through a decoded value by using codecs.
- Codec
Transcode Decoder - Decodes encoded units into caller-provided value buffers by using a
Codec. - Codec
Transcode Encoder - Encodes values into caller-provided output units by using a
Codec. - Codec
Value Decoder - Decodes one encoded unit slice into one owned value by using a
Codec. - Codec
Value Encoder - Encodes one borrowed value into owned units by using a
Codec. - Decode
Lifecycle Output - Values produced by decode reset, the main decode, and decode finish.
- Decode
Lifecycle Progress - Main decoded value and lifecycle output lengths written to caller storage.
- Little
Endian - Type-level marker for little-endian byte order.
- Native
Endian - Type-level marker for native-endian byte order.
- Transcode
Decode Input - Decodes an
Inputunit stream into anInputvalue stream. - Transcode
Encode Output - Encodes an
Outputvalue stream into anOutputunit stream. - Transcode
Progress - Counts how much work a
crate::Transcodercompleted before returning. - Value
Codec Descriptor - An immutable, safely erased bidirectional string codec for one value type.
- Value
Codec Id - A validated, process-independent value-codec identifier.
- Value
Codec Registration - One statically linked value-codec implementation.
- Value
Codec Registration Source - Source location for one linked value-codec registration.
- Value
Codec Registry - An immutable value-codec registry sorted by stable ID.
Enums§
- Async
Transcode Decode Step - Result of one cancellation-safe asynchronous decode operation.
- Byte
Order - Runtime byte order selector.
- Capacity
Error - Error reported by output-capacity planning APIs.
- Decode
Failure - Failure reported by
crate::Codec::decode. - Transcode
Contract Error - Error reported when a transcoder returns inconsistent progress.
- Transcode
Convert Error - Error reported by a unit-to-unit transcode conversion.
- Transcode
Decode Error - Error reported by a decode-oriented transcode operation.
- Transcode
Domain Error - Domain-specific codec, charset, or policy error with transcode context.
- Transcode
Encode Error - Error reported by an encode-oriented transcode operation.
- Transcode
Failure - Framework-level failure reported by a transcode operation.
- Transcode
Status - Reports why a
crate::Transcoderstopped converting input. - Value
Codec Execution Error - Failure produced by a type-erased value-codec invocation.
- Value
Codec IdError - A stable value-codec ID protocol violation.
- Value
Codec Registry Error - Failure while freezing a value-codec registry.
Traits§
- Byte
Order Spec - Describes a type-level byte order.
- Codec
- Encodes and decodes one value or codec quantum against a unit buffer.
- Transcode
Converter - Converts encoded units of one representation into encoded units of another.
- Transcode
Decoder - Decodes encoded units into logical values over caller-provided buffers.
- Transcode
Encoder - Encodes logical values into encoded units over caller-provided buffers.
- Transcoder
- Converts one logical stream of input units into one logical stream of output units.
- Value
Decoder - Decodes a borrowed input value into an owned representation.
- Value
Encoder - Encodes a borrowed input value into an owned representation.
Type Aliases§
- Transcode
Convert Error Of - Convert transcode error for a codec-backed converter.
- Transcode
Decode Error Of - Decode transcode error for a codec-backed decoder.
- Transcode
Encode Error Of - Encode transcode error for a codec-backed encoder.