aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake/protocol.rs
blob: c12da05cfcfe62b72859f0de37327ec4a23fe6e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{deserialize::Deserialize, serialize::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
    }
}
el.git/commit/src/primitive/message.rs?h=master&id=3d049f8843f8ff2ecfca7bdee6f88ec92d6ae627&follow=1'>Use MsgId in MessageTobias Deiminger-18/+6 2025-02-25Use MsgId in VariantTobias Deiminger-20/+37 2025-02-25Add MsgId as Rust typeTobias Deiminger-0/+56 Up to now it was handled implicitely in Variant::UserType. Making it an explicit type allows to centralize the i32/i64 cfg dependency and to use the type for arguments in signalproxy::objects functions. 2025-02-24added session manager comments and log messageMax Audron-1/+3 2025-02-23add identity syncable to SessionManagerMax Audron-1/+8 2025-02-23add syncables for IrcUserMax Audron-2/+53 2025-02-23move network config to it's own file and impl it's syncMax Audron-23/+84 2025-02-23add basic network syncablesMax Audron-39/+420 2025-02-23clean up unused_import and unused_variables a bitMax Audron-2/+8 2025-02-23fix server feature errorsMax Audron-28/+23 2025-02-23fix ircchannel and maplist network representationMax Audron-154/+137 2025-02-22replace deprecated failure crate with thiserrorMax Audron-278/+194 this changes the public API in that all our methods now return a proper ProtocolError crate. Needed change anyways to properly deal with all our errors in the long run. Will still need to do a pass through the crate to remove all existing unwraps where it makes sense. 2025-02-22update dependencies and fix errorsMax Audron-508/+332 2025-02-22update flakeMax Audron-94/+117 2024-05-22add todos to readmeMax Audron-16/+35