Values, Cleaning, Docs, Tests, Example (Current Example is Wrong)

This commit is contained in:
Alex Emmet 2026-06-22 23:29:18 +02:00
commit c2a7afe6c1
37 changed files with 1693 additions and 520 deletions

View file

@ -1,8 +1,7 @@
pub use registry::Registry;
use crate::{CodecError, DataValue, decode, encode};
use mtp_type_map::Version;
pub use mtp_type_map::Registry;
/*
* A version-aware codec that uses a multi-version registry to resolve
* the correct TypeMap for encoding and decoding operations.
@ -17,22 +16,6 @@ impl VersionedCodec {
Self { registry }
}
pub fn encode(&self, value: &DataValue, version: Version) -> Result<Vec<u8>, CodecError> {
let typemap = self
.registry
.get(&version)
.ok_or(CodecError::UnknownVersion)?;
encode(value, typemap)
}
pub fn decode(&self, bytes: &[u8], version: Version) -> Result<DataValue, CodecError> {
let typemap = self
.registry
.get(&version)
.ok_or(CodecError::UnknownVersion)?;
decode(bytes, typemap)
}
pub fn negotiate(&self, client_versions: &[Version]) -> Option<Version> {
self.registry.negotiate(client_versions)
}