summaryrefslogtreecommitdiff
path: root/src/protocol.rs
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-09-05 01:52:56 +0800
committerKeuin <[email protected]>2023-09-05 01:56:21 +0800
commit50dbc034090614d004d097c7a45b0a28a3bbb80b (patch)
treeb8ad419bb8c2fed12ac419274755c716166eb90b /src/protocol.rs
parent863473cdcb29d9989c39b4ff96bd54e14b13c6b6 (diff)
feature: 0-rtt connection phase extensionHEADv0.2.0master
Diffstat (limited to 'src/protocol.rs')
-rw-r--r--src/protocol.rs35
1 files changed, 35 insertions, 0 deletions
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<T: AsRef<str>>(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()
+ }
+ }
+}