Adding the concept of NetworkEndian.
NetworkEndian describes the byte order to use for network communication. Generally, this is always BigEndian.
This commit is contained in:
parent
26080427c0
commit
e4d821333c
@ -22,6 +22,13 @@ pub type PlatformEndian = BigEndian;
|
||||
#[cfg(not(target_endian="big"))]
|
||||
pub type PlatformEndian = LittleEndian;
|
||||
|
||||
/// Referes to NetworkEndian. This could be either
|
||||
/// of the available endians as long as it is consistent
|
||||
/// across the network. However, RFC1700 decided network
|
||||
/// byte order would be BigEndian. As such, it is now the
|
||||
/// common endian style for networking.
|
||||
pub type NetworkEndian = BigEndian;
|
||||
|
||||
/// Handles serialization where the most
|
||||
/// significant byte is stored at the lowest address.
|
||||
pub enum BigEndian
|
||||
@ -48,7 +55,14 @@ pub enum Endianess
|
||||
/// Referes to PlatformEndian. This can be anyone
|
||||
/// of the other available endians depending on
|
||||
/// the platform you are on.
|
||||
Platform
|
||||
Platform,
|
||||
|
||||
/// Referes to NetworkEndian. This could be either
|
||||
/// of the available endians as long as it is consistent
|
||||
/// across the network. However, RFC1700 decided network
|
||||
/// byte order would be BigEndian. As such, it is now the
|
||||
/// common endian style for networking.
|
||||
Network
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,5 +27,6 @@ pub use ::byte_sized::{I8_BYTES, I16_BYTES, I32_BYTES, I64_BYTES, ISIZE_BYTES};
|
||||
pub use ::byte_sized::{F32_BYTES, F64_BYTES};
|
||||
pub use ::byte_sized::get_byte_size_of_string;
|
||||
pub use ::converter::Converter;
|
||||
pub use ::endian::{BigEndian, LittleEndian, PlatformEndian, Endianess};
|
||||
pub use ::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian};
|
||||
pub use ::endian::Endianess;
|
||||
pub use ::transmutable::Transmutable;
|
||||
|
@ -4,7 +4,8 @@ use sigils::quaternion::Quaternion;
|
||||
|
||||
use ::byte_sized::{ByteSized, get_byte_size_of_string};
|
||||
use ::converter::Converter;
|
||||
use ::endian::{BigEndian, LittleEndian, PlatformEndian, Endianess};
|
||||
use ::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian};
|
||||
use ::endian::Endianess;
|
||||
|
||||
|
||||
|
||||
@ -49,6 +50,11 @@ macro_rules! handle_endianess_to_bytes
|
||||
{
|
||||
$buffer.append(&mut PlatformEndian::$func(*$val));
|
||||
}
|
||||
|
||||
Endianess::Network =>
|
||||
{
|
||||
$buffer.append(&mut NetworkEndian::$func(*$val));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,6 +83,11 @@ macro_rules! handle_endianess_from_bytes
|
||||
{
|
||||
PlatformEndian::$func(&$buffer)
|
||||
}
|
||||
|
||||
Endianess::Network =>
|
||||
{
|
||||
NetworkEndian::$func(&$buffer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -524,6 +535,11 @@ impl Transmutable for String
|
||||
{
|
||||
buffer.append(&mut PlatformEndian::string_to_bytes(temp));
|
||||
}
|
||||
|
||||
Endianess::Network =>
|
||||
{
|
||||
buffer.append(&mut NetworkEndian::string_to_bytes(temp));
|
||||
}
|
||||
}
|
||||
|
||||
// Return the byte buffer.
|
||||
|
Loading…
x
Reference in New Issue
Block a user