blob: c8650f9cd583dbac9aa7aa008a6f79c91d4d4d4c (
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
|
use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
use crate::{HandshakeDeserialize, HandshakeSerialize};
/// ClientLoginAck is received after the client has successfully logged in
/// it has no fields
#[derive(Debug, Clone)]
pub struct ClientLoginAck;
impl HandshakeSerialize for ClientLoginAck {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::with_capacity(1);
values.insert(
"MsgType".to_string(),
Variant::String("ClientLoginAck".to_string()),
);
return HandshakeSerialize::serialize(&values);
}
}
impl HandshakeDeserialize for ClientLoginAck {
fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (len, values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?;
let msgtype = match_variant!(&values["MsgType"], Variant::ByteArray);
if msgtype == "ClientLogin" {
Ok((len, Self {}))
} else {
Err(ProtocolError::WrongMsgType)
}
}
}
|