Skip to content

Commit

Permalink
pw_bluetooth_proxy: Clarify MultiBufWriter::IsComplete() behavior
Browse files Browse the repository at this point in the history
Change-Id: If3b9162cb9cd72f900df81b46af790d56377d88c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/266592
Lint: Lint 🤖 <[email protected]>
Docs-Not-Needed: Jonathon Reinhart <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Reviewed-by: David Rees <[email protected]>
Pigweed-Auto-Submit: Jonathon Reinhart <[email protected]>
Commit-Queue: Jonathon Reinhart <[email protected]>
  • Loading branch information
JonathonReinhart authored and CQ Bot Account committed Feb 12, 2025
1 parent d5e8ce4 commit d8e5ff1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pw_bluetooth_proxy/multibuf_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ TEST_F(RecombinationBufferTest, CanTakeMultiBuf) {
ASSERT_TRUE(bool(mbuf_span));
pw::span<uint8_t> mbuf_u8_span(reinterpret_cast<uint8_t*>(mbuf_span->data()),
mbuf_span->size());

EXPECT_TRUE(std::equal(
mbuf_u8_span.begin(), mbuf_u8_span.end(), kData.begin(), kData.end()));

// IsComplete() returns true
EXPECT_TRUE(recomb->IsComplete());

// Can no longer write
EXPECT_NE(recomb->Write(kData), OkStatus());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ class MultiBufWriter {
}

/// Returns true when the MultiBuf is full; i.e., when the total number of
/// bytes written equals the size passed to Create().
/// bytes written equals the size passed to Create(). Always returns true
/// after TakeMultiBuf() is called.
bool IsComplete() const { return remain() == 0; }

/// Consumes the underlying MultiBuf.
///
/// After this method is called, this object is reset to an empty state:
/// No data can be written, and all data accesors will return an empty
/// result.
/// result. IsComplete() will return true.
multibuf::MultiBuf&& TakeMultiBuf() {
write_offset_ = 0;

Expand All @@ -74,6 +75,9 @@ class MultiBufWriter {

private:
MultiBufWriter(multibuf::MultiBuf&& buf) : buf_(std::move(buf)) {}

/// Returns the number of bytes remaining to be written before IsComplete()
/// returns true.
size_t remain() const { return buf_.size() - write_offset_; }

multibuf::MultiBuf buf_;
Expand Down

0 comments on commit d8e5ff1

Please sign in to comment.