|
||||
File indexing completed on 2025-01-31 10:12:04
0001 // Protocol Buffers - Google's data interchange format 0002 // Copyright 2008 Google Inc. All rights reserved. 0003 // 0004 // Use of this source code is governed by a BSD-style 0005 // license that can be found in the LICENSE file or at 0006 // https://developers.google.com/open-source/licenses/bsd 0007 0008 // Adapted from the patch of kenton@google.com (Kenton Varda) 0009 // See https://github.com/protocolbuffers/protobuf/pull/710 for details. 0010 0011 #ifndef GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__ 0012 #define GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__ 0013 0014 #include <ostream> 0015 0016 #include "google/protobuf/io/coded_stream.h" 0017 #include "google/protobuf/io/zero_copy_stream_impl.h" 0018 #include "google/protobuf/message_lite.h" 0019 0020 // Must be included last. 0021 #include "google/protobuf/port_def.inc" 0022 0023 namespace google { 0024 namespace protobuf { 0025 namespace util { 0026 0027 // Write a single size-delimited message to the given stream. Delimited 0028 // format allows a single file or stream to contain multiple messages, 0029 // whereas normally writing multiple non-delimited messages to the same 0030 // stream would cause them to be merged. A delimited message is a varint 0031 // encoding the message size followed by a message of exactly that size. 0032 // 0033 // Note that if you want to *read* a delimited message from a file descriptor 0034 // or istream, you will need to construct an io::FileInputStream or 0035 // io::OstreamInputStream (implementations of io::ZeroCopyStream) and use the 0036 // utility function ParseDelimitedFromZeroCopyStream(). You must then 0037 // continue to use the same ZeroCopyInputStream to read all further data from 0038 // the stream until EOF. This is because these ZeroCopyInputStream 0039 // implementations are buffered: they read a big chunk of data at a time, 0040 // then parse it. As a result, they may read past the end of the delimited 0041 // message. There is no way for them to push the extra data back into the 0042 // underlying source, so instead you must keep using the same stream object. 0043 bool PROTOBUF_EXPORT SerializeDelimitedToFileDescriptor( 0044 const MessageLite& message, int file_descriptor); 0045 0046 bool PROTOBUF_EXPORT SerializeDelimitedToOstream(const MessageLite& message, 0047 std::ostream* output); 0048 0049 // Read a single size-delimited message from the given stream. Delimited 0050 // format allows a single file or stream to contain multiple messages, 0051 // whereas normally parsing consumes the entire input. A delimited message 0052 // is a varint encoding the message size followed by a message of exactly 0053 // that size. 0054 // 0055 // If |clean_eof| is not NULL, then it will be set to indicate whether the 0056 // stream ended cleanly. That is, if the stream ends without this method 0057 // having read any data at all from it, then *clean_eof will be set true, 0058 // otherwise it will be set false. Note that these methods return false 0059 // on EOF, but they also return false on other errors, so |clean_eof| is 0060 // needed to distinguish a clean end from errors. 0061 bool PROTOBUF_EXPORT ParseDelimitedFromZeroCopyStream( 0062 MessageLite* message, io::ZeroCopyInputStream* input, bool* clean_eof); 0063 0064 bool PROTOBUF_EXPORT ParseDelimitedFromCodedStream(MessageLite* message, 0065 io::CodedInputStream* input, 0066 bool* clean_eof); 0067 0068 // Write a single size-delimited message from the given stream. Delimited 0069 // format allows a single file or stream to contain multiple messages, 0070 // whereas normally writing multiple non-delimited messages to the same 0071 // stream would cause them to be merged. A delimited message is a varint 0072 // encoding the message size followed by a message of exactly that size. 0073 bool PROTOBUF_EXPORT SerializeDelimitedToZeroCopyStream( 0074 const MessageLite& message, io::ZeroCopyOutputStream* output); 0075 0076 bool PROTOBUF_EXPORT SerializeDelimitedToCodedStream( 0077 const MessageLite& message, io::CodedOutputStream* output); 0078 0079 } // namespace util 0080 } // namespace protobuf 0081 } // namespace google 0082 0083 #include "google/protobuf/port_undef.inc" 0084 0085 #endif // GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |