[Protocol] Replace IpAddr with SocketAddr in protocols (#44)

* [Crate] Replace IpAddr with SocketAddr in protocols

* [Crate] Remove usage of address.to_string in socket

* [Crate] Update CHANGELOG.md
This commit is contained in:
CosminPerRam 2023-06-02 01:06:24 +03:00 committed by GitHub
parent 596d15df78
commit e0830bdae5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 215 additions and 286 deletions

View file

@ -2,9 +2,7 @@ use crate::{
GDError::{PacketOverflow, PacketUnderflow},
GDResult,
};
use std::cmp::Ordering;
use std::net::IpAddr;
pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
match size.cmp(&expected) {
@ -14,22 +12,10 @@ pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
}
}
pub fn address_and_port_as_string(address: &IpAddr, port: u16) -> String { format!("{}:{}", address, port) }
pub fn u8_lower_upper(n: u8) -> (u8, u8) { (n & 15, n >> 4) }
#[cfg(test)]
mod tests {
use std::net::{IpAddr, Ipv4Addr};
#[test]
fn address_and_port_as_string() {
assert_eq!(
super::address_and_port_as_string(&IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), 27015),
"192.168.0.1:27015"
);
}
#[test]
fn u8_lower_upper() {
assert_eq!(super::u8_lower_upper(171), (11, 10));