haprox_rs/protocol_v2/autogen/
mod.rs1use autogen_alpn::{AlpnType, ALPNS_LIST};
16
17
18
19pub mod autogen_alpn;
20
21#[derive(Clone, Debug, PartialEq, Eq)]
23pub struct AlpnProtocolId
24{
25 pub ident: AlpnType,
26 pub ident_seq: &'static [u8],
27 pub ident_str: &'static str,
28 pub descr: &'static str,
29}
30
31impl AlpnProtocolId
32{
33 pub
35 fn get_by_alpn_type(altp: AlpnType) -> &'static AlpnProtocolId
36 {
37 return &ALPNS_LIST[altp as usize];
38 }
39
40 pub
43 fn get_by_ident_str(ident: &str) -> Option<&'static AlpnProtocolId>
44 {
45 let idx = ALPNS_LIST.binary_search_by_key(&ident,|v| v.ident_str).ok()?;
46
47 return Some(&ALPNS_LIST[idx]);
48 }
49
50 pub
53 fn get_by_ident_seq(ident: &[u8]) -> Option<&'static AlpnProtocolId>
54 {
55 let idx = ALPNS_LIST.binary_search_by_key(&ident,|v| v.ident_seq).ok()?;
56
57 return Some(&ALPNS_LIST[idx]);
58 }
59}
60
61#[cfg(test)]
62mod tests
63{
64 use crate::protocol_v2::autogen::autogen_alpn::AlpnType;
65
66 use super::AlpnProtocolId;
67
68 #[test]
69 fn test_get_by_ident_str()
70 {
71 let a1 = AlpnProtocolId::get_by_ident_str("h2c");
72 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http2OverTcp)), a1);
73
74 let a1 = AlpnProtocolId::get_by_ident_str("http/1.0");
75 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http10)), a1);
76
77 let a1 = AlpnProtocolId::get_by_ident_str("https/1.0");
78 assert_eq!(None, a1);
79
80 let a1 = AlpnProtocolId::get_by_ident_seq(b"\x68\x32\x63");
81 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http2OverTcp)), a1);
82
83 let a1 = AlpnProtocolId::get_by_ident_seq(b"\x68\x74\x74\x70\x2f\x31\x2e\x30");
84 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http10)), a1);
85 }
86}