Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
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
protobuf
Commits
c415a144
Commit
c415a144
authored
Mar 17, 2017
by
Byron Yi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix several issues
parent
acaa9407
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
delimited_message_util.cc
src/google/protobuf/util/delimited_message_util.cc
+7
-7
delimited_message_util.h
src/google/protobuf/util/delimited_message_util.h
+6
-6
delimited_message_util_test.cc
src/google/protobuf/util/delimited_message_util_test.cc
+2
-2
No files found.
src/google/protobuf/util/delimited_message_util.cc
View file @
c415a144
...
...
@@ -7,12 +7,12 @@ namespace google {
namespace
protobuf
{
namespace
util
{
bool
SerializeDelimitedToFileDescriptor
(
const
Message
*
message
,
int
file_descriptor
)
{
bool
SerializeDelimitedToFileDescriptor
(
const
Message
Lite
&
message
,
int
file_descriptor
)
{
io
::
FileOutputStream
output
(
file_descriptor
);
return
SerializeDelimitedToZeroCopyStream
(
message
,
&
output
);
}
bool
SerializeDelimitedToOstream
(
const
Message
*
message
,
ostream
*
output
)
{
bool
SerializeDelimitedToOstream
(
const
Message
Lite
&
message
,
ostream
*
output
)
{
{
io
::
OstreamOutputStream
zero_copy_output
(
output
);
if
(
!
SerializeDelimitedToZeroCopyStream
(
message
,
&
zero_copy_output
))
return
false
;
...
...
@@ -49,14 +49,14 @@ bool ParseDelimitedFromCodedStream(MessageLite* message, io::CodedInputStream* i
return
true
;
}
bool
SerializeDelimitedToZeroCopyStream
(
const
MessageLite
*
message
,
io
::
ZeroCopyOutputStream
*
output
)
{
bool
SerializeDelimitedToZeroCopyStream
(
const
MessageLite
&
message
,
io
::
ZeroCopyOutputStream
*
output
)
{
google
::
protobuf
::
io
::
CodedOutputStream
coded_output
(
output
);
return
SerializeDelimitedToCodedStream
(
message
,
&
coded_output
);
}
bool
SerializeDelimitedToCodedStream
(
const
MessageLite
*
message
,
io
::
CodedOutputStream
*
output
)
{
bool
SerializeDelimitedToCodedStream
(
const
MessageLite
&
message
,
io
::
CodedOutputStream
*
output
)
{
// Write the size.
int
size
=
message
->
ByteSize
();
int
size
=
message
.
ByteSize
();
output
->
WriteVarint32
(
size
);
// Write the content.
...
...
@@ -64,10 +64,10 @@ bool SerializeDelimitedToCodedStream(const MessageLite* message, io::CodedOutput
if
(
buffer
!=
NULL
)
{
// Optimization: The message fits in one buffer, so use the faster
// direct-to-array serialization path.
message
->
SerializeWithCachedSizesToArray
(
buffer
);
message
.
SerializeWithCachedSizesToArray
(
buffer
);
}
else
{
// Slightly-slower path when the message is multiple buffers.
message
->
SerializeWithCachedSizes
(
output
);
message
.
SerializeWithCachedSizes
(
output
);
if
(
output
->
HadError
())
return
false
;
}
...
...
src/google/protobuf/util/delimited_message_util.h
View file @
c415a144
...
...
@@ -6,7 +6,7 @@
#include <ostream>
#include <google/protobuf/message.h>
#include <google/protobuf/message
_lite
.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
...
...
@@ -23,16 +23,16 @@ namespace util {
// Note that if you want to *read* a delimited message from a file descriptor
// or istream, you will need to construct an io::FileInputStream or
// io::OstreamInputStream (implementations of io::ZeroCopyStream) and use the
//
MessageLite method
ParseDelimitedFromZeroCopyStream(). You must then
//
utility function
ParseDelimitedFromZeroCopyStream(). You must then
// continue to use the same ZeroCopyInputStream to read all further data from
// the stream until EOF. This is because these ZeroCopyInputStream
// implementations are buffered: they read a big chunk of data at a time,
// then parse it. As a result, they may read past the end of the delimited
// message. There is no way for them to push the extra data back into the
// underlying source, so instead you must keep using the same stream object.
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToFileDescriptor
(
const
Message
*
message
,
int
file_descriptor
);
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToFileDescriptor
(
const
Message
Lite
&
message
,
int
file_descriptor
);
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToOstream
(
const
Message
*
message
,
ostream
*
output
);
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToOstream
(
const
Message
Lite
&
message
,
ostream
*
output
);
// Read a single size-delimited message from the given stream. Delimited
// format allows a single file or stream to contain multiple messages,
...
...
@@ -55,9 +55,9 @@ bool LIBPROTOBUF_EXPORT ParseDelimitedFromCodedStream(MessageLite* message, io::
// whereas normally writing multiple non-delimited messages to the same
// stream would cause them to be merged. A delimited message is a varint
// encoding the message size followed by a message of exactly that size.
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToZeroCopyStream
(
const
MessageLite
*
message
,
io
::
ZeroCopyOutputStream
*
output
);
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToZeroCopyStream
(
const
MessageLite
&
message
,
io
::
ZeroCopyOutputStream
*
output
);
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToCodedStream
(
const
MessageLite
*
message
,
io
::
CodedOutputStream
*
output
);
bool
LIBPROTOBUF_EXPORT
SerializeDelimitedToCodedStream
(
const
MessageLite
&
message
,
io
::
CodedOutputStream
*
output
);
}
// namespace util
}
// namespace protobuf
...
...
src/google/protobuf/util/delimited_message_util_test.cc
View file @
c415a144
...
...
@@ -20,11 +20,11 @@ TEST(MessageTest, DelimitedMessages) {
{
protobuf_unittest
::
TestAllTypes
message1
;
TestUtil
::
SetAllFields
(
&
message1
);
EXPECT_TRUE
(
SerializeDelimitedToOstream
(
&
message1
,
&
stream
));
EXPECT_TRUE
(
SerializeDelimitedToOstream
(
message1
,
&
stream
));
protobuf_unittest
::
TestPackedTypes
message2
;
TestUtil
::
SetPackedFields
(
&
message2
);
EXPECT_TRUE
(
SerializeDelimitedToOstream
(
&
message2
,
&
stream
));
EXPECT_TRUE
(
SerializeDelimitedToOstream
(
message2
,
&
stream
));
}
{
...
...
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