Refactors TieredStorageFile read/write methods (#34147)
This commit is contained in:
parent
9bb82a3901
commit
e23bfb5167
|
@ -36,18 +36,14 @@ impl TieredStorageFile {
|
||||||
|
|
||||||
pub fn write_type<T>(&self, value: &T) -> IoResult<usize> {
|
pub fn write_type<T>(&self, value: &T) -> IoResult<usize> {
|
||||||
let ptr = value as *const _ as *const u8;
|
let ptr = value as *const _ as *const u8;
|
||||||
let slice = unsafe { std::slice::from_raw_parts(ptr, mem::size_of::<T>()) };
|
let bytes = unsafe { std::slice::from_raw_parts(ptr, mem::size_of::<T>()) };
|
||||||
(&self.0).write_all(slice)?;
|
self.write_bytes(bytes)
|
||||||
|
|
||||||
Ok(std::mem::size_of::<T>())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_type<T>(&self, value: &mut T) -> IoResult<()> {
|
pub fn read_type<T>(&self, value: &mut T) -> IoResult<()> {
|
||||||
let ptr = value as *mut _ as *mut u8;
|
let ptr = value as *mut _ as *mut u8;
|
||||||
let slice = unsafe { std::slice::from_raw_parts_mut(ptr, mem::size_of::<T>()) };
|
let bytes = unsafe { std::slice::from_raw_parts_mut(ptr, mem::size_of::<T>()) };
|
||||||
(&self.0).read_exact(slice)?;
|
self.read_bytes(bytes)
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn seek(&self, offset: u64) -> IoResult<u64> {
|
pub fn seek(&self, offset: u64) -> IoResult<u64> {
|
||||||
|
@ -65,8 +61,6 @@ impl TieredStorageFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_bytes(&self, buffer: &mut [u8]) -> IoResult<()> {
|
pub fn read_bytes(&self, buffer: &mut [u8]) -> IoResult<()> {
|
||||||
(&self.0).read_exact(buffer)?;
|
(&self.0).read_exact(buffer)
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue