(
&self,
dim_bufman: &BufferManager,
data_bufmans: &BufferManagerFactory<VersionNumber>,
cursor: u64,
)
| 13 | |
| 14 | impl<T> TreeMapSerialize for VersionedVec<T> { |
| 15 | fn serialize( |
| 16 | &self, |
| 17 | dim_bufman: &BufferManager, |
| 18 | data_bufmans: &BufferManagerFactory<VersionNumber>, |
| 19 | cursor: u64, |
| 20 | ) -> Result<u32, BufIoError> { |
| 21 | let (next_offset, next_version) = if let Some(next) = &self.next { |
| 22 | ( |
| 23 | next.serialize(dim_bufman, data_bufmans, cursor)?, |
| 24 | *next.version, |
| 25 | ) |
| 26 | } else { |
| 27 | (u32::MAX, u32::MAX) |
| 28 | }; |
| 29 | let offset_read_guard = self.serialized_at.read().map_err(|_| BufIoError::Locking)?; |
| 30 | if let Some(offset) = *offset_read_guard { |
| 31 | let bufman = data_bufmans.get(self.version)?; |
| 32 | let cursor = bufman.open_cursor()?; |
| 33 | bufman.seek_with_cursor(cursor, offset.0 as u64)?; |
| 34 | bufman.update_u32_with_cursor(cursor, next_offset)?; |
| 35 | bufman.update_u32_with_cursor(cursor, next_version)?; |
| 36 | bufman.close_cursor(cursor)?; |
| 37 | return Ok(offset.0); |
| 38 | } |
| 39 | drop(offset_read_guard); |
| 40 | let mut offset_write_guard = self |
| 41 | .serialized_at |
| 42 | .write() |
| 43 | .map_err(|_| BufIoError::Locking)?; |
| 44 | if let Some(offset) = *offset_write_guard { |
| 45 | let bufman = data_bufmans.get(self.version)?; |
| 46 | let cursor = bufman.open_cursor()?; |
| 47 | bufman.seek_with_cursor(cursor, offset.0 as u64)?; |
| 48 | bufman.update_u32_with_cursor(cursor, next_offset)?; |
| 49 | bufman.update_u32_with_cursor(cursor, next_version)?; |
| 50 | bufman.close_cursor(cursor)?; |
| 51 | return Ok(offset.0); |
| 52 | } |
| 53 | let size = 8 * self.list.len() + 16; |
| 54 | let mut buf = Vec::with_capacity(size); |
| 55 | buf.extend(next_offset.to_le_bytes()); |
| 56 | buf.extend(next_version.to_le_bytes()); |
| 57 | buf.extend(self.version.to_le_bytes()); |
| 58 | buf.extend((self.list.len() as u32).to_le_bytes()); |
| 59 | let bufman = data_bufmans.get(self.version)?; |
| 60 | let cursor = bufman.open_cursor()?; |
| 61 | |
| 62 | for el in &self.list { |
| 63 | buf.extend(el.to_le_bytes()); |
| 64 | } |
| 65 | |
| 66 | let offset = bufman.write_to_end_of_file(cursor, &buf)? as u32; |
| 67 | *offset_write_guard = Some(FileOffset(offset)); |
| 68 | |
| 69 | Ok(offset) |
| 70 | } |
| 71 | |
| 72 | fn deserialize( |
nothing calls this directly
no test coverage detected