diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2018-08-08 17:00:41 -0700 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2018-08-08 17:00:41 -0700 |
commit | 6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3 (patch) | |
tree | e575738adf52d24b883cca5e8928a5ded31caba1 /src/google/protobuf/wire_format.h | |
parent | e7746f487cb9cca685ffb1b3d7dccc5554b618a4 (diff) | |
download | protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.tar.gz protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.tar.bz2 protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.zip |
Down-integrate from google3.
Diffstat (limited to 'src/google/protobuf/wire_format.h')
-rw-r--r-- | src/google/protobuf/wire_format.h | 136 |
1 files changed, 75 insertions, 61 deletions
diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h index 36f4a0bb..5bdb1273 100644 --- a/src/google/protobuf/wire_format.h +++ b/src/google/protobuf/wire_format.h @@ -44,16 +44,23 @@ #include <google/protobuf/descriptor.h> #include <google/protobuf/message.h> #include <google/protobuf/wire_format_lite.h> +#include <google/protobuf/stubs/casts.h> + +#ifdef SWIG +#error "You cannot SWIG proto headers" +#endif namespace google { namespace protobuf { - namespace io { - class CodedInputStream; // coded_stream.h - class CodedOutputStream; // coded_stream.h - } - class UnknownFieldSet; // unknown_field_set.h -} +namespace io { +class CodedInputStream; // coded_stream.h +class CodedOutputStream; // coded_stream.h +} // namespace io +class UnknownFieldSet; // unknown_field_set.h +} // namespace protobuf +} // namespace google +namespace google { namespace protobuf { namespace internal { @@ -68,7 +75,6 @@ namespace internal { // This class is really a namespace that contains only static methods class LIBPROTOBUF_EXPORT WireFormat { public: - // Given a field return its WireType static inline WireFormatLite::WireType WireTypeForField( const FieldDescriptor* field); @@ -107,9 +113,8 @@ class LIBPROTOBUF_EXPORT WireFormat { // a parameter to this procedure. // // These return false iff the underlying stream returns a write error. - static void SerializeWithCachedSizes( - const Message& message, - int size, io::CodedOutputStream* output); + static void SerializeWithCachedSizes(const Message& message, int size, + io::CodedOutputStream* output); // Implements Message::ByteSize() via reflection. WARNING: The result // of this method is *not* cached anywhere. However, all embedded messages @@ -127,13 +132,14 @@ class LIBPROTOBUF_EXPORT WireFormat { static bool SkipField(io::CodedInputStream* input, uint32 tag, UnknownFieldSet* unknown_fields); - // Reads and ignores a message from the input. If unknown_fields is non-NULL, - // the contents will be added to it. + // Reads and ignores a message from the input. If unknown_fields is + // non-NULL, the contents will be added to it. static bool SkipMessage(io::CodedInputStream* input, UnknownFieldSet* unknown_fields); - // Read a packed enum field. If the is_valid function is not NULL, values for - // which is_valid(value) returns false are appended to unknown_fields_stream. + // Read a packed enum field. If the is_valid function is not NULL, values + // for which is_valid(value) returns false are appended to + // unknown_fields_stream. static bool ReadPackedEnumPreserveUnknowns(io::CodedInputStream* input, uint32 field_number, bool (*is_valid)(int), @@ -149,22 +155,19 @@ class LIBPROTOBUF_EXPORT WireFormat { // // Returns a pointer past the last written byte. static uint8* SerializeUnknownFieldsToArray( - const UnknownFieldSet& unknown_fields, - uint8* target); + const UnknownFieldSet& unknown_fields, uint8* target); // Same thing except for messages that have the message_set_wire_format // option. static void SerializeUnknownMessageSetItems( - const UnknownFieldSet& unknown_fields, - io::CodedOutputStream* output); + const UnknownFieldSet& unknown_fields, io::CodedOutputStream* output); // Same as above, except writing directly to the provided buffer. // Requires that the buffer have sufficient capacity for // ComputeUnknownMessageSetItemsSize(unknown_fields). // // Returns a pointer past the last written byte. static uint8* SerializeUnknownMessageSetItemsToArray( - const UnknownFieldSet& unknown_fields, - uint8* target); + const UnknownFieldSet& unknown_fields, uint8* target); // Compute the size of the UnknownFieldSet on the wire. static size_t ComputeUnknownFieldsSize(const UnknownFieldSet& unknown_fields); @@ -174,54 +177,47 @@ class LIBPROTOBUF_EXPORT WireFormat { static size_t ComputeUnknownMessageSetItemsSize( const UnknownFieldSet& unknown_fields); - // Helper functions for encoding and decoding tags. (Inlined below and in // _inl.h) // - // This is different from MakeTag(field->number(), field->type()) in the case - // of packed repeated fields. + // This is different from MakeTag(field->number(), field->type()) in the + // case of packed repeated fields. static uint32 MakeTag(const FieldDescriptor* field); // Parse a single field. The input should start out positioned immediately // after the tag. static bool ParseAndMergeField( uint32 tag, - const FieldDescriptor* field, // May be NULL for unknown - Message* message, - io::CodedInputStream* input); + const FieldDescriptor* field, // May be NULL for unknown + Message* message, io::CodedInputStream* input); // Serialize a single field. static void SerializeFieldWithCachedSizes( - const FieldDescriptor* field, // Cannot be NULL - const Message& message, - io::CodedOutputStream* output); + const FieldDescriptor* field, // Cannot be NULL + const Message& message, io::CodedOutputStream* output); // Compute size of a single field. If the field is a message type, this // will call ByteSize() for the embedded message, insuring that it caches // its size. - static size_t FieldByteSize( - const FieldDescriptor* field, // Cannot be NULL - const Message& message); + static size_t FieldByteSize(const FieldDescriptor* field, // Cannot be NULL + const Message& message); // Parse/serialize a MessageSet::Item group. Used with messages that use // opion message_set_wire_format = true. - static bool ParseAndMergeMessageSetItem( - io::CodedInputStream* input, - Message* message); + static bool ParseAndMergeMessageSetItem(io::CodedInputStream* input, + Message* message); static void SerializeMessageSetItemWithCachedSizes( - const FieldDescriptor* field, - const Message& message, + const FieldDescriptor* field, const Message& message, io::CodedOutputStream* output); - static size_t MessageSetItemByteSize( - const FieldDescriptor* field, - const Message& message); + static size_t MessageSetItemByteSize(const FieldDescriptor* field, + const Message& message); // Computes the byte size of a field, excluding tags. For packed fields, it // only includes the size of the raw data, and not the size of the total // length, but for other length-delimited types, the size of the length is // included. static size_t FieldDataOnlyByteSize( - const FieldDescriptor* field, // Cannot be NULL + const FieldDescriptor* field, // Cannot be NULL const Message& message); enum Operation { @@ -235,10 +231,8 @@ class LIBPROTOBUF_EXPORT WireFormat { static void VerifyUTF8String(const char* data, int size, Operation op); // The NamedField variant takes a field name in order to produce an // informative error message if verification fails. - static void VerifyUTF8StringNamedField(const char* data, - int size, - Operation op, - const char* field_name); + static void VerifyUTF8StringNamedField(const char* data, int size, + Operation op, const char* field_name); private: // Skip a MessageSet field. @@ -260,12 +254,12 @@ class LIBPROTOBUF_EXPORT UnknownFieldSetFieldSkipper : public FieldSkipper { public: UnknownFieldSetFieldSkipper(UnknownFieldSet* unknown_fields) : unknown_fields_(unknown_fields) {} - virtual ~UnknownFieldSetFieldSkipper() override {} + ~UnknownFieldSetFieldSkipper() override {} // implements FieldSkipper ----------------------------------------- - virtual bool SkipField(io::CodedInputStream* input, uint32 tag) override; - virtual bool SkipMessage(io::CodedInputStream* input) override; - virtual void SkipUnknownEnum(int field_number, int value) override; + bool SkipField(io::CodedInputStream* input, uint32 tag) override; + bool SkipMessage(io::CodedInputStream* input) override; + void SkipUnknownEnum(int field_number, int value) override; protected: UnknownFieldSet* unknown_fields_; @@ -287,8 +281,7 @@ inline WireFormatLite::WireType WireFormat::WireTypeForFieldType( // Some compilers don't like enum -> enum casts, so we implicit_cast to // int first. return WireFormatLite::WireTypeForFieldType( - static_cast<WireFormatLite::FieldType>( - implicit_cast<int>(type))); + static_cast<WireFormatLite::FieldType>(::google::protobuf::implicit_cast<int>(type))); } inline uint32 WireFormat::MakeTag(const FieldDescriptor* field) { @@ -299,37 +292,58 @@ inline size_t WireFormat::TagSize(int field_number, FieldDescriptor::Type type) { // Some compilers don't like enum -> enum casts, so we implicit_cast to // int first. - return WireFormatLite::TagSize(field_number, - static_cast<WireFormatLite::FieldType>( - implicit_cast<int>(type))); + return WireFormatLite::TagSize( + field_number, + static_cast<WireFormatLite::FieldType>(::google::protobuf::implicit_cast<int>(type))); } inline void WireFormat::VerifyUTF8String(const char* data, int size, - WireFormat::Operation op) { + WireFormat::Operation op) { #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED WireFormatLite::VerifyUtf8String( data, size, static_cast<WireFormatLite::Operation>(op), NULL); #else // Avoid the compiler warning about unused variables. - (void)data; (void)size; (void)op; + (void)data; + (void)size; + (void)op; #endif } -inline void WireFormat::VerifyUTF8StringNamedField( - const char* data, int size, WireFormat::Operation op, - const char* field_name) { +inline void WireFormat::VerifyUTF8StringNamedField(const char* data, int size, + WireFormat::Operation op, + const char* field_name) { #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED WireFormatLite::VerifyUtf8String( data, size, static_cast<WireFormatLite::Operation>(op), field_name); #else // Avoid the compiler warning about unused variables. - (void)data; (void)size; (void)op; (void)field_name; + (void)data; + (void)size; + (void)op; + (void)field_name; #endif } +inline void SerializeUnknownMessageSetItems( + const UnknownFieldSet& unknown_fields, io::CodedOutputStream* output) { + WireFormat::SerializeUnknownMessageSetItems(unknown_fields, output); +} + +inline uint8* SerializeUnknownMessageSetItemsToArray( + const UnknownFieldSet& unknown_fields, uint8* target) { + return WireFormat::SerializeUnknownMessageSetItemsToArray(unknown_fields, + target); +} + +inline size_t ComputeUnknownMessageSetItemsSize( + const UnknownFieldSet& unknown_fields) { + return WireFormat::ComputeUnknownMessageSetItemsSize(unknown_fields); +} + } // namespace internal } // namespace protobuf - } // namespace google + #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_H__ |