Skip to content

Commit 0565d8d

Browse files
x1wanzhaohanqing
andauthored
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 <zhaohanqing@kuaishou.com>
1 parent d5dab28 commit 0565d8d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/butil/iobuf.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,10 +1849,14 @@ void IOBufAsZeroCopyInputStream::BackUp(int count) {
18491849
}
18501850
}
18511851

1852-
// Skips a number of bytes. Returns false if the end of the stream is
1853-
// reached or some input error occurred. In the end-of-stream case, the
1854-
// stream is advanced to the end of the stream (so ByteCount() will return
1855-
// the total size of the stream).
1852+
// Skips `count` number of bytes.
1853+
// Returns true on success, or false if some input error occurred, or `count`
1854+
// exceeds the end of the stream. This function may skip up to `count - 1`
1855+
// bytes in case of failure.
1856+
//
1857+
// Preconditions:
1858+
// * `count` is non-negative.
1859+
//
18561860
bool IOBufAsZeroCopyInputStream::Skip(int count) {
18571861
const IOBuf::BlockRef* cur_ref = _buf->_pref_at(_ref_index);
18581862
while (cur_ref) {
@@ -1867,7 +1871,7 @@ bool IOBufAsZeroCopyInputStream::Skip(int count) {
18671871
_byte_count += left_bytes;
18681872
cur_ref = _buf->_pref_at(++_ref_index);
18691873
}
1870-
return false;
1874+
return (0 == count);
18711875
}
18721876

18731877
int64_t IOBufAsZeroCopyInputStream::ByteCount() const {
@@ -2102,4 +2106,4 @@ bool IOBufBytesIterator::forward_one_block(const void** data, size_t* size) {
21022106

21032107
void* fast_memcpy(void *__restrict dest, const void *__restrict src, size_t n) {
21042108
return butil::iobuf::cp(dest, src, n);
2105-
} // namespace butil
2109+
} // namespace butil

0 commit comments

Comments
 (0)