1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! 压缩器 Trait 定义
//!
//! 定义标准压缩接口,方便用户实现自定义压缩算法
use crateResult;
use CompressionAlgorithm;
/// 压缩器标准接口
///
/// 实现此 trait 以支持自定义压缩算法
///
/// # 示例
///
/// ```rust
/// use flare_core::common::compression::{Compressor, CompressionAlgorithm};
/// use flare_core::common::error::Result;
///
/// struct MyCustomCompressor;
///
/// impl Compressor for MyCustomCompressor {
/// fn compress(&self, data: &[u8]) -> Result<Vec<u8>> {
/// // 实现压缩逻辑
/// Ok(data.to_vec())
/// }
///
/// fn decompress(&self, data: &[u8]) -> Result<Vec<u8>> {
/// // 实现解压逻辑
/// Ok(data.to_vec())
/// }
///
/// fn algorithm(&self) -> CompressionAlgorithm {
/// CompressionAlgorithm::None
/// }
///
/// fn name(&self) -> &'static str {
/// "my_custom"
/// }
///
/// fn can_detect(&self, data: &[u8]) -> bool {
/// // 实现魔数检测逻辑
/// false
/// }
/// }
/// ```