pub struct BinlogParser<R: Read = File> { /* private fields */ }Expand description
Maintains the format description and table maps while reading one event at a time.
The reader works on any Read input (a file, standard input, or an
in-memory buffer). Raw event sizes are capped at MAX_EVENT_SIZE by
default, configurable through BinlogParser::with_max_event_size, and
the inner-event collection of the collecting BinlogParser::events
iterator is bounded by DEFAULT_INNER_EVENT_LIMIT, configurable
through BinlogParser::with_inner_event_limit (R46b). Decoded row
images can consume more memory than their wire data.
BinlogParser::visit_events delivers and releases each inner event in
turn while retaining the outer raw payload and shared table-map state.
Implementations§
Source§impl BinlogParser<File>
impl BinlogParser<File>
Source§impl<R: Read> BinlogParser<R>
impl<R: Read> BinlogParser<R>
Sourcepub fn from_reader(reader: R) -> Result<Self, ParserError>
pub fn from_reader(reader: R) -> Result<Self, ParserError>
Read from an arbitrary streaming source after validating the four-byte binlog magic.
Only the magic is consumed here; events are read lazily through
BinlogParser::events, so the input does not need to be seekable.
Sourcepub fn with_max_event_size(self, cap: u32) -> Self
pub fn with_max_event_size(self, cap: u32) -> Self
Overrides the per-event size cap (defaulting to MAX_EVENT_SIZE).
Sourcepub fn with_inner_event_limit(self, limit: NonZeroUsize) -> Self
pub fn with_inner_event_limit(self, limit: NonZeroUsize) -> Self
Overrides the inner-event collection bound of the collecting
BinlogParser::events iterator (defaulting to
DEFAULT_INNER_EVENT_LIMIT, R46b).
Like Self::with_max_event_size, this is infallible builder-style
configuration: a limit of zero cannot be expressed because the
argument is a core::num::NonZeroUsize. Only the collecting path
is bounded; Self::visit_events stays uncapped because its
callback applies backpressure.
Sourcepub fn take_warnings(&mut self) -> Vec<String>
pub fn take_warnings(&mut self) -> Vec<String>
Drains the advisory warnings collected so far.
Warnings are non-fatal observations that do not stop parsing — most
notably a header log_pos that does not land right after its event.
The buffer is bounded, so a corrupt file cannot grow it without limit;
call this periodically (the CLI drains after each input).
Sourcepub fn events(
&mut self,
) -> impl Iterator<Item = Result<ParsedEvent, ParserError>> + '_
pub fn events( &mut self, ) -> impl Iterator<Item = Result<ParsedEvent, ParserError>> + '_
Iterate over events, retrying transient io::ErrorKind::Interrupted
reads. Other I/O errors and framing or decoding errors terminate the stream.
This iterator collects the inner events of each transaction payload
into EventPayload::TransactionPayload.events, so that collection is
bounded by DEFAULT_INNER_EVENT_LIMIT (configurable through
Self::with_inner_event_limit, R46b); breaching the bound stops the
stream with ParserError::TooManyInnerEvents.
Sourcepub fn visit_events(
&mut self,
visitor: impl FnMut(VisitEvent<'_>) -> Result<ControlFlow<()>>,
) -> Result<ControlFlow<()>, ParserError>
pub fn visit_events( &mut self, visitor: impl FnMut(VisitEvent<'_>) -> Result<ControlFlow<()>>, ) -> Result<ControlFlow<()>, ParserError>
Visit the remaining events, consuming compressed transactions one inner event at a time.
Unlike Self::events, this method does not collect the decoded inner
events of a transaction into a vector. The parser retains the outer
compressed event, the current inner event, and its shared table maps.
A single decoded event can still contain multiple row images. The
collecting path’s DEFAULT_INNER_EVENT_LIMIT does not apply here:
the callback consumes each inner event immediately, so memory stays
bounded by backpressure instead of a numeric cap (R46b).
The callback receives VisitEvent::TransactionPayloadStart only
after outer framing, checksum, and payload-header validation and
decompressor creation succeed. VisitEvent::TransactionPayloadEnd
confirms that all inner events and the decompression stream completed.
Previously delivered callbacks cannot be rolled back on a later error.
Return ControlFlow::Break from the callback to stop immediately.
EOF returns ControlFlow::Continue. Both outcomes leave this parser
terminated. Callback errors carry the current outer
file offset through ParserError::Io. A callback error or panic
also terminates the parser, so subsequent calls cannot resume with
partially updated table-map state.
§Example
use binlog_inspect::parser::{BinlogParser, VisitEvent};
use std::ops::ControlFlow;
let mut parser = BinlogParser::open("mysql-bin.000001")?;
let mut inner_events = 0u64;
let outcome = parser.visit_events(|notification| {
if let VisitEvent::Event { parent_offset: Some(_), .. } = notification {
inner_events += 1;
}
Ok(ControlFlow::Continue(()))
})?;
assert_eq!(outcome, ControlFlow::Continue(()));
println!("Decoded {inner_events} inner events");Auto Trait Implementations§
impl<R> Forget for BinlogParser<R>
impl<R> Freeze for BinlogParser<R>
impl<R> Move for BinlogParser<R>
impl<R> RefUnwindSafe for BinlogParser<R>where
BufReader<R>: RefUnwindSafe,
impl<R> Send for BinlogParser<R>
impl<R> Sync for BinlogParser<R>
impl<R> Unpin for BinlogParser<R>
impl<R> UnsafeUnpin for BinlogParser<R>where
BufReader<R>: UnsafeUnpin,
impl<R> UnwindSafe for BinlogParser<R>where
BufReader<R>: UnwindSafe,
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.