pub struct MessageCompressor { /* private fields */ }Expand description
消息压缩器,跟踪压缩统计
Implementations§
Source§impl MessageCompressor
impl MessageCompressor
Sourcepub fn new(config: CompressionConfig) -> Self
pub fn new(config: CompressionConfig) -> Self
创建压缩器
Sourcepub fn config(&self) -> &CompressionConfig
pub fn config(&self) -> &CompressionConfig
获取配置
Sourcepub async fn compress(&self, data: &[u8]) -> Vec<u8> ⓘ
pub async fn compress(&self, data: &[u8]) -> Vec<u8> ⓘ
压缩消息。对于小消息(<32 字节)不压缩直接返回原文。
格式:1 字节标记 + 数据
- 标记 0x00:原始数据(未压缩,后跟原文)
- 标记 0x01:DEFLATE 压缩数据(后跟 RFC 7692 zlib 流)
Sourcepub async fn decompress(&self, data: &[u8]) -> Result<Vec<u8>, String>
pub async fn decompress(&self, data: &[u8]) -> Result<Vec<u8>, String>
解压消息
根据首字节标记决定解压路径:
- 0x00:原始数据,跳过标记后直接返回
- 0x01:DEFLATE 压缩数据,调用 zlib 解压
Sourcepub async fn stats(&self) -> CompressionStats
pub async fn stats(&self) -> CompressionStats
获取当前压缩统计快照
Sourcepub async fn reset_stats(&self)
pub async fn reset_stats(&self)
重置统计
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MessageCompressor
impl !UnwindSafe for MessageCompressor
impl Freeze for MessageCompressor
impl Send for MessageCompressor
impl Sync for MessageCompressor
impl Unpin for MessageCompressor
impl UnsafeUnpin for MessageCompressor
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
Mutably borrows from an owned value. Read more