rapace_core/limits.rs
1//! Resource limits for validation.
2
3/// Limits for descriptor validation.
4#[derive(Debug, Clone)]
5pub struct DescriptorLimits {
6 /// Maximum payload length (default: 1MB).
7 pub max_payload_len: u32,
8 /// Maximum number of channels (default: 1024).
9 pub max_channels: u32,
10 /// Maximum frames in flight per channel (default: 64).
11 pub max_frames_in_flight_per_channel: u32,
12 /// Maximum frames in flight total (default: 4096).
13 pub max_frames_in_flight_total: u32,
14 /// Number of slots (for SHM validation).
15 pub slot_count: u32,
16 /// Size of each slot in bytes (for SHM validation).
17 pub slot_size: u32,
18}
19
20impl Default for DescriptorLimits {
21 fn default() -> Self {
22 Self {
23 max_payload_len: 1024 * 1024, // 1MB
24 max_channels: 1024,
25 max_frames_in_flight_per_channel: 64,
26 max_frames_in_flight_total: 4096,
27 slot_count: 0, // No slots by default (non-SHM)
28 slot_size: 0,
29 }
30 }
31}
32
33impl DescriptorLimits {
34 /// Create limits for non-SHM transports (no slot validation).
35 pub fn without_slots() -> Self {
36 Self::default()
37 }
38
39 /// Create limits for SHM transport with the given slot configuration.
40 pub fn with_slots(slot_count: u32, slot_size: u32) -> Self {
41 Self {
42 slot_count,
43 slot_size,
44 ..Default::default()
45 }
46 }
47}