Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
2b748f82
Commit
2b748f82
authored
May 22, 2019
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename read_bytes() in RecordReader to offset() to avoid misusage and adjust the UT
parent
50aaa985
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
10 deletions
+12
-10
recordio.cc
src/butil/recordio.cc
+5
-5
recordio.h
src/butil/recordio.h
+4
-2
recordio_unittest.cpp
test/recordio_unittest.cpp
+3
-3
No files found.
src/butil/recordio.cc
View file @
2b748f82
...
...
@@ -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
);
...
...
src/butil/recordio.h
View file @
2b748f82
...
...
@@ -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
();
...
...
test/recordio_unittest.cpp
View file @
2b748f82
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment