Skip to main content

MessageCompressor

Struct MessageCompressor 

Source
pub struct MessageCompressor { /* private fields */ }
Expand description

消息压缩器,跟踪压缩统计

Implementations§

Source§

impl MessageCompressor

Source

pub fn new(config: CompressionConfig) -> Self

创建压缩器

Source

pub fn config(&self) -> &CompressionConfig

获取配置

Source

pub async fn compress(&self, data: &[u8]) -> Vec<u8>

压缩消息。对于小消息(<32 字节)不压缩直接返回原文。

格式:1 字节标记 + 数据

  • 标记 0x00:原始数据(未压缩,后跟原文)
  • 标记 0x01:DEFLATE 压缩数据(后跟 RFC 7692 zlib 流)
Source

pub async fn decompress(&self, data: &[u8]) -> Result<Vec<u8>, String>

解压消息

根据首字节标记决定解压路径:

  • 0x00:原始数据,跳过标记后直接返回
  • 0x01:DEFLATE 压缩数据,调用 zlib 解压
Source

pub async fn stats(&self) -> CompressionStats

获取当前压缩统计快照

Source

pub async fn reset_stats(&self)

重置统计

Trait Implementations§

Source§

impl Debug for MessageCompressor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.