1 | use crate::enums::AlertDescription; |
2 | use crate::error::InvalidMessage; |
3 | use crate::msgs::codec::{Codec, Reader}; |
4 | use crate::msgs::enums::AlertLevel; |
5 | |
6 | use alloc::vec::Vec; |
7 | |
8 | #[derive (Debug)] |
9 | pub struct AlertMessagePayload { |
10 | pub level: AlertLevel, |
11 | pub description: AlertDescription, |
12 | } |
13 | |
14 | impl Codec for AlertMessagePayload { |
15 | fn encode(&self, bytes: &mut Vec<u8>) { |
16 | self.level.encode(bytes); |
17 | self.description.encode(bytes); |
18 | } |
19 | |
20 | fn read(r: &mut Reader) -> Result<Self, InvalidMessage> { |
21 | let level: AlertLevel = AlertLevel::read(r)?; |
22 | let description: AlertDescription = AlertDescription::read(r)?; |
23 | r.expect_empty("AlertMessagePayload" ) |
24 | .map(|_| Self { level, description }) |
25 | } |
26 | } |
27 | |