pub const CLIENT_BIDI: u64 = 0x0;
pub const SERVER_BIDI: u64 = 0x1;
pub const CLIENT_UNI: u64 = 0x2;
pub const SERVER_UNI: u64 = 0x3;
#[inline]
pub fn stream_type(id: u64) -> u64 {
id & 0x3
}
#[inline]
pub fn stream_index(id: u64) -> u64 {
id >> 2
}
#[inline]
pub fn stream_id(stream_type: u64, index: u64) -> u64 {
(index << 2) | stream_type
}
#[inline]
pub fn is_client_initiated(id: u64) -> bool {
matches!(stream_type(id), CLIENT_BIDI | CLIENT_UNI)
}
#[inline]
pub fn is_unidirectional(id: u64) -> bool {
matches!(stream_type(id), CLIENT_UNI | SERVER_UNI)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ids_and_types() {
assert_eq!(stream_type(0), CLIENT_BIDI);
assert_eq!(stream_type(4), CLIENT_BIDI);
assert_eq!(stream_index(4), 1);
assert_eq!(stream_id(CLIENT_BIDI, 2), 8);
assert_eq!(stream_type(5), SERVER_BIDI);
assert_eq!(stream_type(2), CLIENT_UNI);
assert_eq!(stream_type(6), CLIENT_UNI);
assert_eq!(stream_type(3), SERVER_UNI);
assert!(is_client_initiated(6));
assert!(!is_client_initiated(7));
assert!(is_unidirectional(2));
assert!(!is_unidirectional(0));
}
}