mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
[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:
parent
596d15df78
commit
e0830bdae5
70 changed files with 215 additions and 286 deletions
14
src/utils.rs
14
src/utils.rs
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue