-
Notifications
You must be signed in to change notification settings - Fork 21
/
packet_headers.rs
39 lines (31 loc) · 1.14 KB
/
packet_headers.rs
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
36
37
38
//! An example of packets with common headers.
//! This works because types and packets are the same thing.
//! This means that we can simply have a packet with another packet field.
#[derive(protocol::Protocol, Clone, Debug, PartialEq)]
pub struct Handshake;
#[derive(protocol::Protocol, Clone, Debug, PartialEq)]
pub struct Packet {
headers: std::collections::HashMap<String, String>,
kind: PacketKind
}
#[derive(protocol::Protocol, Clone, Debug, PartialEq)]
pub enum PacketKind {
Handshake(Handshake),
}
fn main() {
use std::net::TcpStream;
let stream = TcpStream::connect("127.0.0.1:34254").unwrap();
let mut connection = protocol::wire::stream::Connection::new(stream,
protocol::wire::middleware::pipeline::default(),
protocol::Settings::default());
connection.send_packet(&Packet {
headers: std::collections::HashMap::new(),
kind: PacketKind::Handshake(Handshake),
}).unwrap();
loop {
if let Some(response) = connection.receive_packet().unwrap() {
println!("{:?}", response);
break;
}
}
}