splix commented on code in PR #530:
URL: https://github.com/apache/avro-rs/pull/530#discussion_r3038876846
##########
avro/src/reader/block.rs:
##########
@@ -35,10 +35,57 @@ use crate::{
util,
};
+/// Byte offset and record count of a single Avro data block.
+///
+/// Captured automatically as blocks are read during forward iteration.
+/// Use with [`super::Reader::seek_to_block`] to jump back to a
previously-read block.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct BlockPosition {
+ /// Byte offset in the stream where this block starts (before the
object-count varint).
+ pub offset: u64,
+ /// Total number of records in this block.
+ pub message_count: usize,
+}
+
+/// Wraps an inner reader and tracks the current byte position.
+///
+/// Avoids requiring `Seek` just to know how many bytes have been consumed.
+/// When the inner reader also implements `Seek`, seeking updates the tracked
position.
+#[derive(Debug, Clone)]
+struct PositionTracker<R> {
+ inner: R,
+ pos: u64,
+}
+
+impl<R> PositionTracker<R> {
+ fn new(inner: R) -> Self {
+ Self { inner, pos: 0 }
+ }
+
+ fn position(&self) -> u64 {
+ self.pos
+ }
+}
+
+impl<R: Read> Read for PositionTracker<R> {
+ fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
+ let n = self.inner.read(buf)?;
+ self.pos += n as u64;
+ Ok(n)
+ }
Review Comment:
Is there any common examples for this behavior?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]