initial commit

This commit is contained in:
2026-02-22 20:58:47 +07:00
parent 89b3037556
commit bf7d50bcef
61 changed files with 3840 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
pub mod u24;
+27
View File
@@ -0,0 +1,27 @@
use bytes::Buf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct U24([u8; 3]);
impl U24 {
pub fn from_u32(value: u32) -> Self {
let b = value.to_be_bytes();
U24([b[1], b[2], b[3]])
}
pub fn to_u32(&self) -> u32 {
u32::from_be_bytes([0, self.0[0], self.0[1], self.0[2]])
}
}
pub trait BufExt: Buf {
fn get_u24(&mut self) -> u32 {
let b1 = self.get_u8() as u32;
let b2 = self.get_u8() as u32;
let b3 = self.get_u8() as u32;
(b1 << 16) | (b2 << 8) | b3
}
}
// Реализуем этот трейт для всего, что поддерживает Buf (включая BytesMut)
impl<T: Buf> BufExt for T {}