rl2tp/message/avp/types/
assigned_tunnel_id.rs1use crate::avp::{QueryableAVP, WritableAVP};
2use crate::common::{DecodeError, DecodeResult, Reader, Writer};
3
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct AssignedTunnelId {
6 pub value: u16,
7}
8
9impl AssignedTunnelId {
10 const ATTRIBUTE_TYPE: u16 = 9;
11 const LENGTH: usize = 2;
12
13 #[inline]
14 pub fn try_read<T>(reader: &mut impl Reader<T>) -> DecodeResult<Self> {
15 if reader.len() < Self::LENGTH {
16 return Err(DecodeError::IncompleteAVP(Self::ATTRIBUTE_TYPE));
17 }
18
19 let value = unsafe { reader.read_u16_be_unchecked() };
20 Ok(Self { value })
21 }
22}
23
24impl From<u16> for AssignedTunnelId {
25 #[inline]
26 fn from(value: u16) -> Self {
27 Self { value }
28 }
29}
30
31impl From<AssignedTunnelId> for u16 {
32 #[inline]
33 fn from(value: AssignedTunnelId) -> Self {
34 value.value
35 }
36}
37
38impl QueryableAVP for AssignedTunnelId {
39 #[inline]
40 fn get_length(&self) -> usize {
41 Self::LENGTH
42 }
43}
44
45impl WritableAVP for AssignedTunnelId {
46 #[inline]
47 fn write(&self, writer: &mut impl Writer) {
48 writer.write_u16_be(Self::ATTRIBUTE_TYPE);
49 writer.write_u16_be(self.value);
50 }
51}