aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/message_lite.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/message_lite.h')
-rw-r--r--src/google/protobuf/message_lite.h107
1 files changed, 64 insertions, 43 deletions
diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h
index b8644142..0e8c3475 100644
--- a/src/google/protobuf/message_lite.h
+++ b/src/google/protobuf/message_lite.h
@@ -40,29 +40,47 @@
#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__
#include <climits>
+#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/once.h>
#include <google/protobuf/arena.h>
-#include <google/protobuf/stubs/port.h>
+#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/port.h>
+
+
+#include <google/protobuf/port_def.inc>
+
+#ifdef SWIG
+#error "You cannot SWIG proto headers"
+#endif
namespace google {
namespace protobuf {
+
template <typename T>
class RepeatedPtrField;
+
namespace io {
+
class CodedInputStream;
class CodedOutputStream;
class ZeroCopyInputStream;
class ZeroCopyOutputStream;
-}
+
+} // namespace io
namespace internal {
+#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
+// See parse_context.h for explanation
+class ParseContext;
+typedef const char* (*ParseFunc)(const char* ptr, const char* end, void* object,
+ ParseContext* ctx);
+#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
+
class RepeatedPtrFieldBase;
class WireFormatLite;
class WeakFieldMap;
-#ifndef SWIG
// We compute sizes as size_t but cache them as int. This function converts a
// computed size to a cached size. Since we don't proceed with serialization
// if the total size was > INT_MAX, it is not important what this function
@@ -128,14 +146,16 @@ class ExplicitlyConstructed {
// Default empty string object. Don't use this directly. Instead, call
// GetEmptyString() to get the reference.
-LIBPROTOBUF_EXPORT extern ExplicitlyConstructed<::std::string> fixed_address_empty_string;
+PROTOBUF_EXPORT extern ExplicitlyConstructed<::std::string>
+ fixed_address_empty_string;
-LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() {
+
+PROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() {
return fixed_address_empty_string.get();
}
-LIBPROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const string& str);
-#endif // SWIG
+PROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const std::string& str);
+
} // namespace internal
// Interface to light weight protocol messages.
@@ -161,7 +181,7 @@ LIBPROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const string& str);
// is best when you only have a small number of message types linked
// into your binary, in which case the size of the protocol buffers
// runtime itself is the biggest problem.
-class LIBPROTOBUF_EXPORT MessageLite {
+class PROTOBUF_EXPORT MessageLite {
public:
inline MessageLite() {}
virtual ~MessageLite() {}
@@ -169,7 +189,7 @@ class LIBPROTOBUF_EXPORT MessageLite {
// Basic Operations ------------------------------------------------
// Get the name of this message type, e.g. "foo.bar.BazProto".
- virtual string GetTypeName() const = 0;
+ virtual std::string GetTypeName() const = 0;
// Construct a new instance of the same type. Ownership is passed to the
// caller.
@@ -177,14 +197,14 @@ class LIBPROTOBUF_EXPORT MessageLite {
// Construct a new instance on the arena. Ownership is passed to the caller
// if arena is a NULL. Default implementation for backwards compatibility.
- virtual MessageLite* New(::google::protobuf::Arena* arena) const;
+ virtual MessageLite* New(Arena* arena) const;
// Get the arena, if any, associated with this message. Virtual method
// required for generic operations but most arena-related operations should
// use the GetArenaNoVirtual() generated-code method. Default implementation
// to reduce code size by avoiding the need for per-type implementations
// when types do not implement arena support.
- virtual ::google::protobuf::Arena* GetArena() const { return NULL; }
+ virtual Arena* GetArena() const { return NULL; }
// Get a pointer that may be equal to this message's arena, or may not be.
// If the value returned by this method is equal to some arena pointer, then
@@ -210,7 +230,7 @@ class LIBPROTOBUF_EXPORT MessageLite {
// This is not implemented for Lite messages -- it just returns "(cannot
// determine missing fields for lite message)". However, it is implemented
// for full messages. See message.h.
- virtual string InitializationErrorString() const;
+ virtual std::string InitializationErrorString() const;
// If |other| is the exact same class as this, calls MergeFrom(). Otherwise,
// results are undefined (probably crash).
@@ -249,10 +269,10 @@ class LIBPROTOBUF_EXPORT MessageLite {
// format, matching the encoding output by MessageLite::SerializeToString().
// If you'd like to convert a human-readable string into a protocol buffer
// object, see google::protobuf::TextFormat::ParseFromString().
- bool ParseFromString(const string& data);
+ bool ParseFromString(const std::string& data);
// Like ParseFromString(), but accepts messages that are missing
// required fields.
- bool ParsePartialFromString(const string& data);
+ bool ParsePartialFromString(const std::string& data);
// Parse a protocol buffer contained in an array of bytes.
bool ParseFromArray(const void* data, int size);
// Like ParseFromArray(), but accepts messages that are missing
@@ -278,7 +298,14 @@ class LIBPROTOBUF_EXPORT MessageLite {
//
// MergeFromCodedStream() is just implemented as MergePartialFromCodedStream()
// followed by IsInitialized().
+#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
+ virtual bool MergePartialFromCodedStream(io::CodedInputStream* input);
+#else
virtual bool MergePartialFromCodedStream(io::CodedInputStream* input) = 0;
+#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
+
+ // Merge a protocol buffer contained in a string.
+ bool MergeFromString(const std::string& data);
// Serialization ---------------------------------------------------
@@ -298,9 +325,9 @@ class LIBPROTOBUF_EXPORT MessageLite {
bool SerializePartialToZeroCopyStream(io::ZeroCopyOutputStream* output) const;
// Serialize the message and store it in the given string. All required
// fields must be set.
- bool SerializeToString(string* output) const;
+ bool SerializeToString(std::string* output) const;
// Like SerializeToString(), but allows missing required fields.
- bool SerializePartialToString(string* output) const;
+ bool SerializePartialToString(std::string* output) const;
// Serialize the message and store it in the given byte array. All required
// fields must be set.
bool SerializeToArray(void* data, int size) const;
@@ -313,15 +340,15 @@ class LIBPROTOBUF_EXPORT MessageLite {
// Note: If you intend to generate many such strings, you may
// reduce heap fragmentation by instead re-using the same string
// object with calls to SerializeToString().
- string SerializeAsString() const;
+ std::string SerializeAsString() const;
// Like SerializeAsString(), but allows missing required fields.
- string SerializePartialAsString() const;
+ std::string SerializePartialAsString() const;
// Like SerializeToString(), but appends to the data to the string's existing
// contents. All required fields must be set.
- bool AppendToString(string* output) const;
+ bool AppendToString(std::string* output) const;
// Like AppendToString(), but allows missing required fields.
- bool AppendPartialToString(string* output) const;
+ bool AppendPartialToString(std::string* output) const;
// Computes the serialized size of the message. This recursively calls
// ByteSizeLong() on all embedded messages.
@@ -331,7 +358,7 @@ class LIBPROTOBUF_EXPORT MessageLite {
virtual size_t ByteSizeLong() const = 0;
// Legacy ByteSize() API.
- PROTOBUF_RUNTIME_DEPRECATED("Please use ByteSizeLong() instead")
+ PROTOBUF_DEPRECATED_MSG("Please use ByteSizeLong() instead")
int ByteSize() const {
return internal::ToIntSize(ByteSizeLong());
}
@@ -370,19 +397,27 @@ class LIBPROTOBUF_EXPORT MessageLite {
virtual uint8* InternalSerializeWithCachedSizesToArray(bool deterministic,
uint8* target) const;
+#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
+ virtual internal::ParseFunc _ParseFunc() const {
+ GOOGLE_LOG(FATAL) << "Type " << typeid(*this).name()
+ << " doesn't implement _InternalParse";
+ return nullptr;
+ }
+#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
+
protected:
// CastToBase allows generated code to cast a RepeatedPtrField<T> to
// RepeatedPtrFieldBase. We try to restrict access to RepeatedPtrFieldBase
// because it is an implementation detail that user code should not access
// directly.
template <typename T>
- static ::google::protobuf::internal::RepeatedPtrFieldBase* CastToBase(
- ::google::protobuf::RepeatedPtrField<T>* repeated) {
+ static internal::RepeatedPtrFieldBase* CastToBase(
+ RepeatedPtrField<T>* repeated) {
return repeated;
}
template <typename T>
- static const ::google::protobuf::internal::RepeatedPtrFieldBase& CastToBase(
- const ::google::protobuf::RepeatedPtrField<T>& repeated) {
+ static const internal::RepeatedPtrFieldBase& CastToBase(
+ const RepeatedPtrField<T>& repeated) {
return repeated;
}
@@ -402,23 +437,9 @@ class LIBPROTOBUF_EXPORT MessageLite {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite);
};
-namespace internal {
-
-extern bool LIBPROTOBUF_EXPORT proto3_preserve_unknown_;
-
-// DO NOT USE: For migration only. Will be removed when Proto3 defaults to
-// preserve unknowns.
-inline bool GetProto3PreserveUnknownsDefault() {
- return proto3_preserve_unknown_;
-}
-
-// DO NOT USE: For migration only. Will be removed when Proto3 defaults to
-// preserve unknowns.
-void LIBPROTOBUF_EXPORT SetProto3PreserveUnknownsDefault(bool preserve);
-} // namespace internal
-
-
} // namespace protobuf
-
} // namespace google
+
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__