加上注释,防止忘记
This commit is contained in:
parent
e87601144b
commit
18fe86224e
@ -21,6 +21,7 @@ macro_rules! read {
|
|||||||
#[doc = concat!("读取 ", stringify!($ty), " 类型 ", $size, " 长度的数据")]
|
#[doc = concat!("读取 ", stringify!($ty), " 类型 ", $size, " 长度的数据")]
|
||||||
pub fn $name(&mut self) -> $ty {
|
pub fn $name(&mut self) -> $ty {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
// 使用 std::ptr::read_unaligned 解决未对齐地址问题
|
||||||
let value = std::ptr::read_unaligned(self.data[self.cursor..].as_ptr() as *const $ty);
|
let value = std::ptr::read_unaligned(self.data[self.cursor..].as_ptr() as *const $ty);
|
||||||
self.cursor += std::mem::size_of::<$ty>();
|
self.cursor += std::mem::size_of::<$ty>();
|
||||||
value.to_be()
|
value.to_be()
|
||||||
@ -31,6 +32,7 @@ macro_rules! read {
|
|||||||
#[doc = concat!("读取 ", stringify!($ty), " 类型 ", $size, " 长度的数据")]
|
#[doc = concat!("读取 ", stringify!($ty), " 类型 ", $size, " 长度的数据")]
|
||||||
pub fn $name(&mut self) -> $ty {
|
pub fn $name(&mut self) -> $ty {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
// 使用 std::ptr::read_unaligned 解决未对齐地址问题
|
||||||
let value = std::ptr::read_unaligned(self.data[self.cursor..].as_ptr() as *const $ty);
|
let value = std::ptr::read_unaligned(self.data[self.cursor..].as_ptr() as *const $ty);
|
||||||
self.cursor += std::mem::size_of::<$ty>();
|
self.cursor += std::mem::size_of::<$ty>();
|
||||||
value
|
value
|
||||||
|
Loading…
Reference in New Issue
Block a user