iemejia commented on code in PR #3859:
URL: https://github.com/apache/avro/pull/3859#discussion_r3565836923
##########
lang/c++/include/avro/Stream.hh:
##########
@@ -345,6 +356,26 @@ struct StreamReader {
return next_ != end_ || fill();
}
+ /**
+ * Returns the number of bytes still available to be read: those already
+ * buffered in this reader plus whatever the underlying stream reports as
+ * remaining. Returns a negative value when the underlying stream cannot
+ * report its remaining size.
+ */
+ int64_t remainingBytes() const {
+ if (in_ == nullptr) {
+ return -1;
+ }
+ int64_t streamRemaining = in_->remainingBytes();
+ if (streamRemaining < 0) {
+ return -1;
+ }
+ // end_ - next_ is the data already buffered in this reader; it is
added
+ // to what the underlying stream still has. The addition promotes the
+ // pointer difference to int64_t.
+ return (end_ - next_) + streamRemaining;
+ }
Review Comment:
Good catch. Fixed in 83b3b7137a: the buffered-byte count is now computed as
(next_ != nullptr) ? (end_ - next_) : 0, so the pointer subtraction is skipped
when next_/end_ are both null (right after init()/reset(), before any fill).
Added testBytesRemainingRightAfterInit that calls bytesRemaining() immediately
after init() on a BinaryDecoder.
--
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]