pub struct Commit {
pub min_tx_offset: u64,
pub n: u16,
pub records: Vec<u8>,
}Expand description
Entry type of a crate::Commitlog.
Fields§
§min_tx_offset: u64The offset of the first record in this commit.
The offset starts from zero and is counted from the beginning of the entire log.
n: u16The number of records in the commit.
records: Vec<u8>A buffer of all records in the commit in serialized form.
Readers must bring their own crate::Decoder to interpret this buffer.
n indicates how many records the buffer contains.
Implementations§
Source§impl Commit
impl Commit
pub const FRAMING_LEN: usize = 18usize
pub const CHECKSUM_ALGORITHM: u8 = 0u8
Sourcepub fn tx_range(&self) -> Range<u64>
pub fn tx_range(&self) -> Range<u64>
The range of transaction offsets contained in this commit.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Length in bytes of this commit when written to the log via Self::write.
Sourcepub fn write<W: Write>(&self, out: W) -> Result<u32>
pub fn write<W: Write>(&self, out: W) -> Result<u32>
Serialize and write self to out.
Returns the crc32 checksum of the commit on success.
Sourcepub fn decode<R: Read>(reader: R) -> Result<Option<Self>>
pub fn decode<R: Read>(reader: R) -> Result<Option<Self>>
Attempt to read one Commit from the given Reader.
Returns None if the reader is already at EOF.
Verifies the checksum of the commit. If it doesn’t match, an error of
kind io::ErrorKind::InvalidData with an inner error downcastable to
ChecksumMismatch is returned.
To retain access to the checksum, use StoredCommit::decode.
Sourcepub fn into_transactions<D: Decoder>(
self,
version: u8,
from_offset: u64,
de: &D,
) -> impl Iterator<Item = Result<Transaction<D::Record>, D::Error>> + '_
pub fn into_transactions<D: Decoder>( self, version: u8, from_offset: u64, de: &D, ) -> impl Iterator<Item = Result<Transaction<D::Record>, D::Error>> + '_
Convert self into an iterator yielding Transactions.
The supplied Decoder is responsible for extracting individual
transactions from the records buffer.
version is the log format version of the current segment, and gets
passed to Decoder::decode_record.
from_offset is the transaction offset within the current commit from
which to start decoding. That is:
-
if the tx offset within the commit is smaller than
from_offset,Decoder::skip_recordis called.The iterator does not yield a value, unless
skip_recordreturns an error. -
if the tx offset within the commit is greater of equal to
from_offset,Decoder::decode_recordis called.The iterator yields the result of this call.
-
if
from_offsetdoesn’t fall into the current commit, the iterator yields nothing.
Trait Implementations§
Source§impl From<StoredCommit> for Commit
impl From<StoredCommit> for Commit
Source§fn from(_: StoredCommit) -> Self
fn from(_: StoredCommit) -> Self
impl StructuralPartialEq for Commit
Auto Trait Implementations§
impl Freeze for Commit
impl RefUnwindSafe for Commit
impl Send for Commit
impl Sync for Commit
impl Unpin for Commit
impl UnwindSafe for Commit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more