Skip to main content

bacnet_server/server/
enrollment_summary_budget.rs

1//! Local limits for the deprecated GetEnrollmentSummary interoperability service.
2use super::*;
3
4/// Positive limits on total database objects and complete logical ACK bytes.
5///
6/// Counts all objects before any callbacks, after request decoding. Bytes exclude
7/// APDU/NPDU and are independent of peer APDU size and segmentation. Does not bound
8/// request decoding, individual callbacks/reads, recipient-list processing,
9/// allocation capacity/OOM, RSS, CPU or deadlines. Reads are not rolled back.
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub struct GetEnrollmentSummaryBudget {
12    /// Maximum total database objects, including noncandidates and classes (4096).
13    pub max_objects: usize,
14    /// Maximum encoded service ACK logical bytes (16384).
15    pub max_service_ack_bytes: usize,
16}
17
18impl Default for GetEnrollmentSummaryBudget {
19    fn default() -> Self {
20        Self {
21            max_objects: 4096,
22            max_service_ack_bytes: 16384,
23        }
24    }
25}
26
27impl GetEnrollmentSummaryBudget {
28    /// Reject zero; positive limits are local operator policy, not BACnet limits.
29    pub fn validate(&self) -> Result<(), Error> {
30        for (name, value) in [
31            ("enrollment_summary_max_objects", self.max_objects),
32            (
33                "enrollment_summary_max_service_ack_bytes",
34                self.max_service_ack_bytes,
35            ),
36        ] {
37            if value == 0 {
38                return Err(Error::Encoding(format!("{name} must be positive")));
39            }
40        }
41        Ok(())
42    }
43}
44
45impl<T: TransportPort + 'static> ServerBuilder<T> {
46    /// Set GetEnrollmentSummary limits validated before transport startup.
47    pub fn get_enrollment_summary_budget(mut self, budget: GetEnrollmentSummaryBudget) -> Self {
48        self.config.get_enrollment_summary_budget = budget;
49        self
50    }
51}
52impl BipServerBuilder {
53    /// Set GetEnrollmentSummary limits validated before transport startup.
54    pub fn get_enrollment_summary_budget(mut self, budget: GetEnrollmentSummaryBudget) -> Self {
55        self.config.get_enrollment_summary_budget = budget;
56        self
57    }
58}
59#[cfg(feature = "sc-tls")]
60impl ScServerBuilder {
61    /// Set GetEnrollmentSummary limits validated before SC dialing.
62    pub fn get_enrollment_summary_budget(mut self, budget: GetEnrollmentSummaryBudget) -> Self {
63        self.config.get_enrollment_summary_budget = budget;
64        self
65    }
66}