pub struct CodecRuntime {
pub id: CodecId,
pub symbol: Symbol,
pub decoder: Option<Arc<dyn Decoder>>,
pub located_decoder: Option<Arc<dyn LocatedDecoder>>,
pub tree_decoder: Option<Arc<dyn TreeDecoder>>,
pub encoder: Option<Arc<dyn Encoder>>,
pub located_encoder: Option<Arc<dyn LocatedEncoder>>,
pub tree_encoder: Option<Arc<dyn TreeEncoder>>,
pub expr_shape: ShapeRef,
pub options_shape: ShapeRef,
pub default_decode: CodecDefaultDecode,
}Expand description
A registered codec as a runtime object: a symbol-named bundle of optional decode/encode capabilities plus the Shapes and default-decode policy it exposes.
This is the value the kernel hands back from a codec lookup. Each capability
is optional; the dispatch methods (decode,
encode_located, …) pick the richest
implementation present and fall back to the plain forms otherwise, failing
closed with a codec error when none is provided.
Fields§
§id: CodecIdStable id of this codec.
symbol: SymbolThe symbol the codec is registered and looked up under.
decoder: Option<Arc<dyn Decoder>>Plain Expr decoder, if the codec can read.
located_decoder: Option<Arc<dyn LocatedDecoder>>Origin-preserving decoder, if available.
tree_decoder: Option<Arc<dyn TreeDecoder>>Full-tree (lossless) decoder, if available.
encoder: Option<Arc<dyn Encoder>>Plain Expr encoder, if the codec can write.
located_encoder: Option<Arc<dyn LocatedEncoder>>Origin-aware encoder, if available.
tree_encoder: Option<Arc<dyn TreeEncoder>>Full-tree (lossless) encoder, if available.
expr_shape: ShapeRefShape describing the expressions this codec accepts/produces.
options_shape: ShapeRefShape describing this codec’s options table.
default_decode: CodecDefaultDecodeHow this codec maps a DecodePosition to a DecodeTarget.
Implementations§
Source§impl CodecRuntime
impl CodecRuntime
Sourcepub fn decode(&self, cx: &mut ReadCx<'_>, input: Input) -> Result<Expr>
pub fn decode(&self, cx: &mut ReadCx<'_>, input: Input) -> Result<Expr>
Decode input with this codec’s plain decoder, erroring if it has none.
Sourcepub fn encode(&self, cx: &mut WriteCx<'_>, expr: &Expr) -> Result<Output>
pub fn encode(&self, cx: &mut WriteCx<'_>, expr: &Expr) -> Result<Output>
Encode expr with this codec’s plain encoder, erroring if it has none.
Sourcepub fn decode_located(
&self,
cx: &mut ReadCx<'_>,
input: Input,
source_id: String,
) -> Result<LocatedExpr>
pub fn decode_located( &self, cx: &mut ReadCx<'_>, input: Input, source_id: String, ) -> Result<LocatedExpr>
Decode input preserving origin, falling back to decode
with no origin when the codec has no LocatedDecoder.
Sourcepub fn decode_tree(
&self,
cx: &mut ReadCx<'_>,
input: Input,
source_id: String,
) -> Result<LocatedExprTree>
pub fn decode_tree( &self, cx: &mut ReadCx<'_>, input: Input, source_id: String, ) -> Result<LocatedExprTree>
Decode input into a full tree, falling back to
decode_located reconstructed recursively when
the codec has no TreeDecoder.
Sourcepub fn encode_located(
&self,
cx: &mut WriteCx<'_>,
expr: &LocatedExpr,
) -> Result<Output>
pub fn encode_located( &self, cx: &mut WriteCx<'_>, expr: &LocatedExpr, ) -> Result<Output>
Encode a LocatedExpr, using the origin-aware encoder only when
lossless-origin output is requested; otherwise drop the origin and use
encode.
Sourcepub fn encode_tree(
&self,
cx: &mut WriteCx<'_>,
expr: &LocatedExprTree,
) -> Result<Output>
pub fn encode_tree( &self, cx: &mut WriteCx<'_>, expr: &LocatedExprTree, ) -> Result<Output>
Encode a LocatedExprTree, preferring the tree encoder then the
located encoder for lossless-origin output, and otherwise dropping to
encode on the bare expression.
Trait Implementations§
Source§impl Object for CodecRuntime
impl Object for CodecRuntime
Source§fn display(&self, _cx: &mut Cx) -> Result<String>
fn display(&self, _cx: &mut Cx) -> Result<String>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.