From 50dbc034090614d004d097c7a45b0a28a3bbb80b Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 5 Sep 2023 01:52:56 +0800 Subject: feature: 0-rtt connection phase extension --- src/protocol.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/protocol.rs (limited to 'src/protocol.rs') diff --git a/src/protocol.rs b/src/protocol.rs new file mode 100644 index 0000000..7bfec51 --- /dev/null +++ b/src/protocol.rs @@ -0,0 +1,35 @@ +pub const PREFIX: &str = "__nonstd_ext_no_ack_"; + +fn to_no_ack_service_name>(original_name: T) -> String { + PREFIX.to_owned() + original_name.as_ref() +} + +fn parse_service_name(service_name: &str) -> (&str, bool) { + if service_name.starts_with(PREFIX) { + (&service_name[PREFIX.len()..], true) + } else { + (service_name, false) + } +} + +pub struct ServiceName<'a> { + pub service_name: &'a str, + pub no_ack: bool, +} + +impl<'a> ServiceName<'a> { + pub fn from(s: &'a str) -> Self { + let (service_name, no_ack) = parse_service_name(s); + ServiceName { + service_name, + no_ack, + } + } + pub fn to_string(&self) -> String { + if self.no_ack { + to_no_ack_service_name(self.service_name).to_owned() + } else { + self.service_name.to_string() + } + } +} -- cgit v1.2.3