mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
http load test and protocol: cut down on allocations a bit
This commit is contained in:
parent
47c71376e2
commit
45940a05a9
4 changed files with 70 additions and 19 deletions
|
|
@ -22,13 +22,28 @@ pub struct AnnounceRequest {
|
|||
|
||||
impl AnnounceRequest {
|
||||
pub fn as_bytes(&self) -> Vec<u8> {
|
||||
let mut bytes = Vec::new();
|
||||
let mut bytes = Vec::with_capacity(
|
||||
24 +
|
||||
60 +
|
||||
9 +
|
||||
60 +
|
||||
6 +
|
||||
5 + // high estimate
|
||||
6 +
|
||||
2 + // estimate
|
||||
14 + // FIXME event
|
||||
9 +
|
||||
1 +
|
||||
20 + // numwant bad estimate
|
||||
20 + // key bad estimate
|
||||
13
|
||||
);
|
||||
|
||||
bytes.extend_from_slice(b"GET /announce?info_hash=");
|
||||
bytes.extend_from_slice(&urlencode_20_bytes(self.info_hash.0));
|
||||
urlencode_20_bytes(self.info_hash.0, &mut bytes);
|
||||
|
||||
bytes.extend_from_slice(b"&peer_id=");
|
||||
bytes.extend_from_slice(&urlencode_20_bytes(self.peer_id.0));
|
||||
urlencode_20_bytes(self.info_hash.0, &mut bytes);
|
||||
|
||||
bytes.extend_from_slice(b"&port=");
|
||||
let _ = itoa::write(&mut bytes, self.port);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue