blob: 72dd6ac8e753cebd1b18a45e3f1008774f9906bf (
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::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
use crate::{HandshakeDeserialize, HandshakeSerialize};
use failure::Error;
/// 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>, Error> {
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), Error> {
let (len, values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?;
let msgtype = match_variant!(&values["MsgType"], Variant::ByteArray);
if msgtype == "ClientLogin" {
return Ok((len, Self {}));
} else {
bail!(ProtocolError::WrongMsgType);
}
}
}
|