aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake/protocol.rs
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2020-09-26 12:01:27 +0200
committerMax Audron <audron@cocaine.farm>2020-09-26 12:03:01 +0200
commit3bdae21716d10032f70a0a889070766bbbe4d141 (patch)
tree78a1ddf98601fbbc03a9375626dfa7923ab85521 /src/message/handshake/protocol.rs
parentadd parsing of signalproxy messages (diff)
split handshake.rs
Diffstat (limited to 'src/message/handshake/protocol.rs')
-rw-r--r--src/message/handshake/protocol.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/message/handshake/protocol.rs b/src/message/handshake/protocol.rs
new file mode 100644
index 0000000..d020f33
--- /dev/null
+++ b/src/message/handshake/protocol.rs
@@ -0,0 +1,36 @@
+use crate::Deserialize;
+use crate::Serialize;
+
+pub enum Protocol {
+ Legacy = 0x00000001,
+ Datastream = 0x00000002,
+}
+
+impl Protocol {
+ pub fn new() -> Self {
+ Protocol::Datastream
+ }
+
+ pub fn serialize(self) -> Vec<u8> {
+ let proto: u32 = 0x80000002;
+
+ proto.serialize().unwrap()
+ }
+
+ pub fn parse(buf: &[u8]) -> Self {
+ let mut protolist: Vec<u32> = Vec::new();
+ let mut pos = 0;
+ loop {
+ let (_, proto) = u32::parse(&buf[pos..(pos + 4)]).unwrap();
+ if (proto & 0x80000000) >= 1 {
+ protolist.push(proto - 0x80000000);
+ break;
+ } else {
+ protolist.push(proto);
+ pos += 4;
+ }
+ }
+
+ Protocol::Datastream
+ }
+}