naia_shared/connection/compression_config.rs
1/// Per-direction zstd compression settings for a connection.
2#[derive(Clone)]
3pub struct CompressionConfig {
4 /// Compression applied to packets flowing from server to client.
5 pub server_to_client: Option<CompressionMode>,
6 /// Compression applied to packets flowing from client to server.
7 pub client_to_server: Option<CompressionMode>,
8}
9
10impl CompressionConfig {
11 /// Creates a `CompressionConfig` with the given per-direction modes.
12 pub fn new(
13 server_to_client: Option<CompressionMode>,
14 client_to_server: Option<CompressionMode>,
15 ) -> Self {
16 Self {
17 server_to_client,
18 client_to_server,
19 }
20 }
21}
22
23/// Selects the zstd compression strategy applied to a direction of traffic.
24#[derive(Clone, Eq, PartialEq)]
25pub enum CompressionMode {
26 /// Compression mode using default zstd dictionary.
27 /// 1st i32 parameter here is the compression level from -7 (fastest) to 22
28 /// (smallest).
29 Default(i32),
30 /// Compression mode using custom dictionary.
31 /// 1st i32 parameter here is the compression level from -7 (fastest) to 22
32 /// (smallest). 2nd `Vec<u8>` parameter here is the dictionary itself.
33 Dictionary(i32, Vec<u8>),
34 /// Dictionary training mode.
35 /// 1st usize parameter here describes the desired number of samples
36 /// (packets) to train on. Obviously, the more samples trained on, the
37 /// better theoretical compression.
38 Training(usize),
39}