refactor: Actually, why not just store entry as-is within SequencedEntry
@@ -1228,13 +1228,9 @@ pub enum SequencedEntryError {
},
}
-#[self_referencing]
#[derive(Debug)]
pub struct SequencedEntry {
- data: Vec<u8>,
- #[borrows(data)]
- #[covariant]
- entry: entry_fb::Entry<'this>,
+ entry: Entry,
sequence: Sequence,
}
@@ -1250,34 +1246,21 @@ impl SequencedEntry {
server_id: ServerId,
entry: Entry,
) -> Result<Self, SequencedEntryError> {
- let heads = entry.into_heads();
- let data = heads.data;
-
- SequencedEntryTryBuilder {
- data,
- entry_builder: |data| {
- flatbuffers::root::<entry_fb::Entry<'_>>(data).context(InvalidFlatbuffer)
- },
+ Ok(Self {
+ entry,
sequence: Sequence {
id: server_id.get_u32(),
number: process_clock.get_u64(),
},
- }
- .try_build()
+ })
}
pub fn new_from_write_metadata(
(sequencer_id, sequence_number): WriteMetadata,
entry: Entry,
) -> Result<Self, SequencedEntryError> {
- let heads = entry.into_heads();
- let data = heads.data;
-
- SequencedEntryTryBuilder {
- data,
- entry_builder: |data| {
- flatbuffers::root::<entry_fb::Entry<'_>>(data).context(InvalidFlatbuffer)
- },
+ Ok(Self {
+ entry,
sequence: Sequence {
id: sequencer_id
.try_into()
@@ -1286,22 +1269,15 @@ impl SequencedEntry {
.try_into()
.context(SequenceNumberOutOfBounds { sequence_number })?,
},
- }
- .try_build()
+ })
}
pub fn partition_writes(&self) -> Option<Vec<PartitionWrite<'_>>> {
- match self.borrow_entry().operation_as_write().as_ref() {
- Some(w) => w
- .partition_writes()
- .as_ref()
- .map(|w| w.iter().map(|fb| PartitionWrite { fb }).collect::<Vec<_>>()),
- None => None,
- }
+ self.entry.partition_writes()
}
pub fn sequence(&self) -> &Sequence {
- self.borrow_sequence()
+ &self.sequence
}
}
