summaryrefslogtreecommitdiff
path: root/src/protocol.rs
diff options
context:
space:
mode:
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()
+ }
+ }
+}