mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
udp protocol: rename "write" and "from_bytes" methods
This commit is contained in:
parent
f30ab82371
commit
1c59972834
9 changed files with 27 additions and 27 deletions
|
|
@ -19,7 +19,7 @@ pub enum Request {
|
|||
}
|
||||
|
||||
impl Request {
|
||||
pub fn write(self, bytes: &mut impl Write) -> Result<(), io::Error> {
|
||||
pub fn write_bytes(self, bytes: &mut impl Write) -> Result<(), io::Error> {
|
||||
match self {
|
||||
Request::Connect(r) => {
|
||||
bytes.write_i64::<NetworkEndian>(PROTOCOL_IDENTIFIER)?;
|
||||
|
|
@ -42,7 +42,7 @@ impl Request {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn from_bytes(bytes: &[u8], max_scrape_torrents: u8) -> Result<Self, RequestParseError> {
|
||||
pub fn parse_bytes(bytes: &[u8], max_scrape_torrents: u8) -> Result<Self, RequestParseError> {
|
||||
let action = bytes
|
||||
.get(8..12)
|
||||
.map(|bytes| I32::from_bytes(bytes.try_into().unwrap()))
|
||||
|
|
@ -323,8 +323,8 @@ mod tests {
|
|||
fn same_after_conversion(request: Request) -> bool {
|
||||
let mut buf = Vec::new();
|
||||
|
||||
request.clone().write(&mut buf).unwrap();
|
||||
let r2 = Request::from_bytes(&buf[..], ::std::u8::MAX).unwrap();
|
||||
request.clone().write_bytes(&mut buf).unwrap();
|
||||
let r2 = Request::parse_bytes(&buf[..], ::std::u8::MAX).unwrap();
|
||||
|
||||
let success = request == r2;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue