use std::hash::Hasher;
pub trait Hash32 {
fn hash32(&self) -> u32;
}
impl<T: std::hash::Hash> Hash32 for T {
fn hash32(&self) -> u32 {
let mut hasher = std::hash::DefaultHasher::new();
self.hash(&mut hasher);
let hash: u64 = hasher.finish();
#[allow(clippy::cast_possible_truncation)]
let hash: u32 = (hash ^ (hash >> 32)) as u32;
hash
}
}
pub(crate) trait AsFfi {
type Target<'a>
where
Self: 'a;
fn as_ffi(&self) -> Self::Target<'_>;
}
pub trait CdrHeader {
fn cdr_header() -> [u8; 4];
}
impl CdrHeader for byteorder::LittleEndian {
fn cdr_header() -> [u8; 4] {
[0x00, 0x01, 0x00, 0x00]
}
}
impl CdrHeader for byteorder::BigEndian {
fn cdr_header() -> [u8; 4] {
[0x00, 0x00, 0x00, 0x00]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cdr_header_configurations() {
let expected = [0x00, 0x01, 0x00, 0x00];
let actual = byteorder::LittleEndian::cdr_header();
assert_eq!(expected, actual);
let expected = [0x00, 0x00, 0x00, 0x00];
let actual = byteorder::BigEndian::cdr_header();
assert_eq!(expected, actual);
}
}