This is an automated email from the ASF dual-hosted git repository.
guangmingchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 0565d8d2 Skip() return true if the end of the stream is reached (#3242)
0565d8d2 is described below
commit 0565d8d2c7a1cde87e94aa222fe4946e6f20c358
Author: x1wan <[email protected]>
AuthorDate: Mon Mar 16 20:47:20 2026 +0800
Skip() return true if the end of the stream is reached (#3242)
* return true if the end of the stream is reached
* update the comment with protocolbuffers/protobuf@ab25c3e
---------
Co-authored-by: zhaohanqing <[email protected]>
---
src/butil/iobuf.cpp | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/butil/iobuf.cpp b/src/butil/iobuf.cpp
index 26046e37..ce609323 100644
--- a/src/butil/iobuf.cpp
+++ b/src/butil/iobuf.cpp
@@ -1849,10 +1849,14 @@ void IOBufAsZeroCopyInputStream::BackUp(int count) {
}
}
-// Skips a number of bytes. Returns false if the end of the stream is
-// reached or some input error occurred. In the end-of-stream case, the
-// stream is advanced to the end of the stream (so ByteCount() will return
-// the total size of the stream).
+// Skips `count` number of bytes.
+// Returns true on success, or false if some input error occurred, or `count`
+// exceeds the end of the stream. This function may skip up to `count - 1`
+// bytes in case of failure.
+//
+// Preconditions:
+// * `count` is non-negative.
+//
bool IOBufAsZeroCopyInputStream::Skip(int count) {
const IOBuf::BlockRef* cur_ref = _buf->_pref_at(_ref_index);
while (cur_ref) {
@@ -1867,7 +1871,7 @@ bool IOBufAsZeroCopyInputStream::Skip(int count) {
_byte_count += left_bytes;
cur_ref = _buf->_pref_at(++_ref_index);
}
- return false;
+ return (0 == count);
}
int64_t IOBufAsZeroCopyInputStream::ByteCount() const {
@@ -2102,4 +2106,4 @@ bool IOBufBytesIterator::forward_one_block(const void**
data, size_t* size) {
void* fast_memcpy(void *__restrict dest, const void *__restrict src, size_t n)
{
return butil::iobuf::cp(dest, src, n);
-} // namespace butil
\ No newline at end of file
+} // namespace butil
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]