diff options
Diffstat (limited to 'src/google/protobuf/wire_format_lite.h')
-rw-r--r-- | src/google/protobuf/wire_format_lite.h | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index cf614c02..2244b35d 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -346,32 +346,27 @@ class LIBPROTOBUF_EXPORT WireFormatLite { Operation op, const char* field_name); + template <typename MessageType> static inline bool ReadGroup(int field_number, io::CodedInputStream* input, - MessageLite* value); + MessageType* value); + + template <typename MessageType> static inline bool ReadMessage(io::CodedInputStream* input, - MessageLite* value); + MessageType* value); - // Like above, but de-virtualize the call to MergePartialFromCodedStream(). - // The pointer must point at an instance of MessageType, *not* a subclass (or - // the subclass must not override MergePartialFromCodedStream()). + // Do not use. template <typename MessageType> static inline bool ReadGroupNoVirtual(int field_number, io::CodedInputStream* input, - MessageType* value); - template<typename MessageType> - static inline bool ReadMessageNoVirtual(io::CodedInputStream* input, - MessageType* value); - - // The same, but do not modify input's recursion depth. This is useful - // when reading a bunch of groups or messages in a loop, because then the - // recursion depth can be incremented before the loop and decremented after. - template<typename MessageType> - static inline bool ReadGroupNoVirtualNoRecursionDepth( - int field_number, io::CodedInputStream* input, MessageType* value); + MessageType* value) { + return ReadGroup(field_number, input, value); + } template<typename MessageType> - static inline bool ReadMessageNoVirtualNoRecursionDepth( - io::CodedInputStream* input, MessageType* value); + static inline bool ReadMessageNoVirtual(io::CodedInputStream* input, + MessageType* value) { + return ReadMessage(input, value); + } // Write a tag. The Write*() functions typically include the tag, so // normally there's no need to call this unless using the Write*NoTag() @@ -612,12 +607,14 @@ class LIBPROTOBUF_EXPORT WireFormatLite { // of serialization, the "ToArray" variants may be invoked. But they don't // have a CodedOutputStream available, so they get an additional parameter // telling them whether to serialize deterministically. + template<typename MessageType> INL static uint8* InternalWriteGroupToArray(int field_number, - const MessageLite& value, + const MessageType& value, bool deterministic, uint8* target); + template<typename MessageType> INL static uint8* InternalWriteMessageToArray(int field_number, - const MessageLite& value, + const MessageType& value, bool deterministic, uint8* target); @@ -674,13 +671,13 @@ class LIBPROTOBUF_EXPORT WireFormatLite { static inline size_t SInt64Size ( int64 value); static inline size_t EnumSize ( int value); - static size_t Int32Size (const RepeatedField< int32>& value); - static inline size_t Int64Size (const RepeatedField< int64>& value); - static size_t UInt32Size(const RepeatedField<uint32>& value); - static inline size_t UInt64Size(const RepeatedField<uint64>& value); - static size_t SInt32Size(const RepeatedField< int32>& value); - static inline size_t SInt64Size(const RepeatedField< int64>& value); - static size_t EnumSize (const RepeatedField< int>& value); + static size_t Int32Size (const RepeatedField< int32>& value); + static size_t Int64Size (const RepeatedField< int64>& value); + static size_t UInt32Size(const RepeatedField<uint32>& value); + static size_t UInt64Size(const RepeatedField<uint64>& value); + static size_t SInt32Size(const RepeatedField< int32>& value); + static size_t SInt64Size(const RepeatedField< int64>& value); + static size_t EnumSize (const RepeatedField< int>& value); // These types always have the same size. static const size_t kFixed32Size = 4; @@ -694,8 +691,10 @@ class LIBPROTOBUF_EXPORT WireFormatLite { static inline size_t StringSize(const string& value); static inline size_t BytesSize (const string& value); - static inline size_t GroupSize (const MessageLite& value); - static inline size_t MessageSize(const MessageLite& value); + template<typename MessageType> + static inline size_t GroupSize (const MessageType& value); + template<typename MessageType> + static inline size_t MessageSize(const MessageType& value); // Like above, but de-virtualize the call to ByteSize(). The // pointer must point at an instance of MessageType, *not* a subclass (or @@ -764,9 +763,9 @@ class LIBPROTOBUF_EXPORT CodedOutputStreamFieldSkipper : public FieldSkipper { virtual ~CodedOutputStreamFieldSkipper() {} // implements FieldSkipper ----------------------------------------- - virtual bool SkipField(io::CodedInputStream* input, uint32 tag); - virtual bool SkipMessage(io::CodedInputStream* input); - virtual void SkipUnknownEnum(int field_number, int value); + 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; protected: io::CodedOutputStream* unknown_fields_; @@ -860,7 +859,7 @@ inline uint32 WireFormatLite::ZigZagEncode32(int32 n) { inline int32 WireFormatLite::ZigZagDecode32(uint32 n) { // Note: Using unsigned types prevent undefined behavior - return static_cast<int32>((n >> 1) ^ -(n & 1)); + return static_cast<int32>((n >> 1) ^ (~(n & 1) + 1)); } inline uint64 WireFormatLite::ZigZagEncode64(int64 n) { @@ -871,7 +870,7 @@ inline uint64 WireFormatLite::ZigZagEncode64(int64 n) { inline int64 WireFormatLite::ZigZagDecode64(uint64 n) { // Note: Using unsigned types prevent undefined behavior - return static_cast<int64>((n >> 1) ^ -(n & 1)); + return static_cast<int64>((n >> 1) ^ (~(n & 1) + 1)); } // String is for UTF-8 text only, but, even so, ReadString() can simply |