summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge_mapper/src/core/size_threshold.rs
blob: da1ee10859ba941831c6e28549c83866c075cddc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use mqtt_channel::Message;

use super::error::ConversionError;

#[derive(Debug)]
pub struct SizeThreshold(pub usize);

impl SizeThreshold {
    pub fn validate(&self, input: &Message) -> Result<(), ConversionError> {
        let actual_size = input.payload_bytes().len();
        let threshold = self.0;
        if actual_size > threshold {
            Err(ConversionError::SizeThresholdExceeded {
                topic: input.topic.name.clone(),
                actual_size,
                threshold,
            })
        } else {
            Ok(())
        }
    }
}