加上注释,防止忘记

This commit is contained in:
shenjack 2024-03-08 01:03:00 +08:00
parent e87601144b
commit 18fe86224e
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -21,6 +21,7 @@ macro_rules! read {
#[doc = concat!("读取 ", stringify!($ty), " 类型 ", $size, " 长度的数据")]
pub fn $name(&mut self) -> $ty {
unsafe {
// 使用 std::ptr::read_unaligned 解决未对齐地址问题
let value = std::ptr::read_unaligned(self.data[self.cursor..].as_ptr() as *const $ty);
self.cursor += std::mem::size_of::<$ty>();
value.to_be()
@ -31,6 +32,7 @@ macro_rules! read {
#[doc = concat!("读取 ", stringify!($ty), " 类型 ", $size, " 长度的数据")]
pub fn $name(&mut self) -> $ty {
unsafe {
// 使用 std::ptr::read_unaligned 解决未对齐地址问题
let value = std::ptr::read_unaligned(self.data[self.cursor..].as_ptr() as *const $ty);
self.cursor += std::mem::size_of::<$ty>();
value