Add file_position to EntryDetailed
This commit is contained in:
parent
ff378b1dd8
commit
0f98903759
2 changed files with 6 additions and 4 deletions
|
|
@ -121,12 +121,13 @@ pub trait CursorWithStoreHeader<T>: PrimitiveCursor<T> {
|
|||
async fn next(&mut self) -> Result<Option<EntryDetailed<T>>>
|
||||
where T: Decode
|
||||
{
|
||||
let file_position = self.current_file_position().await?;
|
||||
let Some(entry_header) = self.next_entry_header().await? else { return Ok(None) };
|
||||
|
||||
let mut data_bytes: Vec<u8> = vec![0; entry_header.size_of_data()];
|
||||
self.read_bytes(&mut data_bytes).await?;
|
||||
let entry: EntryDetailed<T> =
|
||||
EntryDetailed::decode(entry_header, self.header().number_of_columns, &mut data_bytes)?;
|
||||
EntryDetailed::decode(entry_header, file_position, self.header().number_of_columns, &mut data_bytes)?;
|
||||
|
||||
Ok(Some(entry))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use bincode::{Decode, Encode};
|
||||
|
||||
use crate::binary_coding::{encode_sequence, encode_sequence_with_sizes, decode_sequence};
|
||||
use crate::storage_engine::Result;
|
||||
use crate::storage_engine::{Result, FilePosition};
|
||||
use crate::error::{Error, DecodeErrorKind};
|
||||
use crate::entry_header::{EntryHeader, EntryHeaderWithDataSize};
|
||||
|
||||
|
|
@ -14,6 +14,7 @@ pub struct Entry<T> {
|
|||
#[derive(Debug)]
|
||||
pub struct EntryDetailed<T> {
|
||||
pub header: EntryHeaderWithDataSize,
|
||||
pub file_position: FilePosition,
|
||||
pub data: Vec<T>,
|
||||
}
|
||||
|
||||
|
|
@ -40,11 +41,11 @@ impl <T>Entry<T> {
|
|||
}
|
||||
|
||||
impl <T>EntryDetailed<T> {
|
||||
pub fn decode(header: EntryHeaderWithDataSize, number_of_columns: usize, bytes: &[u8]) -> Result<Self>
|
||||
pub fn decode(header: EntryHeaderWithDataSize, file_position: FilePosition, number_of_columns: usize, bytes: &[u8]) -> Result<Self>
|
||||
where T: Decode
|
||||
{
|
||||
let data = decode_sequence::<T>(number_of_columns, bytes)
|
||||
.map_err(|e| Error::DecodeError(DecodeErrorKind::EntryData, e))?;
|
||||
Ok(EntryDetailed { header, data })
|
||||
Ok(EntryDetailed { header, file_position, data })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue