Skip to content

Commit ab25c3e

Browse files
martijnvelscopybara-github
authored andcommitted
Fix documentation for ZeroCopyInputStream
- Update Skip() to reflect the actual behavior when skipping to / beyond EOS - Move a paragraph for BackUp() that was wrongly added to ZeroCopyInputStream insteaf of ZeroCopyOutputStream PiperOrigin-RevId: 495682331
1 parent 6eddd66 commit ab25c3e

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/file_lists.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ set(libprotobuf_hdrs
168168
${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops.h
169169
${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.h
170170
${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h
171-
${protobuf_SOURCE_DIR}/src/google/protobuf/serial_arena.h
172171
${protobuf_SOURCE_DIR}/src/google/protobuf/service.h
172+
${protobuf_SOURCE_DIR}/src/google/protobuf/serial_arena.h
173173
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h
174174
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h
175175
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h

src/google/protobuf/io/zero_copy_stream.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,6 @@ class PROTOBUF_EXPORT ZeroCopyInputStream {
157157
// buffer that goes beyond what you wanted to read, you can use BackUp()
158158
// to return to the point where you intended to finish.
159159
//
160-
// This method can be called with `count = 0` to finalize (flush) any
161-
// previously returned buffer. For example, a file output stream can
162-
// flush buffers returned from a previous call to Next() upon such
163-
// BackUp(0) invocations. ZeroCopyOutputStream callers should always
164-
// invoke BackUp() after a final Next() call, even if there is no
165-
// excess buffer data to be backed up to indicate a flush point.
166-
//
167160
// Preconditions:
168161
// * The last method called must have been Next().
169162
// * count must be less than or equal to the size of the last buffer
@@ -175,10 +168,14 @@ class PROTOBUF_EXPORT ZeroCopyInputStream {
175168
// the same data again before producing new data.
176169
virtual void BackUp(int count) = 0;
177170

178-
// Skips a number of bytes. Returns false if the end of the stream is
179-
// reached or some input error occurred. In the end-of-stream case, the
180-
// stream is advanced to the end of the stream (so ByteCount() will return
181-
// the total size of the stream).
171+
// Skips `count` number of bytes.
172+
// Returns true on success, or false if some input error occurred, or `count`
173+
// exceeds the end of the stream. This function may skip up to `count - 1`
174+
// bytes in case of failure.
175+
//
176+
// Preconditions:
177+
// * `count` is non-negative.
178+
//
182179
virtual bool Skip(int count) = 0;
183180

184181
// Returns the total number of bytes read since this object was created.
@@ -235,6 +232,13 @@ class PROTOBUF_EXPORT ZeroCopyOutputStream {
235232
// than you needed. You don't want to write a bunch of garbage after the
236233
// end of your data, so you use BackUp() to back up.
237234
//
235+
// This method can be called with `count = 0` to finalize (flush) any
236+
// previously returned buffer. For example, a file output stream can
237+
// flush buffers returned from a previous call to Next() upon such
238+
// BackUp(0) invocations. ZeroCopyOutputStream callers should always
239+
// invoke BackUp() after a final Next() call, even if there is no
240+
// excess buffer data to be backed up to indicate a flush point.
241+
//
238242
// Preconditions:
239243
// * The last method called must have been Next().
240244
// * count must be less than or equal to the size of the last buffer

0 commit comments

Comments
 (0)