pub struct CodecEngine {
pub ml_routing: bool,
pub brotli_threshold: usize,
pub prefer_m2m_for_api: bool,
/* private fields */
}Expand description
Codec engine with automatic algorithm selection
Fields§
§ml_routing: boolML routing enabled (requires inference module)
brotli_threshold: usizeMinimum size for Brotli (bytes)
prefer_m2m_for_api: boolPrefer M2M for LLM API payloads (default: true)
Implementations§
Source§impl CodecEngine
impl CodecEngine
Sourcepub fn with_ml_routing(self, enabled: bool) -> Self
pub fn with_ml_routing(self, enabled: bool) -> Self
Enable ML-based routing (requires loaded model)
Sourcepub fn with_hydra(self, model: HydraModel) -> Self
pub fn with_hydra(self, model: HydraModel) -> Self
Set Hydra model for ML-based algorithm selection
Sourcepub fn with_brotli_threshold(self, threshold: usize) -> Self
pub fn with_brotli_threshold(self, threshold: usize) -> Self
Set Brotli threshold
Sourcepub fn with_encoding(self, encoding: Encoding) -> Self
pub fn with_encoding(self, encoding: Encoding) -> Self
Set token-native encoding
Sourcepub fn compress_with_tokens(
&self,
content: &str,
algorithm: Algorithm,
encoding: Encoding,
) -> Result<CompressionResult>
pub fn compress_with_tokens( &self, content: &str, algorithm: Algorithm, encoding: Encoding, ) -> Result<CompressionResult>
Compress with specified algorithm and track token counts
This method counts tokens before and after compression to provide accurate token savings metrics. Use this when token efficiency matters more than raw speed.
Sourcepub fn secure_compress(
&self,
content: &str,
scanner: &SecurityScanner,
) -> Result<CompressionResult>
pub fn secure_compress( &self, content: &str, scanner: &SecurityScanner, ) -> Result<CompressionResult>
Secure compress: Run cognitive security scan before compression
This method combines security scanning with compression:
- Scans plaintext for threats using Hydra/patterns
- If safe, compresses with optimal algorithm
- If threat detected and blocking enabled, returns error
Epistemic basis:
- K: Threats exist in plaintext, not compressed form
- K: Security scan must happen before compression
- B: Combined scan provides defense in depth
Sourcepub fn secure_compress_ml(
&self,
content: &str,
) -> Result<(CompressionResult, bool)>
pub fn secure_compress_ml( &self, content: &str, ) -> Result<(CompressionResult, bool)>
Secure compress with ML-based algorithm selection
Uses Hydra for both security scanning and algorithm selection.
Sourcepub fn compress_auto_with_tokens(
&self,
content: &str,
encoding: Encoding,
) -> Result<(CompressionResult, Algorithm)>
pub fn compress_auto_with_tokens( &self, content: &str, encoding: Encoding, ) -> Result<(CompressionResult, Algorithm)>
Compress with automatic algorithm selection and token tracking
Sourcepub fn compress(
&self,
content: &str,
algorithm: Algorithm,
) -> Result<CompressionResult>
pub fn compress( &self, content: &str, algorithm: Algorithm, ) -> Result<CompressionResult>
Compress with specified algorithm
Sourcepub fn compress_auto(
&self,
content: &str,
) -> Result<(CompressionResult, Algorithm)>
pub fn compress_auto( &self, content: &str, ) -> Result<(CompressionResult, Algorithm)>
Compress with automatic algorithm selection
Sourcepub fn compress_value(
&self,
value: &Value,
) -> Result<(CompressionResult, Algorithm)>
pub fn compress_value( &self, value: &Value, ) -> Result<(CompressionResult, Algorithm)>
Compress JSON value with automatic selection
Sourcepub fn select_algorithm(&self, analysis: &ContentAnalysis) -> Algorithm
pub fn select_algorithm(&self, analysis: &ContentAnalysis) -> Algorithm
Select optimal algorithm based on content analysis
Sourcepub fn select_algorithm_for_content(&self, content: &str) -> Algorithm
pub fn select_algorithm_for_content(&self, content: &str) -> Algorithm
Select algorithm with full content access (for ML routing)
Sourcepub fn decompress(&self, wire: &str) -> Result<String>
pub fn decompress(&self, wire: &str) -> Result<String>
Decompress content (auto-detects algorithm from wire format)
Sourcepub fn decompress_value(&self, wire: &str) -> Result<Value>
pub fn decompress_value(&self, wire: &str) -> Result<Value>
Decompress to JSON value
Sourcepub fn compress_best(&self, content: &str) -> Result<CompressionResult>
pub fn compress_best(&self, content: &str) -> Result<CompressionResult>
Try all algorithms and return best result
Sourcepub fn analyze(&self, content: &str) -> ContentAnalysis
pub fn analyze(&self, content: &str) -> ContentAnalysis
Get analysis for content
Trait Implementations§
Source§impl Clone for CodecEngine
impl Clone for CodecEngine
Source§fn clone(&self) -> CodecEngine
fn clone(&self) -> CodecEngine
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CodecEngine
impl !RefUnwindSafe for CodecEngine
impl Send for CodecEngine
impl Sync for CodecEngine
impl Unpin for CodecEngine
impl !UnwindSafe for CodecEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more