mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
aquatic_http: clean up / move around code; update TODO
This commit is contained in:
parent
c8de9857f8
commit
6fc4b693cd
4 changed files with 29 additions and 33 deletions
|
|
@ -1,6 +1,8 @@
|
|||
use std::net::IpAddr;
|
||||
|
||||
use serde::{Serializer, Deserializer, de::{Visitor, SeqAccess}};
|
||||
|
||||
use super::InfoHash;
|
||||
use super::{InfoHash, ResponsePeer};
|
||||
|
||||
|
||||
struct TwentyCharStringVisitor;
|
||||
|
|
@ -90,4 +92,28 @@ pub fn deserialize_info_hashes<'de, D>(
|
|||
where D: Deserializer<'de>,
|
||||
{
|
||||
Ok(deserializer.deserialize_any(InfoHashVecVisitor).unwrap_or_default())
|
||||
}
|
||||
|
||||
|
||||
pub fn serialize_response_peers_compact<S>(
|
||||
response_peers: &Vec<ResponsePeer>,
|
||||
serializer: S
|
||||
) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
let mut bytes = Vec::with_capacity(response_peers.len() * 6);
|
||||
|
||||
for peer in response_peers {
|
||||
match peer.ip_address {
|
||||
IpAddr::V4(ip) => {
|
||||
bytes.extend_from_slice(&u32::from(ip).to_be_bytes());
|
||||
bytes.extend_from_slice(&peer.port.to_be_bytes())
|
||||
},
|
||||
IpAddr::V6(_) => {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let text: String = bytes.into_iter().map(|byte| byte as char).collect();
|
||||
|
||||
serializer.serialize_str(&text)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue