This is an automated email from the ASF dual-hosted git repository. jamesge pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/master by this push: new 2b748f8 Rename read_bytes() in RecordReader to offset() to avoid misusage and adjust the UT 2b748f8 is described below commit 2b748f82c3447196c8ce372733e5af8f8d76cef5 Author: gejun <ge...@bilibili.com> AuthorDate: Wed May 22 17:41:47 2019 +0800 Rename read_bytes() in RecordReader to offset() to avoid misusage and adjust the UT --- src/butil/recordio.cc | 10 +++++----- src/butil/recordio.h | 6 ++++-- test/recordio_unittest.cpp | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/butil/recordio.cc b/src/butil/recordio.cc index 447fde3..12befac 100755 --- a/src/butil/recordio.cc +++ b/src/butil/recordio.cc @@ -210,7 +210,7 @@ int RecordReader::CutRecord(Record* rec) { if (*(const uint32_t*)dummy != *(const uint32_t*)BRPC_RECORDIO_MAGIC) { LOG(ERROR) << "Invalid magic_num=" << butil::PrintedAsBinary(std::string((char*)headbuf, 4)) - << ", offset=" << read_bytes(); + << ", offset=" << offset(); return -1; } uint32_t tmp = NetToHost32(*(const uint32_t*)(headbuf + 4)); @@ -224,7 +224,7 @@ int RecordReader::CutRecord(Record* rec) { << std::hex << tmp << std::dec << "(metabit=" << has_meta << " size=" << data_size - << " offset=" << read_bytes() + << " offset=" << offset() << "), expected=" << (unsigned)headbuf[8] << " actual=" << (unsigned)checksum; return -1; @@ -233,7 +233,7 @@ int RecordReader::CutRecord(Record* rec) { LOG(ERROR) << "data_size=" << data_size << " is larger than -recordio_max_record_size=" << FLAGS_recordio_max_record_size - << ", offset=" << read_bytes(); + << ", offset=" << offset(); return -1; } if (_cutter.remaining_bytes() < data_size) { @@ -257,13 +257,13 @@ int RecordReader::CutRecord(Record* rec) { if (consumed_bytes + 5 + name_size + meta_size > data_size) { LOG(ERROR) << name << ".meta_size=" << meta_size << " is inconsistent with its data_size=" << data_size - << ", offset=" << read_bytes(); + << ", offset=" << offset(); return -1; } butil::IOBuf* meta = rec->MutableMeta(name, true/*null_on_found*/); if (meta == NULL) { LOG(ERROR) << "Fail to add meta=" << name - << ", offset=" << read_bytes(); + << ", offset=" << offset(); return -1; } _cutter.cutn(meta, meta_size); diff --git a/src/butil/recordio.h b/src/butil/recordio.h index cd50592..3541bdf 100755 --- a/src/butil/recordio.h +++ b/src/butil/recordio.h @@ -102,8 +102,10 @@ public: // END_OF_READER means all data in the IReader are successfully consumed. int last_error() const { return _last_error; } - // Total bytes of all read records. - size_t read_bytes() const { return _ncut; } + // Total bytes consumed. + // NOTE: this value may not equal to read bytes from the IReader even if + // the reader runs out, due to parsing errors. + size_t offset() const { return _ncut; } private: bool CutUntilNextRecordCandidate(); diff --git a/test/recordio_unittest.cpp b/test/recordio_unittest.cpp index 2fe9a08..d7e7bd3 100755 --- a/test/recordio_unittest.cpp +++ b/test/recordio_unittest.cpp @@ -164,7 +164,7 @@ TEST(RecordIOTest, write_read_basic) { ASSERT_FALSE(rr.ReadNext(NULL)); ASSERT_EQ((int)butil::RecordReader::END_OF_READER, rr.last_error()); - ASSERT_EQ(sw.str().size(), rr.read_bytes()); + ASSERT_EQ(sw.str().size(), rr.offset()); } TEST(RecordIOTest, incomplete_reader) { @@ -208,7 +208,7 @@ TEST(RecordIOTest, incomplete_reader) { ASSERT_FALSE(rr.ReadNext(NULL)); ASSERT_EQ(EAGAIN, rr.last_error()); - ASSERT_EQ(sw.str().size(), rr.read_bytes()); + ASSERT_EQ(sw.str().size(), rr.offset()); } static std::string rand_string(int min_len, int max_len) { @@ -299,8 +299,8 @@ TEST(RecordIOTest, write_read_random) { ASSERT_EQ(name_value_list[j].second, *r.MetaAt(0).data); } ASSERT_EQ((int)butil::RecordReader::END_OF_READER, rr.last_error()); - ASSERT_EQ(str.size(), rr.read_bytes()); ASSERT_EQ(j, name_value_list.size()); + ASSERT_LE(str.size() - rr.offset(), 3); } } // namespace --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org