aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/util
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-09-07 16:15:38 -0700
committerGitHub <noreply@github.com>2018-09-07 16:15:38 -0700
commitf9d8138376765d229a32635c9209061e4e4aed8c (patch)
tree50719686fd7262f405c9bda8694d6c72e7c038b8 /src/google/protobuf/util
parent2e7563f40ec7f901ae8ae1cc749d701fa07e211d (diff)
parente53be9bce4556cf0d13e24f1a25a7d75f663144f (diff)
downloadprotobuf-f9d8138376765d229a32635c9209061e4e4aed8c.tar.gz
protobuf-f9d8138376765d229a32635c9209061e4e4aed8c.tar.bz2
protobuf-f9d8138376765d229a32635c9209061e4e4aed8c.zip
Merge pull request #5109 from haberman/integrate
Down-integrate from google3.
Diffstat (limited to 'src/google/protobuf/util')
-rw-r--r--src/google/protobuf/util/delimited_message_util.h23
-rw-r--r--src/google/protobuf/util/field_comparator.h12
-rw-r--r--src/google/protobuf/util/field_mask_util.cc8
-rw-r--r--src/google/protobuf/util/field_mask_util.h39
-rw-r--r--src/google/protobuf/util/internal/datapiece.h16
-rw-r--r--src/google/protobuf/util/internal/default_value_objectwriter.h28
-rw-r--r--src/google/protobuf/util/internal/error_listener.h8
-rw-r--r--src/google/protobuf/util/internal/expecting_objectwriter.h26
-rw-r--r--src/google/protobuf/util/internal/field_mask_utility.cc2
-rw-r--r--src/google/protobuf/util/internal/field_mask_utility.h4
-rw-r--r--src/google/protobuf/util/internal/json_objectwriter.h14
-rw-r--r--src/google/protobuf/util/internal/json_stream_parser.h16
-rw-r--r--src/google/protobuf/util/internal/location_tracker.h8
-rw-r--r--src/google/protobuf/util/internal/object_location_tracker.h2
-rw-r--r--src/google/protobuf/util/internal/object_source.h6
-rw-r--r--src/google/protobuf/util/internal/object_writer.h6
-rw-r--r--src/google/protobuf/util/internal/proto_writer.cc11
-rw-r--r--src/google/protobuf/util/internal/proto_writer.h22
-rw-r--r--src/google/protobuf/util/internal/protostream_objectsource.cc10
-rw-r--r--src/google/protobuf/util/internal/protostream_objectsource.h12
-rw-r--r--src/google/protobuf/util/internal/protostream_objectwriter.cc9
-rw-r--r--src/google/protobuf/util/internal/protostream_objectwriter.h33
-rw-r--r--src/google/protobuf/util/internal/protostream_objectwriter_test.cc16
-rw-r--r--src/google/protobuf/util/internal/structured_objectwriter.h8
-rw-r--r--src/google/protobuf/util/internal/type_info.h6
-rw-r--r--src/google/protobuf/util/internal/type_info_test_helper.h6
-rw-r--r--src/google/protobuf/util/internal/utility.cc6
-rw-r--r--src/google/protobuf/util/internal/utility.h61
-rw-r--r--src/google/protobuf/util/json_util.cc9
-rw-r--r--src/google/protobuf/util/json_util.h66
-rw-r--r--src/google/protobuf/util/message_differencer.h24
-rw-r--r--src/google/protobuf/util/message_differencer_unittest.cc6
-rw-r--r--src/google/protobuf/util/time_util.cc4
-rw-r--r--src/google/protobuf/util/time_util.h41
-rw-r--r--src/google/protobuf/util/type_resolver.h10
-rw-r--r--src/google/protobuf/util/type_resolver_util.h9
36 files changed, 355 insertions, 232 deletions
diff --git a/src/google/protobuf/util/delimited_message_util.h b/src/google/protobuf/util/delimited_message_util.h
index ffad0a7a..5f2d94cd 100644
--- a/src/google/protobuf/util/delimited_message_util.h
+++ b/src/google/protobuf/util/delimited_message_util.h
@@ -10,6 +10,8 @@
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
@@ -30,9 +32,11 @@ namespace util {
// 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 MessageLite& message, int file_descriptor);
+bool PROTOBUF_EXPORT SerializeDelimitedToFileDescriptor(
+ const MessageLite& message, int file_descriptor);
-bool LIBPROTOBUF_EXPORT SerializeDelimitedToOstream(const MessageLite& message, std::ostream* output);
+bool PROTOBUF_EXPORT SerializeDelimitedToOstream(const MessageLite& message,
+ std::ostream* output);
// Read a single size-delimited message from the given stream. Delimited
// format allows a single file or stream to contain multiple messages,
@@ -46,21 +50,28 @@ bool LIBPROTOBUF_EXPORT SerializeDelimitedToOstream(const MessageLite& message,
// otherwise it will be set false. Note that these methods return false
// on EOF, but they also return false on other errors, so |clean_eof| is
// needed to distinguish a clean end from errors.
-bool LIBPROTOBUF_EXPORT ParseDelimitedFromZeroCopyStream(MessageLite* message, io::ZeroCopyInputStream* input, bool* clean_eof);
+bool PROTOBUF_EXPORT ParseDelimitedFromZeroCopyStream(
+ MessageLite* message, io::ZeroCopyInputStream* input, bool* clean_eof);
-bool LIBPROTOBUF_EXPORT ParseDelimitedFromCodedStream(MessageLite* message, io::CodedInputStream* input, bool* clean_eof);
+bool PROTOBUF_EXPORT ParseDelimitedFromCodedStream(MessageLite* message,
+ io::CodedInputStream* input,
+ bool* clean_eof);
// Write a single size-delimited message from the given stream. Delimited
// format allows a single file or stream to contain multiple messages,
// 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 PROTOBUF_EXPORT SerializeDelimitedToZeroCopyStream(
+ const MessageLite& message, io::ZeroCopyOutputStream* output);
-bool LIBPROTOBUF_EXPORT SerializeDelimitedToCodedStream(const MessageLite& message, io::CodedOutputStream* output);
+bool PROTOBUF_EXPORT SerializeDelimitedToCodedStream(
+ const MessageLite& message, io::CodedOutputStream* output);
} // namespace util
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__
diff --git a/src/google/protobuf/util/field_comparator.h b/src/google/protobuf/util/field_comparator.h
index 624fb2cf..8c952831 100644
--- a/src/google/protobuf/util/field_comparator.h
+++ b/src/google/protobuf/util/field_comparator.h
@@ -39,6 +39,8 @@
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
@@ -55,7 +57,7 @@ class MessageDifferencer;
// Regular users should consider using or subclassing DefaultFieldComparator
// rather than this interface.
// Currently, this does not support comparing unknown fields.
-class LIBPROTOBUF_EXPORT FieldComparator {
+class PROTOBUF_EXPORT FieldComparator {
public:
FieldComparator();
virtual ~FieldComparator();
@@ -95,7 +97,7 @@ class LIBPROTOBUF_EXPORT FieldComparator {
// Basic implementation of FieldComparator. Supports three modes of floating
// point value comparison: exact, approximate using MathUtil::AlmostEqual
// method, and arbitrarily precise using MathUtil::WithinFractionOrMargin.
-class LIBPROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator {
+class PROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator {
public:
enum FloatComparison {
EXACT, // Floats and doubles are compared exactly.
@@ -207,8 +209,8 @@ class LIBPROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator {
return value_1 == value_2;
}
- bool CompareString(const FieldDescriptor& field, const string& value_1,
- const string& value_2) {
+ bool CompareString(const FieldDescriptor& field, const std::string& value_1,
+ const std::string& value_2) {
return value_1 == value_2;
}
@@ -260,4 +262,6 @@ class LIBPROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__
diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc
index cf65ef27..7cd652b1 100644
--- a/src/google/protobuf/util/field_mask_util.cc
+++ b/src/google/protobuf/util/field_mask_util.cc
@@ -160,7 +160,7 @@ bool FieldMaskUtil::GetFieldDescriptors(
return true;
}
-void FieldMaskUtil::InternalGetFieldMaskForAllFields(
+void FieldMaskUtil::GetFieldMaskForAllFields(
const Descriptor* descriptor, FieldMask* out) {
for (int i = 0; i < descriptor->field_count(); ++i) {
out->add_paths(descriptor->field(i)->name());
@@ -644,9 +644,9 @@ void FieldMaskUtil::Intersect(const FieldMask& mask1, const FieldMask& mask2,
intersection.MergeToFieldMask(out);
}
-void FieldMaskUtil::InternalSubtract(const Descriptor* descriptor,
- const FieldMask& mask1,
- const FieldMask& mask2, FieldMask* out) {
+void FieldMaskUtil::Subtract(const Descriptor* descriptor,
+ const FieldMask& mask1, const FieldMask& mask2,
+ FieldMask* out) {
if (mask1.paths().empty()) {
out->Clear();
return;
diff --git a/src/google/protobuf/util/field_mask_util.h b/src/google/protobuf/util/field_mask_util.h
index 6fabc3ec..7031442d 100644
--- a/src/google/protobuf/util/field_mask_util.h
+++ b/src/google/protobuf/util/field_mask_util.h
@@ -45,20 +45,20 @@ namespace google {
namespace protobuf {
namespace util {
-class LIBPROTOBUF_EXPORT FieldMaskUtil {
+class PROTOBUF_EXPORT FieldMaskUtil {
typedef google::protobuf::FieldMask FieldMask;
public:
// Converts FieldMask to/from string, formatted by separating each path
// with a comma (e.g., "foo_bar,baz.quz").
- static string ToString(const FieldMask& mask);
+ static std::string ToString(const FieldMask& mask);
static void FromString(StringPiece str, FieldMask* out);
// Converts FieldMask to/from string, formatted according to proto3 JSON
// spec for FieldMask (e.g., "fooBar,baz.quz"). If the field name is not
// style conforming (i.e., not snake_case when converted to string, or not
// camelCase when converted from string), the conversion will fail.
- static bool ToJsonString(const FieldMask& mask, string* out);
+ static bool ToJsonString(const FieldMask& mask, std::string* out);
static bool FromJsonString(StringPiece str, FieldMask* out);
// Get the descriptors of the fields which the given path from the message
@@ -98,15 +98,18 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil {
template <typename T>
static FieldMask GetFieldMaskForAllFields() {
FieldMask out;
- InternalGetFieldMaskForAllFields(T::descriptor(), &out);
+ GetFieldMaskForAllFields(T::descriptor(), &out);
return out;
}
template <typename T>
- GOOGLE_PROTOBUF_DEPRECATED_MSG(
- "Use *out = GetFieldMaskForAllFields() instead")
+ PROTOBUF_DEPRECATED_MSG("Use *out = GetFieldMaskForAllFields() instead")
static void GetFieldMaskForAllFields(FieldMask* out) {
- InternalGetFieldMaskForAllFields(T::descriptor(), out);
+ GetFieldMaskForAllFields(T::descriptor(), out);
}
+ // This flavor takes the protobuf type descriptor as an argument.
+ // Useful when the type is not known at compile time.
+ static void GetFieldMaskForAllFields(const Descriptor* descriptor,
+ FieldMask* out);
// Converts a FieldMask to the canonical form. It will:
// 1. Remove paths that are covered by another path. For example,
@@ -127,8 +130,13 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil {
template <typename T>
static void Subtract(const FieldMask& mask1, const FieldMask& mask2,
FieldMask* out) {
- InternalSubtract(T::descriptor(), mask1, mask2, out);
+ Subtract(T::descriptor(), mask1, mask2, out);
}
+ // This flavor takes the protobuf type descriptor as an argument.
+ // Useful when the type is not known at compile time.
+ static void Subtract(const Descriptor* descriptor,
+ const FieldMask& mask1, const FieldMask& mask2,
+ FieldMask* out);
// Returns true if path is covered by the given FieldMask. Note that path
// "foo.bar" covers all paths like "foo.bar.baz", "foo.bar.quz.x", etc.
@@ -169,7 +177,7 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil {
// Note that the input can contain characters not allowed in C identifiers.
// For example, "foo_bar,baz_quz" will be converted to "fooBar,bazQuz"
// successfully.
- static bool SnakeCaseToCamelCase(StringPiece input, string* output);
+ static bool SnakeCaseToCamelCase(StringPiece input, std::string* output);
// Converts a field name from camelCase to snake_case:
// 1. Every uppercase letter is converted to lowercase with a additional
// preceding "-".
@@ -182,17 +190,10 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil {
// Note that the input can contain characters not allowed in C identifiers.
// For example, "fooBar,bazQuz" will be converted to "foo_bar,baz_quz"
// successfully.
- static bool CamelCaseToSnakeCase(StringPiece input, string* output);
-
- static void InternalGetFieldMaskForAllFields(const Descriptor* descriptor,
- FieldMask* out);
-
- static void InternalSubtract(const Descriptor* descriptor,
- const FieldMask& mask1, const FieldMask& mask2,
- FieldMask* out);
+ static bool CamelCaseToSnakeCase(StringPiece input, std::string* output);
};
-class LIBPROTOBUF_EXPORT FieldMaskUtil::MergeOptions {
+class PROTOBUF_EXPORT FieldMaskUtil::MergeOptions {
public:
MergeOptions()
: replace_message_fields_(false), replace_repeated_fields_(false) {}
@@ -220,7 +221,7 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil::MergeOptions {
bool replace_repeated_fields_;
};
-class LIBPROTOBUF_EXPORT FieldMaskUtil::TrimOptions {
+class PROTOBUF_EXPORT FieldMaskUtil::TrimOptions {
public:
TrimOptions()
: keep_required_fields_(false) {}
diff --git a/src/google/protobuf/util/internal/datapiece.h b/src/google/protobuf/util/internal/datapiece.h
index 074fde69..556c0ec4 100644
--- a/src/google/protobuf/util/internal/datapiece.h
+++ b/src/google/protobuf/util/internal/datapiece.h
@@ -37,6 +37,8 @@
#include <google/protobuf/stubs/stringpiece.h>
#include <google/protobuf/stubs/statusor.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
class Enum;
@@ -58,7 +60,7 @@ class ProtoWriter;
// Just like StringPiece, the DataPiece class does not own the storage for
// the actual string or Cord, so it is the user's responsiblity to guarantee
// that the underlying storage is still valid when the DataPiece is accessed.
-class LIBPROTOBUF_EXPORT DataPiece {
+class PROTOBUF_EXPORT DataPiece {
public:
// Identifies data type of the value.
// These are the types supported by DataPiece.
@@ -121,7 +123,7 @@ class LIBPROTOBUF_EXPORT DataPiece {
bool use_strict_base64_decoding() { return use_strict_base64_decoding_; }
StringPiece str() const {
- GOOGLE_LOG_IF(DFATAL, type_ != TYPE_STRING) << "Not a string type.";
+ GOOGLE_LOG_IF(DFATAL, type_ != TYPE_STRING) << "Not a std::string type.";
return str_;
}
@@ -148,13 +150,13 @@ class LIBPROTOBUF_EXPORT DataPiece {
util::StatusOr<bool> ToBool() const;
// Parses, casts or converts the value stored in the DataPiece into a string.
- util::StatusOr<string> ToString() const;
+ util::StatusOr<std::string> ToString() const;
// Tries to convert the value contained in this datapiece to string. If the
// conversion fails, it returns the default_string.
- string ValueAsStringOrDefault(StringPiece default_string) const;
+ std::string ValueAsStringOrDefault(StringPiece default_string) const;
- util::StatusOr<string> ToBytes() const;
+ util::StatusOr<std::string> ToBytes() const;
// Converts a value into protocol buffer enum number. If the value is a
// string, first attempts conversion by name, trying names as follows:
@@ -198,7 +200,7 @@ class LIBPROTOBUF_EXPORT DataPiece {
To*)) const;
// Decodes a base64 string. Returns true on success.
- bool DecodeBase64(StringPiece src, string* dest) const;
+ bool DecodeBase64(StringPiece src, std::string* dest) const;
// Helper function to initialize this DataPiece with 'other'.
void InternalCopy(const DataPiece& other);
@@ -229,4 +231,6 @@ class LIBPROTOBUF_EXPORT DataPiece {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_DATAPIECE_H__
diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h
index d15cc7cb..7a8863ca 100644
--- a/src/google/protobuf/util/internal/default_value_objectwriter.h
+++ b/src/google/protobuf/util/internal/default_value_objectwriter.h
@@ -44,6 +44,8 @@
#include <google/protobuf/util/type_resolver.h>
#include <google/protobuf/stubs/stringpiece.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
@@ -55,7 +57,7 @@ namespace converter {
// ObjectWriter when EndObject() is called on the root object. It also writes
// out all non-repeated primitive fields that haven't been explicitly rendered
// with their default values (0 for numbers, "" for strings, etc).
-class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
+class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
public:
// A Callback function to check whether a field needs to be scrubbed.
//
@@ -69,7 +71,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
//
// The Field* should point to the google::protobuf::Field of "c".
typedef ResultCallback2<bool /*return*/,
- const std::vector<string>& /*path of the field*/,
+ const std::vector<std::string>& /*path of the field*/,
const google::protobuf::Field* /*field*/>
FieldScrubCallBack;
@@ -146,11 +148,11 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// "Node" represents a node in the tree that holds the input of
// DefaultValueObjectWriter.
- class LIBPROTOBUF_EXPORT Node {
+ class PROTOBUF_EXPORT Node {
public:
- Node(const string& name, const google::protobuf::Type* type, NodeKind kind,
+ Node(const std::string& name, const google::protobuf::Type* type, NodeKind kind,
const DataPiece& data, bool is_placeholder,
- const std::vector<string>& path, bool suppress_empty_list,
+ const std::vector<std::string>& path, bool suppress_empty_list,
bool preserve_proto_field_names, bool use_ints_for_enums,
FieldScrubCallBack* field_scrub_callback);
virtual ~Node() {
@@ -176,9 +178,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
virtual void WriteTo(ObjectWriter* ow);
// Accessors
- const string& name() const { return name_; }
+ const std::string& name() const { return name_; }
- const std::vector<string>& path() const { return path_; }
+ const std::vector<std::string>& path() const { return path_; }
const google::protobuf::Type* type() const { return type_; }
@@ -208,7 +210,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
void WriteChildren(ObjectWriter* ow);
// The name of this node.
- string name_;
+ std::string name_;
// google::protobuf::Type of this node. Owned by TypeInfo.
const google::protobuf::Type* type_;
// The kind of this node.
@@ -226,7 +228,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
bool is_placeholder_;
// Path of the field of this node
- std::vector<string> path_;
+ std::vector<std::string> path_;
// Whether to suppress empty list output.
bool suppress_empty_list_;
@@ -246,10 +248,10 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
};
// Creates a new Node and returns it. Caller owns memory of returned object.
- virtual Node* CreateNewNode(const string& name,
+ virtual Node* CreateNewNode(const std::string& name,
const google::protobuf::Type* type, NodeKind kind,
const DataPiece& data, bool is_placeholder,
- const std::vector<string>& path,
+ const std::vector<std::string>& path,
bool suppress_empty_list,
bool preserve_proto_field_names,
bool use_ints_for_enums,
@@ -297,7 +299,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// google::protobuf::Type of the root message type.
const google::protobuf::Type& type_;
// Holds copies of strings passed to RenderString.
- std::vector<string*> string_values_;
+ std::vector<std::string*> string_values_;
// The current Node. Owned by its parents.
Node* current_;
@@ -329,4 +331,6 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_DEFAULT_VALUE_OBJECTWRITER_H__
diff --git a/src/google/protobuf/util/internal/error_listener.h b/src/google/protobuf/util/internal/error_listener.h
index 18666526..c2b7560d 100644
--- a/src/google/protobuf/util/internal/error_listener.h
+++ b/src/google/protobuf/util/internal/error_listener.h
@@ -42,13 +42,15 @@
#include <google/protobuf/util/internal/location_tracker.h>
#include <google/protobuf/stubs/stringpiece.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
namespace converter {
// Interface for error listener.
-class LIBPROTOBUF_EXPORT ErrorListener {
+class PROTOBUF_EXPORT ErrorListener {
public:
virtual ~ErrorListener() {}
@@ -75,7 +77,7 @@ class LIBPROTOBUF_EXPORT ErrorListener {
};
// An error listener that ignores all errors.
-class LIBPROTOBUF_EXPORT NoopErrorListener : public ErrorListener {
+class PROTOBUF_EXPORT NoopErrorListener : public ErrorListener {
public:
NoopErrorListener() {}
~NoopErrorListener() override {}
@@ -101,4 +103,6 @@ class LIBPROTOBUF_EXPORT NoopErrorListener : public ErrorListener {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_ERROR_LISTENER_H__
diff --git a/src/google/protobuf/util/internal/expecting_objectwriter.h b/src/google/protobuf/util/internal/expecting_objectwriter.h
index a7f6fc22..108a15b9 100644
--- a/src/google/protobuf/util/internal/expecting_objectwriter.h
+++ b/src/google/protobuf/util/internal/expecting_objectwriter.h
@@ -94,7 +94,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* StartObject(StringPiece name) {
(name.empty() ? EXPECT_CALL(*mock_, StartObject(IsEmpty()))
- : EXPECT_CALL(*mock_, StartObject(StrEq(string(name)))))
+ : EXPECT_CALL(*mock_, StartObject(StrEq(std::string(name)))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@@ -109,7 +109,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* StartList(StringPiece name) {
(name.empty() ? EXPECT_CALL(*mock_, StartList(IsEmpty()))
- : EXPECT_CALL(*mock_, StartList(StrEq(string(name)))))
+ : EXPECT_CALL(*mock_, StartList(StrEq(std::string(name)))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@@ -126,7 +126,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_, RenderBool(IsEmpty(), TypedEq<bool>(value)))
: EXPECT_CALL(*mock_,
- RenderBool(StrEq(string(name)), TypedEq<bool>(value))))
+ RenderBool(StrEq(std::string(name)), TypedEq<bool>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@@ -136,7 +136,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_, RenderInt32(IsEmpty(), TypedEq<int32>(value)))
: EXPECT_CALL(*mock_,
- RenderInt32(StrEq(string(name)), TypedEq<int32>(value))))
+ RenderInt32(StrEq(std::string(name)), TypedEq<int32>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@@ -145,7 +145,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderUint32(StringPiece name, uint32 value) {
(name.empty()
? EXPECT_CALL(*mock_, RenderUint32(IsEmpty(), TypedEq<uint32>(value)))
- : EXPECT_CALL(*mock_, RenderUint32(StrEq(string(name)),
+ : EXPECT_CALL(*mock_, RenderUint32(StrEq(std::string(name)),
TypedEq<uint32>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@@ -156,7 +156,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_, RenderInt64(IsEmpty(), TypedEq<int64>(value)))
: EXPECT_CALL(*mock_,
- RenderInt64(StrEq(string(name)), TypedEq<int64>(value))))
+ RenderInt64(StrEq(std::string(name)), TypedEq<int64>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@@ -165,7 +165,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderUint64(StringPiece name, uint64 value) {
(name.empty()
? EXPECT_CALL(*mock_, RenderUint64(IsEmpty(), TypedEq<uint64>(value)))
- : EXPECT_CALL(*mock_, RenderUint64(StrEq(string(name)),
+ : EXPECT_CALL(*mock_, RenderUint64(StrEq(std::string(name)),
TypedEq<uint64>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@@ -176,7 +176,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_,
RenderDouble(IsEmpty(), NanSensitiveDoubleEq(value)))
- : EXPECT_CALL(*mock_, RenderDouble(StrEq(string(name)),
+ : EXPECT_CALL(*mock_, RenderDouble(StrEq(std::string(name)),
NanSensitiveDoubleEq(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@@ -187,7 +187,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_,
RenderFloat(IsEmpty(), NanSensitiveFloatEq(value)))
- : EXPECT_CALL(*mock_, RenderFloat(StrEq(string(name)),
+ : EXPECT_CALL(*mock_, RenderFloat(StrEq(std::string(name)),
NanSensitiveFloatEq(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@@ -199,10 +199,10 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_,
RenderString(IsEmpty(),
- TypedEq<StringPiece>(string(value))))
+ TypedEq<StringPiece>(std::string(value))))
: EXPECT_CALL(*mock_,
- RenderString(StrEq(string(name)),
- TypedEq<StringPiece>(string(value)))))
+ RenderString(StrEq(std::string(name)),
+ TypedEq<StringPiece>(std::string(value)))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@@ -221,7 +221,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderNull(StringPiece name) {
(name.empty() ? EXPECT_CALL(*mock_, RenderNull(IsEmpty()))
- : EXPECT_CALL(*mock_, RenderNull(StrEq(string(name))))
+ : EXPECT_CALL(*mock_, RenderNull(StrEq(std::string(name))))
.WillOnce(Return(mock_))
.RetiresOnSaturation());
return this;
diff --git a/src/google/protobuf/util/internal/field_mask_utility.cc b/src/google/protobuf/util/internal/field_mask_utility.cc
index 014b81aa..b0190127 100644
--- a/src/google/protobuf/util/internal/field_mask_utility.cc
+++ b/src/google/protobuf/util/internal/field_mask_utility.cc
@@ -34,6 +34,8 @@
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/status_macros.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
diff --git a/src/google/protobuf/util/internal/field_mask_utility.h b/src/google/protobuf/util/internal/field_mask_utility.h
index 7d1c2af0..97755804 100644
--- a/src/google/protobuf/util/internal/field_mask_utility.h
+++ b/src/google/protobuf/util/internal/field_mask_utility.h
@@ -45,14 +45,14 @@ namespace protobuf {
namespace util {
namespace converter {
-typedef string (*ConverterCallback)(StringPiece);
+typedef std::string (*ConverterCallback)(StringPiece);
typedef ResultCallback1<util::Status, StringPiece>* PathSinkCallback;
// Applies a 'converter' to each segment of a FieldMask path and returns the
// result. Quoted strings in the 'path' are copied to the output as-is without
// converting their content. Escaping is supported within quoted strings.
// For example, "ab\"_c" will be returned as "ab\"_c" without any changes.
-string ConvertFieldMaskPath(const StringPiece path,
+std::string ConvertFieldMaskPath(const StringPiece path,
ConverterCallback converter);
// Decodes a compact list of FieldMasks. For example, "a.b,a.c.d,a.c.e" will be
diff --git a/src/google/protobuf/util/internal/json_objectwriter.h b/src/google/protobuf/util/internal/json_objectwriter.h
index c8a061d5..ebfc7fba 100644
--- a/src/google/protobuf/util/internal/json_objectwriter.h
+++ b/src/google/protobuf/util/internal/json_objectwriter.h
@@ -38,6 +38,8 @@
#include <google/protobuf/util/internal/structured_objectwriter.h>
#include <google/protobuf/stubs/bytestream.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
@@ -82,7 +84,7 @@ namespace converter {
// uint64 would lose precision if rendered as numbers.
//
// JsonObjectWriter is thread-unsafe.
-class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
+class PROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
public:
JsonObjectWriter(StringPiece indent_string, io::CodedOutputStream* out)
: element_(new Element(/*parent=*/nullptr, /*is_json_object=*/false)),
@@ -115,7 +117,7 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
}
protected:
- class LIBPROTOBUF_EXPORT Element : public BaseElement {
+ class PROTOBUF_EXPORT Element : public BaseElement {
public:
Element(Element* parent, bool is_json_object)
: BaseElement(parent),
@@ -146,7 +148,7 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
Element* element() override { return element_.get(); }
private:
- class LIBPROTOBUF_EXPORT ByteSinkWrapper : public strings::ByteSink {
+ class PROTOBUF_EXPORT ByteSinkWrapper : public strings::ByteSink {
public:
explicit ByteSinkWrapper(io::CodedOutputStream* stream) : stream_(stream) {}
~ByteSinkWrapper() override {}
@@ -165,7 +167,7 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
// Renders a simple value as a string. By default all non-string Render
// methods convert their argument to a string and call this method. This
// method can then be used to render the simple value without escaping it.
- JsonObjectWriter* RenderSimple(StringPiece name, const string& value) {
+ JsonObjectWriter* RenderSimple(StringPiece name, const std::string& value) {
WritePrefix(name);
stream_->WriteString(value);
return this;
@@ -210,7 +212,7 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
std::unique_ptr<Element> element_;
io::CodedOutputStream* stream_;
ByteSinkWrapper sink_;
- const string indent_string_;
+ const std::string indent_string_;
// Whether to use regular or websafe base64 encoding for byte fields. Defaults
// to regular base64 encoding.
@@ -224,4 +226,6 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_JSON_OBJECTWRITER_H__
diff --git a/src/google/protobuf/util/internal/json_stream_parser.h b/src/google/protobuf/util/internal/json_stream_parser.h
index 4a065d27..3526ec57 100644
--- a/src/google/protobuf/util/internal/json_stream_parser.h
+++ b/src/google/protobuf/util/internal/json_stream_parser.h
@@ -38,6 +38,8 @@
#include <google/protobuf/stubs/stringpiece.h>
#include <google/protobuf/stubs/status.h>
+#include <google/protobuf/port_def.inc>
+
namespace util {
class Status;
} // namespace util
@@ -69,7 +71,7 @@ class ObjectWriter;
//
// This parser is thread-compatible as long as only one thread is calling a
// Parse() method at a time.
-class LIBPROTOBUF_EXPORT JsonStreamParser {
+class PROTOBUF_EXPORT JsonStreamParser {
public:
// Creates a JsonStreamParser that will write to the given ObjectWriter.
explicit JsonStreamParser(ObjectWriter* ow);
@@ -166,7 +168,7 @@ class LIBPROTOBUF_EXPORT JsonStreamParser {
util::Status ParseNumberHelper(NumberResult* result);
// Parse a number as double into a NumberResult.
- util::Status ParseDoubleHelper(const string& number, NumberResult* result);
+ util::Status ParseDoubleHelper(const std::string& number, NumberResult* result);
// Handles a { during parsing of a value.
util::Status HandleBeginObject();
@@ -232,7 +234,7 @@ class LIBPROTOBUF_EXPORT JsonStreamParser {
// Contains any leftover text from a previous chunk that we weren't able to
// fully parse, for example the start of a key or number.
- string leftover_;
+ std::string leftover_;
// The current chunk of JSON being parsed. Primarily used for providing
// context during error reporting.
@@ -246,7 +248,7 @@ class LIBPROTOBUF_EXPORT JsonStreamParser {
// Storage for key_ if we need to keep ownership, for example between chunks
// or if the key was unescaped from a JSON string.
- string key_storage_;
+ std::string key_storage_;
// True during the FinishParse() call, so we know that any errors are fatal.
// For example an unterminated string will normally result in cancelling and
@@ -258,14 +260,14 @@ class LIBPROTOBUF_EXPORT JsonStreamParser {
// Storage for the string we parsed. This may be empty if the string was able
// to be parsed directly from the input.
- string parsed_storage_;
+ std::string parsed_storage_;
// The character that opened the string, either ' or ".
// A value of 0 indicates that string parsing is not in process.
char string_open_;
// Storage for the chunk that are being parsed in ParseChunk().
- string chunk_storage_;
+ std::string chunk_storage_;
// Whether to allow non UTF-8 encoded input and replace invalid code points.
bool coerce_to_utf8_;
@@ -291,4 +293,6 @@ class LIBPROTOBUF_EXPORT JsonStreamParser {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_JSON_STREAM_PARSER_H__
diff --git a/src/google/protobuf/util/internal/location_tracker.h b/src/google/protobuf/util/internal/location_tracker.h
index 52173d76..c29a75a7 100644
--- a/src/google/protobuf/util/internal/location_tracker.h
+++ b/src/google/protobuf/util/internal/location_tracker.h
@@ -35,6 +35,8 @@
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
@@ -42,12 +44,12 @@ namespace converter {
// LocationTrackerInterface is an interface for classes that track
// the location information for the purpose of error reporting.
-class LIBPROTOBUF_EXPORT LocationTrackerInterface {
+class PROTOBUF_EXPORT LocationTrackerInterface {
public:
virtual ~LocationTrackerInterface() {}
// Returns the object location as human readable string.
- virtual string ToString() const = 0;
+ virtual std::string ToString() const = 0;
protected:
LocationTrackerInterface() {}
@@ -62,4 +64,6 @@ class LIBPROTOBUF_EXPORT LocationTrackerInterface {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_LOCATION_TRACKER_H__
diff --git a/src/google/protobuf/util/internal/object_location_tracker.h b/src/google/protobuf/util/internal/object_location_tracker.h
index 61189a79..571279d5 100644
--- a/src/google/protobuf/util/internal/object_location_tracker.h
+++ b/src/google/protobuf/util/internal/object_location_tracker.h
@@ -50,7 +50,7 @@ class ObjectLocationTracker : public LocationTrackerInterface {
~ObjectLocationTracker() override {}
// Returns empty because nothing is tracked.
- string ToString() const override { return ""; }
+ std::string ToString() const override { return ""; }
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjectLocationTracker);
diff --git a/src/google/protobuf/util/internal/object_source.h b/src/google/protobuf/util/internal/object_source.h
index 3a24b750..c8ee36fb 100644
--- a/src/google/protobuf/util/internal/object_source.h
+++ b/src/google/protobuf/util/internal/object_source.h
@@ -35,6 +35,8 @@
#include <google/protobuf/stubs/stringpiece.h>
#include <google/protobuf/stubs/status.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
@@ -48,7 +50,7 @@ class ObjectWriter;
// example, a character stream, or protobuf.
//
// Derived classes could be thread-unsafe.
-class LIBPROTOBUF_EXPORT ObjectSource {
+class PROTOBUF_EXPORT ObjectSource {
public:
virtual ~ObjectSource() {}
@@ -76,4 +78,6 @@ class LIBPROTOBUF_EXPORT ObjectSource {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_OBJECT_SOURCE_H__
diff --git a/src/google/protobuf/util/internal/object_writer.h b/src/google/protobuf/util/internal/object_writer.h
index a92c61da..a4b509da 100644
--- a/src/google/protobuf/util/internal/object_writer.h
+++ b/src/google/protobuf/util/internal/object_writer.h
@@ -34,6 +34,8 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stringpiece.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
@@ -55,7 +57,7 @@ class DataPiece;
//
// TODO(xinb): seems like a prime candidate to apply the RAII paradigm
// and get rid the need to call EndXXX().
-class LIBPROTOBUF_EXPORT ObjectWriter {
+class PROTOBUF_EXPORT ObjectWriter {
public:
virtual ~ObjectWriter() {}
@@ -137,4 +139,6 @@ class LIBPROTOBUF_EXPORT ObjectWriter {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_OBJECT_WRITER_H__
diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc
index 52921956..56ee774a 100644
--- a/src/google/protobuf/util/internal/proto_writer.cc
+++ b/src/google/protobuf/util/internal/proto_writer.cc
@@ -52,8 +52,8 @@ namespace protobuf {
namespace util {
namespace converter {
-using ::GOOGLE_PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
using io::CodedOutputStream;
+using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
using util::Status;
using util::StatusOr;
using util::error::INVALID_ARGUMENT;
@@ -67,6 +67,7 @@ ProtoWriter::ProtoWriter(TypeResolver* type_resolver,
own_typeinfo_(true),
done_(false),
ignore_unknown_fields_(false),
+ ignore_unknown_enum_values_(false),
use_lower_camel_for_enums_(false),
element_(nullptr),
size_insert_(),
@@ -86,6 +87,7 @@ ProtoWriter::ProtoWriter(const TypeInfo* typeinfo,
own_typeinfo_(false),
done_(false),
ignore_unknown_fields_(false),
+ ignore_unknown_enum_values_(false),
use_lower_camel_for_enums_(false),
element_(nullptr),
size_insert_(),
@@ -669,9 +671,10 @@ ProtoWriter* ProtoWriter::RenderPrimitiveField(
break;
}
case google::protobuf::Field_Kind_TYPE_ENUM: {
- status = WriteEnum(
- field.number(), data, typeinfo_->GetEnumByTypeUrl(field.type_url()),
- stream_.get(), use_lower_camel_for_enums_, ignore_unknown_fields_);
+ status = WriteEnum(field.number(), data,
+ typeinfo_->GetEnumByTypeUrl(field.type_url()),
+ stream_.get(), use_lower_camel_for_enums_,
+ ignore_unknown_enum_values_);
break;
}
default: // TYPE_GROUP or TYPE_MESSAGE
diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h
index 11761096..1a8df982 100644
--- a/src/google/protobuf/util/internal/proto_writer.h
+++ b/src/google/protobuf/util/internal/proto_writer.h
@@ -48,6 +48,8 @@
#include <google/protobuf/stubs/hash.h>
#include <google/protobuf/stubs/status.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace io {
@@ -76,7 +78,7 @@ class ObjectLocationTracker;
// special types by inheriting from it or by wrapping it.
//
// It also supports streaming.
-class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
+class PROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
public:
// Constructor. Does not take ownership of any parameter passed in.
ProtoWriter(TypeResolver* type_resolver, const google::protobuf::Type& type,
@@ -152,12 +154,17 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
ignore_unknown_fields_ = ignore_unknown_fields;
}
+ void set_ignore_unknown_enum_values(bool ignore_unknown_enum_values) {
+ ignore_unknown_enum_values_ = ignore_unknown_enum_values;
+ }
+
void set_use_lower_camel_for_enums(bool use_lower_camel_for_enums) {
use_lower_camel_for_enums_ = use_lower_camel_for_enums;
}
protected:
- class LIBPROTOBUF_EXPORT ProtoElement : public BaseElement, public LocationTrackerInterface {
+ class PROTOBUF_EXPORT ProtoElement : public BaseElement,
+ public LocationTrackerInterface {
public:
// Constructor for the root element. No parent nor field.
ProtoElement(const TypeInfo* typeinfo, const google::protobuf::Type& type,
@@ -187,7 +194,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
void RegisterField(const google::protobuf::Field* field);
// To report location on error messages.
- string ToString() const override;
+ std::string ToString() const override;
ProtoElement* parent() const override {
return static_cast<ProtoElement*>(BaseElement::parent());
@@ -321,9 +328,12 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
// Indicates whether we finished writing root message completely.
bool done_;
- // If true, don't report unknown field names and enum values to the listener.
+ // If true, don't report unknown field names to the listener.
bool ignore_unknown_fields_;
+ // If true, don't report unknown enum values to the listener.
+ bool ignore_unknown_enum_values_;
+
// If true, check if enum name in camel case or without underscore matches the
// field name.
bool use_lower_camel_for_enums_;
@@ -342,7 +352,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
// adapter_ : internal adapter between CodedOutputStream and buffer_.
// stream_ : wrapper for writing tags and other encodings in wire format.
strings::ByteSink* output_;
- string buffer_;
+ std::string buffer_;
io::StringOutputStream adapter_;
std::unique_ptr<io::CodedOutputStream> stream_;
@@ -362,4 +372,6 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTO_WRITER_H__
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc
index 2a1b2511..97a8bb48 100644
--- a/src/google/protobuf/util/internal/protostream_objectsource.cc
+++ b/src/google/protobuf/util/internal/protostream_objectsource.cc
@@ -66,8 +66,8 @@ using util::error::Code;
using util::error::INTERNAL;
}
namespace converter {
-using ::GOOGLE_PROTOBUF_NAMESPACE_ID::internal::WireFormat;
-using ::GOOGLE_PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
+using ::PROTOBUF_NAMESPACE_ID::internal::WireFormat;
+using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
using util::Status;
using util::StatusOr;
@@ -701,7 +701,7 @@ Status ProtoStreamObjectSource::RenderFieldMask(
std::unordered_map<string, ProtoStreamObjectSource::TypeRenderer>*
ProtoStreamObjectSource::renderers_ = NULL;
-GOOGLE_PROTOBUF_NAMESPACE_ID::internal::once_flag source_renderers_init_;
+PROTOBUF_NAMESPACE_ID::internal::once_flag source_renderers_init_;
void ProtoStreamObjectSource::InitRendererMap() {
renderers_ =
@@ -748,8 +748,8 @@ void ProtoStreamObjectSource::DeleteRendererMap() {
// static
ProtoStreamObjectSource::TypeRenderer*
ProtoStreamObjectSource::FindTypeRenderer(const string& type_url) {
- GOOGLE_PROTOBUF_NAMESPACE_ID::internal::call_once(source_renderers_init_,
- InitRendererMap);
+ PROTOBUF_NAMESPACE_ID::internal::call_once(source_renderers_init_,
+ InitRendererMap);
return FindOrNull(*renderers_, type_url);
}
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h
index 90e23a3a..c2549878 100644
--- a/src/google/protobuf/util/internal/protostream_objectsource.h
+++ b/src/google/protobuf/util/internal/protostream_objectsource.h
@@ -46,6 +46,8 @@
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/statusor.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
class Field;
@@ -73,7 +75,7 @@ class TypeInfo;
// <your message google::protobuf::Type>);
//
// Status status = os.WriteTo(<some ObjectWriter>);
-class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
+class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
public:
ProtoStreamObjectSource(io::CodedInputStream* stream,
TypeResolver* type_resolver,
@@ -160,7 +162,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
// Reads field value according to Field spec in 'field' and returns the read
// value as string. This only works for primitive datatypes (no message
// types).
- const string ReadFieldValueAsString(
+ const std::string ReadFieldValueAsString(
const google::protobuf::Field& field) const;
@@ -258,10 +260,10 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
StringPiece name,
ObjectWriter* ow);
- static std::unordered_map<string, TypeRenderer>* renderers_;
+ static std::unordered_map<std::string, TypeRenderer>* renderers_;
static void InitRendererMap();
static void DeleteRendererMap();
- static TypeRenderer* FindTypeRenderer(const string& type_url);
+ static TypeRenderer* FindTypeRenderer(const std::string& type_url);
// Same as above but renders all non-message field types. Callers don't call
// this function directly. They just use RenderField.
@@ -331,4 +333,6 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTOSTREAM_OBJECTSOURCE_H__
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc
index 3751e07c..9c52116e 100644
--- a/src/google/protobuf/util/internal/protostream_objectwriter.cc
+++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc
@@ -55,7 +55,7 @@ namespace protobuf {
namespace util {
namespace converter {
-using ::GOOGLE_PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
+using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
using util::Status;
using util::StatusOr;
using util::error::INVALID_ARGUMENT;
@@ -70,6 +70,7 @@ ProtoStreamObjectWriter::ProtoStreamObjectWriter(
current_(nullptr),
options_(options) {
set_ignore_unknown_fields(options_.ignore_unknown_fields);
+ set_ignore_unknown_enum_values(options_.ignore_unknown_enum_values);
set_use_lower_camel_for_enums(options_.use_lower_camel_for_enums);
}
@@ -1165,7 +1166,7 @@ ProtoStreamObjectWriter* ProtoStreamObjectWriter::RenderDataPiece(
// represented by the key.
std::unordered_map<string, ProtoStreamObjectWriter::TypeRenderer>*
ProtoStreamObjectWriter::renderers_ = NULL;
-GOOGLE_PROTOBUF_NAMESPACE_ID::internal::once_flag writer_renderers_init_;
+PROTOBUF_NAMESPACE_ID::internal::once_flag writer_renderers_init_;
void ProtoStreamObjectWriter::InitRendererMap() {
renderers_ =
@@ -1224,8 +1225,8 @@ void ProtoStreamObjectWriter::DeleteRendererMap() {
ProtoStreamObjectWriter::TypeRenderer*
ProtoStreamObjectWriter::FindTypeRenderer(const string& type_url) {
- GOOGLE_PROTOBUF_NAMESPACE_ID::internal::call_once(writer_renderers_init_,
- InitRendererMap);
+ PROTOBUF_NAMESPACE_ID::internal::call_once(writer_renderers_init_,
+ InitRendererMap);
return FindOrNull(*renderers_, type_url);
}
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.h b/src/google/protobuf/util/internal/protostream_objectwriter.h
index df56a8bd..fe8170d1 100644
--- a/src/google/protobuf/util/internal/protostream_objectwriter.h
+++ b/src/google/protobuf/util/internal/protostream_objectwriter.h
@@ -49,6 +49,8 @@
#include <google/protobuf/stubs/bytestream.h>
#include <google/protobuf/stubs/hash.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace io {
@@ -76,7 +78,7 @@ class ObjectLocationTracker;
// the ProtoWriter class to write raw proto bytes.
//
// It also supports streaming.
-class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
+class PROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
public:
// Options that control ProtoStreamObjectWriter class's behavior.
struct Options {
@@ -91,9 +93,13 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
bool struct_integers_as_strings;
// Not treat unknown fields as an error. If there is an unknown fields,
- // just ignore it and continue to process the rest.
+ // just ignore it and continue to process the rest. Note that this doesn't
+ // apply to unknown enum values.
bool ignore_unknown_fields;
+ // Ignore unknown enum values.
+ bool ignore_unknown_enum_values;
+
// If true, check if enum name in camel case or without underscore matches
// the field name.
bool use_lower_camel_for_enums;
@@ -105,6 +111,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
Options()
: struct_integers_as_strings(false),
ignore_unknown_fields(false),
+ ignore_unknown_enum_values(false),
use_lower_camel_for_enums(false),
ignore_null_value_map_entry(false) {}
@@ -140,7 +147,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
const DataPiece&);
// Handles writing Anys out using nested object writers and the like.
- class LIBPROTOBUF_EXPORT AnyWriter {
+ class PROTOBUF_EXPORT AnyWriter {
public:
explicit AnyWriter(ProtoStreamObjectWriter* parent);
~AnyWriter();
@@ -165,7 +172,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
private:
// Before the "@type" field is encountered, we store all incoming data
// into this Event struct and replay them after we get the "@type" field.
- class LIBPROTOBUF_EXPORT Event {
+ class PROTOBUF_EXPORT Event {
public:
enum Type {
START_OBJECT = 0,
@@ -207,9 +214,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
void DeepCopy();
Type type_;
- string name_;
+ std::string name_;
DataPiece value_;
- string value_storage_;
+ std::string value_storage_;
};
// Handles starting up the any once we have a type.
@@ -226,14 +233,14 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
std::unique_ptr<ProtoStreamObjectWriter> ow_;
// The type_url_ that this Any represents.
- string type_url_;
+ std::string type_url_;
// Whether this any is invalid. This allows us to only report an invalid
// Any message a single time rather than every time we get a nested field.
bool invalid_;
// The output data and wrapping ByteSink.
- string data_;
+ std::string data_;
strings::StringByteSink output_;
// The depth within the Any, so we can track when we're done.
@@ -254,7 +261,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
// Represents an item in a stack of items used to keep state between
// ObjectWrier events.
- class LIBPROTOBUF_EXPORT Item : public BaseElement {
+ class PROTOBUF_EXPORT Item : public BaseElement {
public:
// Indicates the type of item.
enum ItemType {
@@ -306,7 +313,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
// Set of map keys already seen for the type_. Used to validate incoming
// messages so no map key appears more than once.
- std::unique_ptr<std::unordered_set<string> > map_keys_;
+ std::unique_ptr<std::unordered_set<std::string> > map_keys_;
// Conveys whether this Item is a placeholder or not. Placeholder items are
// pushed to stack to account for special types.
@@ -367,7 +374,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
static void InitRendererMap();
static void DeleteRendererMap();
- static TypeRenderer* FindTypeRenderer(const string& type_url);
+ static TypeRenderer* FindTypeRenderer(const std::string& type_url);
// Returns true if the map key for type_ is not duplicated key.
// If map key is duplicated key, this function returns false.
@@ -397,7 +404,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
private:
// Helper functions to create the map and find functions responsible for
// rendering well known types, keyed by type URL.
- static std::unordered_map<string, TypeRenderer>* renderers_;
+ static std::unordered_map<std::string, TypeRenderer>* renderers_;
// Variables for describing the structure of the input tree:
// master_type_: descriptor for the whole protobuf message.
@@ -417,4 +424,6 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTOSTREAM_OBJECTWRITER_H__
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
index e11dce03..66a8f003 100644
--- a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
+++ b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
@@ -921,6 +921,22 @@ TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownListAtPublisher) {
CheckOutput(expected);
}
+TEST_P(ProtoStreamObjectWriterTest,
+ IgnoreUnknownFieldsDontIgnoreUnknownEnumValues) {
+ ResetTypeInfo(Proto3Message::descriptor());
+
+ Proto3Message expected;
+ EXPECT_CALL(
+ listener_,
+ InvalidValue(_, StringPiece("TYPE_ENUM"),
+ StringPiece("\"someunknownvalueyouwillneverknow\"")))
+ .With(Args<0>(HasObjectLocation("enum_value")));
+ ow_->StartObject("")
+ ->RenderString("enumValue", "someunknownvalueyouwillneverknow")
+ ->EndObject();
+ CheckOutput(expected);
+}
+
TEST_P(ProtoStreamObjectWriterTest, AcceptUnknownEnumValue) {
ResetTypeInfo(Proto3Message::descriptor());
diff --git a/src/google/protobuf/util/internal/structured_objectwriter.h b/src/google/protobuf/util/internal/structured_objectwriter.h
index 3551abc8..bccea718 100644
--- a/src/google/protobuf/util/internal/structured_objectwriter.h
+++ b/src/google/protobuf/util/internal/structured_objectwriter.h
@@ -37,6 +37,8 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/util/internal/object_writer.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
@@ -53,7 +55,7 @@ namespace converter {
// StructuredObjectWriter and its use.
//
// Derived classes could be thread-unsafe.
-class LIBPROTOBUF_EXPORT StructuredObjectWriter : public ObjectWriter {
+class PROTOBUF_EXPORT StructuredObjectWriter : public ObjectWriter {
public:
virtual ~StructuredObjectWriter() {}
@@ -63,7 +65,7 @@ class LIBPROTOBUF_EXPORT StructuredObjectWriter : public ObjectWriter {
// StructuredObjectWriter behaves as a visitor. BaseElement represents a node
// in the input tree. Implementation of StructuredObjectWriter should also
// extend BaseElement to keep track of the location in the input tree.
- class LIBPROTOBUF_EXPORT BaseElement {
+ class PROTOBUF_EXPORT BaseElement {
public:
// Takes ownership of the parent Element.
explicit BaseElement(BaseElement* parent)
@@ -112,4 +114,6 @@ class LIBPROTOBUF_EXPORT StructuredObjectWriter : public ObjectWriter {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_STRUCTURED_OBJECTWRITER_H__
diff --git a/src/google/protobuf/util/internal/type_info.h b/src/google/protobuf/util/internal/type_info.h
index 38d5a3bc..b933b77a 100644
--- a/src/google/protobuf/util/internal/type_info.h
+++ b/src/google/protobuf/util/internal/type_info.h
@@ -38,13 +38,15 @@
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/statusor.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace util {
namespace converter {
// Internal helper class for type resolving. Note that this class is not
// thread-safe and should only be accessed in one thread.
-class LIBPROTOBUF_EXPORT TypeInfo {
+class PROTOBUF_EXPORT TypeInfo {
public:
TypeInfo() {}
virtual ~TypeInfo() {}
@@ -89,4 +91,6 @@ class LIBPROTOBUF_EXPORT TypeInfo {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_TYPE_INFO_H__
diff --git a/src/google/protobuf/util/internal/type_info_test_helper.h b/src/google/protobuf/util/internal/type_info_test_helper.h
index f1eac346..3cafbceb 100644
--- a/src/google/protobuf/util/internal/type_info_test_helper.h
+++ b/src/google/protobuf/util/internal/type_info_test_helper.h
@@ -72,13 +72,13 @@ class TypeInfoTestHelper {
TypeInfo* GetTypeInfo();
ProtoStreamObjectSource* NewProtoSource(io::CodedInputStream* coded_input,
- const string& type_url);
+ const std::string& type_url);
ProtoStreamObjectWriter* NewProtoWriter(
- const string& type_url, strings::ByteSink* output,
+ const std::string& type_url, strings::ByteSink* output,
ErrorListener* listener, const ProtoStreamObjectWriter::Options& options);
- DefaultValueObjectWriter* NewDefaultValueWriter(const string& type_url,
+ DefaultValueObjectWriter* NewDefaultValueWriter(const std::string& type_url,
ObjectWriter* writer);
private:
diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc
index 4a3f2ed0..7c7e3f1c 100644
--- a/src/google/protobuf/util/internal/utility.cc
+++ b/src/google/protobuf/util/internal/utility.cc
@@ -327,7 +327,7 @@ string ToSnakeCase(StringPiece input) {
}
std::set<string>* well_known_types_ = NULL;
-GOOGLE_PROTOBUF_NAMESPACE_ID::internal::once_flag well_known_types_init_;
+PROTOBUF_NAMESPACE_ID::internal::once_flag well_known_types_init_;
const char* well_known_types_name_array_[] = {
"google.protobuf.Timestamp", "google.protobuf.Duration",
"google.protobuf.DoubleValue", "google.protobuf.FloatValue",
@@ -347,8 +347,8 @@ void InitWellKnownTypes() {
}
bool IsWellKnownType(const string& type_name) {
- GOOGLE_PROTOBUF_NAMESPACE_ID::internal::call_once(well_known_types_init_,
- InitWellKnownTypes);
+ PROTOBUF_NAMESPACE_ID::internal::call_once(well_known_types_init_,
+ InitWellKnownTypes);
return ContainsKey(*well_known_types_, type_name);
}
diff --git a/src/google/protobuf/util/internal/utility.h b/src/google/protobuf/util/internal/utility.h
index 816987ae..6fe82959 100644
--- a/src/google/protobuf/util/internal/utility.h
+++ b/src/google/protobuf/util/internal/utility.h
@@ -44,6 +44,8 @@
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/statusor.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
class Method;
@@ -68,46 +70,47 @@ static const int64 kTypeUrlSize = 19;
// Finds the tech option identified by option_name. Parses the boolean value and
// returns it.
// When the option with the given name is not found, default_value is returned.
-LIBPROTOBUF_EXPORT bool GetBoolOptionOrDefault(
+PROTOBUF_EXPORT bool GetBoolOptionOrDefault(
const RepeatedPtrField<google::protobuf::Option>& options,
- const string& option_name, bool default_value);
+ const std::string& option_name, bool default_value);
// Returns int64 option value. If the option isn't found, returns the
// default_value.
-LIBPROTOBUF_EXPORT int64 GetInt64OptionOrDefault(
+PROTOBUF_EXPORT int64 GetInt64OptionOrDefault(
const RepeatedPtrField<google::protobuf::Option>& options,
- const string& option_name, int64 default_value);
+ const std::string& option_name, int64 default_value);
// Returns double option value. If the option isn't found, returns the
// default_value.
-LIBPROTOBUF_EXPORT double GetDoubleOptionOrDefault(
+PROTOBUF_EXPORT double GetDoubleOptionOrDefault(
const RepeatedPtrField<google::protobuf::Option>& options,
- const string& option_name, double default_value);
+ const std::string& option_name, double default_value);
// Returns string option value. If the option isn't found, returns the
// default_value.
-LIBPROTOBUF_EXPORT string GetStringOptionOrDefault(
+PROTOBUF_EXPORT std::string GetStringOptionOrDefault(
const RepeatedPtrField<google::protobuf::Option>& options,
- const string& option_name, const string& default_value);
+ const std::string& option_name, const std::string& default_value);
// Returns a boolean value contained in Any type.
// TODO(skarvaje): Make these utilities dealing with Any types more generic,
// add more error checking and move to a more public/sharable location so others
// can use.
-LIBPROTOBUF_EXPORT bool GetBoolFromAny(const google::protobuf::Any& any);
+PROTOBUF_EXPORT bool GetBoolFromAny(const google::protobuf::Any& any);
// Returns int64 value contained in Any type.
-LIBPROTOBUF_EXPORT int64 GetInt64FromAny(const google::protobuf::Any& any);
+PROTOBUF_EXPORT int64 GetInt64FromAny(const google::protobuf::Any& any);
// Returns double value contained in Any type.
-LIBPROTOBUF_EXPORT double GetDoubleFromAny(const google::protobuf::Any& any);
+PROTOBUF_EXPORT double GetDoubleFromAny(const google::protobuf::Any& any);
// Returns string value contained in Any type.
-LIBPROTOBUF_EXPORT string GetStringFromAny(const google::protobuf::Any& any);
+PROTOBUF_EXPORT std::string GetStringFromAny(const google::protobuf::Any& any);
// Returns the type string without the url prefix. e.g.: If the passed type is
// 'type.googleapis.com/tech.type.Bool', the returned value is 'tech.type.Bool'.
-LIBPROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl(StringPiece type_url);
+PROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl(
+ StringPiece type_url);
// Returns the simple_type with the base type url (kTypeServiceBaseUrl)
// prefixed.
@@ -115,13 +118,13 @@ LIBPROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl(StringPiece type_url);
// E.g:
// GetFullTypeWithUrl("google.protobuf.Timestamp") returns the string
// "type.googleapis.com/google.protobuf.Timestamp".
-LIBPROTOBUF_EXPORT const string GetFullTypeWithUrl(StringPiece simple_type);
+PROTOBUF_EXPORT const std::string GetFullTypeWithUrl(StringPiece simple_type);
// Finds and returns option identified by name and option_name within the
// provided map. Returns nullptr if none found.
const google::protobuf::Option* FindOptionOrNull(
const RepeatedPtrField<google::protobuf::Option>& options,
- const string& option_name);
+ const std::string& option_name);
// Finds and returns the field identified by field_name in the passed tech Type
// object. Returns nullptr if none found.
@@ -155,51 +158,51 @@ const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull(
const google::protobuf::Enum* enum_type, StringPiece enum_name);
// Converts input to camel-case and returns it.
-LIBPROTOBUF_EXPORT string ToCamelCase(const StringPiece input);
+PROTOBUF_EXPORT std::string ToCamelCase(const StringPiece input);
// Converts enum name string to camel-case and returns it.
-string EnumValueNameToLowerCamelCase(const StringPiece input);
+std::string EnumValueNameToLowerCamelCase(const StringPiece input);
// Converts input to snake_case and returns it.
-LIBPROTOBUF_EXPORT string ToSnakeCase(StringPiece input);
+PROTOBUF_EXPORT std::string ToSnakeCase(StringPiece input);
// Returns true if type_name represents a well-known type.
-LIBPROTOBUF_EXPORT bool IsWellKnownType(const string& type_name);
+PROTOBUF_EXPORT bool IsWellKnownType(const std::string& type_name);
// Returns true if 'bool_string' represents a valid boolean value. Only "true",
// "false", "0" and "1" are allowed.
-LIBPROTOBUF_EXPORT bool IsValidBoolString(const string& bool_string);
+PROTOBUF_EXPORT bool IsValidBoolString(const std::string& bool_string);
// Returns true if "field" is a protobuf map field based on its type.
-LIBPROTOBUF_EXPORT bool IsMap(const google::protobuf::Field& field,
- const google::protobuf::Type& type);
+PROTOBUF_EXPORT bool IsMap(const google::protobuf::Field& field,
+ const google::protobuf::Type& type);
// Returns true if the given type has special MessageSet wire format.
bool IsMessageSetWireFormat(const google::protobuf::Type& type);
// Infinity/NaN-aware conversion to string.
-LIBPROTOBUF_EXPORT string DoubleAsString(double value);
-LIBPROTOBUF_EXPORT string FloatAsString(float value);
+PROTOBUF_EXPORT std::string DoubleAsString(double value);
+PROTOBUF_EXPORT std::string FloatAsString(float value);
// Convert from int32, int64, uint32, uint64, double or float to string.
template <typename T>
-string ValueAsString(T value) {
+std::string ValueAsString(T value) {
return SimpleItoa(value);
}
template <>
-inline string ValueAsString(float value) {
+inline std::string ValueAsString(float value) {
return FloatAsString(value);
}
template <>
-inline string ValueAsString(double value) {
+inline std::string ValueAsString(double value) {
return DoubleAsString(value);
}
// Converts a string to float. Unlike safe_strtof, conversion will fail if the
// value fits into double but not float (e.g., DBL_MAX).
-LIBPROTOBUF_EXPORT bool SafeStrToFloat(StringPiece str, float* value);
+PROTOBUF_EXPORT bool SafeStrToFloat(StringPiece str, float* value);
// Returns whether a StringPiece begins with the provided prefix.
bool StringStartsWith(StringPiece text, StringPiece prefix);
@@ -211,4 +214,6 @@ bool StringEndsWith(StringPiece text, StringPiece suffix);
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_UTILITY_H__
diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc
index bf82fa7c..19e20a47 100644
--- a/src/google/protobuf/util/json_util.cc
+++ b/src/google/protobuf/util/json_util.cc
@@ -184,6 +184,8 @@ util::Status JsonToBinaryStream(TypeResolver* resolver,
StatusErrorListener listener;
converter::ProtoStreamObjectWriter::Options proto_writer_options;
proto_writer_options.ignore_unknown_fields = options.ignore_unknown_fields;
+ proto_writer_options.ignore_unknown_enum_values =
+ options.ignore_unknown_fields;
converter::ProtoStreamObjectWriter proto_writer(resolver, type, &sink,
&listener,
proto_writer_options);
@@ -215,8 +217,7 @@ util::Status JsonToBinaryString(TypeResolver* resolver,
namespace {
const char* kTypeUrlPrefix = "type.googleapis.com";
TypeResolver* generated_type_resolver_ = NULL;
-GOOGLE_PROTOBUF_NAMESPACE_ID::internal::once_flag
- generated_type_resolver_init_;
+PROTOBUF_NAMESPACE_ID::internal::once_flag generated_type_resolver_init_;
string GetTypeUrl(const Message& message) {
return string(kTypeUrlPrefix) + "/" + message.GetDescriptor()->full_name();
@@ -231,8 +232,8 @@ void InitGeneratedTypeResolver() {
}
TypeResolver* GetGeneratedTypeResolver() {
- GOOGLE_PROTOBUF_NAMESPACE_ID::internal::call_once(
- generated_type_resolver_init_, InitGeneratedTypeResolver);
+ PROTOBUF_NAMESPACE_ID::internal::call_once(generated_type_resolver_init_,
+ InitGeneratedTypeResolver);
return generated_type_resolver_;
}
} // namespace
diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h
index 96809a4f..f62e7f0f 100644
--- a/src/google/protobuf/util/json_util.h
+++ b/src/google/protobuf/util/json_util.h
@@ -38,6 +38,8 @@
#include <google/protobuf/stubs/bytestream.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
namespace io {
@@ -81,20 +83,20 @@ typedef JsonPrintOptions JsonOptions;
// Converts from protobuf message to JSON and appends it to |output|. This is a
// simple wrapper of BinaryToJsonString(). It will use the DescriptorPool of the
// passed-in message to resolve Any types.
-LIBPROTOBUF_EXPORT util::Status MessageToJsonString(const Message& message,
- string* output,
- const JsonOptions& options);
+PROTOBUF_EXPORT util::Status MessageToJsonString(const Message& message,
+ std::string* output,
+ const JsonOptions& options);
inline util::Status MessageToJsonString(const Message& message,
- string* output) {
+ std::string* output) {
return MessageToJsonString(message, output, JsonOptions());
}
// Converts from JSON to protobuf message. This is a simple wrapper of
// JsonStringToBinary(). It will use the DescriptorPool of the passed-in
// message to resolve Any types.
-LIBPROTOBUF_EXPORT util::Status JsonStringToMessage(StringPiece input, Message* message,
- const JsonParseOptions& options);
+PROTOBUF_EXPORT util::Status JsonStringToMessage(
+ StringPiece input, Message* message, const JsonParseOptions& options);
inline util::Status JsonStringToMessage(StringPiece input,
Message* message) {
@@ -107,32 +109,27 @@ inline util::Status JsonStringToMessage(StringPiece input,
// 2. input is not valid protobuf wire format, or conflicts with the type
// information returned by TypeResolver.
// Note that unknown fields will be discarded silently.
-LIBPROTOBUF_EXPORT util::Status BinaryToJsonStream(
- TypeResolver* resolver,
- const string& type_url,
+PROTOBUF_EXPORT util::Status BinaryToJsonStream(
+ TypeResolver* resolver, const std::string& type_url,
io::ZeroCopyInputStream* binary_input,
- io::ZeroCopyOutputStream* json_output,
- const JsonPrintOptions& options);
+ io::ZeroCopyOutputStream* json_output, const JsonPrintOptions& options);
inline util::Status BinaryToJsonStream(
- TypeResolver* resolver, const string& type_url,
+ TypeResolver* resolver, const std::string& type_url,
io::ZeroCopyInputStream* binary_input,
io::ZeroCopyOutputStream* json_output) {
return BinaryToJsonStream(resolver, type_url, binary_input, json_output,
JsonPrintOptions());
}
-LIBPROTOBUF_EXPORT util::Status BinaryToJsonString(
- TypeResolver* resolver,
- const string& type_url,
- const string& binary_input,
- string* json_output,
- const JsonPrintOptions& options);
+PROTOBUF_EXPORT util::Status BinaryToJsonString(
+ TypeResolver* resolver, const std::string& type_url, const std::string& binary_input,
+ std::string* json_output, const JsonPrintOptions& options);
inline util::Status BinaryToJsonString(TypeResolver* resolver,
- const string& type_url,
- const string& binary_input,
- string* json_output) {
+ const std::string& type_url,
+ const std::string& binary_input,
+ std::string* json_output) {
return BinaryToJsonString(resolver, type_url, binary_input, json_output,
JsonPrintOptions());
}
@@ -142,39 +139,36 @@ inline util::Status BinaryToJsonString(TypeResolver* resolver,
// 1. TypeResolver fails to resolve a type.
// 2. input is not valid JSON format, or conflicts with the type
// information returned by TypeResolver.
-LIBPROTOBUF_EXPORT util::Status JsonToBinaryStream(
- TypeResolver* resolver,
- const string& type_url,
+PROTOBUF_EXPORT util::Status JsonToBinaryStream(
+ TypeResolver* resolver, const std::string& type_url,
io::ZeroCopyInputStream* json_input,
- io::ZeroCopyOutputStream* binary_output,
- const JsonParseOptions& options);
+ io::ZeroCopyOutputStream* binary_output, const JsonParseOptions& options);
inline util::Status JsonToBinaryStream(
TypeResolver* resolver,
- const string& type_url,
+ const std::string& type_url,
io::ZeroCopyInputStream* json_input,
io::ZeroCopyOutputStream* binary_output) {
return JsonToBinaryStream(resolver, type_url, json_input, binary_output,
JsonParseOptions());
}
-LIBPROTOBUF_EXPORT util::Status JsonToBinaryString(TypeResolver* resolver,
- const string& type_url,
- StringPiece json_input,
- string* binary_output,
- const JsonParseOptions& options);
+PROTOBUF_EXPORT util::Status JsonToBinaryString(
+ TypeResolver* resolver, const std::string& type_url,
+ StringPiece json_input, std::string* binary_output,
+ const JsonParseOptions& options);
inline util::Status JsonToBinaryString(TypeResolver* resolver,
- const string& type_url,
+ const std::string& type_url,
StringPiece json_input,
- string* binary_output) {
+ std::string* binary_output) {
return JsonToBinaryString(resolver, type_url, json_input, binary_output,
JsonParseOptions());
}
namespace internal {
// Internal helper class. Put in the header so we can write unit-tests for it.
-class LIBPROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink {
+class PROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink {
public:
explicit ZeroCopyStreamByteSink(io::ZeroCopyOutputStream* stream)
: stream_(stream), buffer_(NULL), buffer_size_(0) {}
@@ -195,4 +189,6 @@ class LIBPROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__
diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h
index 0c2174bf..9419267e 100644
--- a/src/google/protobuf/util/message_differencer.h
+++ b/src/google/protobuf/util/message_differencer.h
@@ -51,6 +51,8 @@
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/util/field_comparator.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
@@ -106,7 +108,7 @@ class FieldContext; // declared below MessageDifferencer
// guard it with a lock to use the same MessageDifferencer instance from
// multiple threads. Note that it's fine to call static comparison methods
// (like MessageDifferencer::Equals) concurrently.
-class LIBPROTOBUF_EXPORT MessageDifferencer {
+class PROTOBUF_EXPORT MessageDifferencer {
public:
// Determines whether the supplied messages are equal. Equality is defined as
// all fields within the two messages being set to the same value. Primitive
@@ -212,7 +214,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// FieldDescriptors. The first will be the field of the embedded message
// itself and the second will be the actual field in the embedded message
// that was added/deleted/modified.
- class LIBPROTOBUF_EXPORT Reporter {
+ class PROTOBUF_EXPORT Reporter {
public:
Reporter();
virtual ~Reporter();
@@ -290,7 +292,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// MapKeyComparator is used to determine if two elements have the same key
// when comparing elements of a repeated field as a map.
- class LIBPROTOBUF_EXPORT MapKeyComparator {
+ class PROTOBUF_EXPORT MapKeyComparator {
public:
MapKeyComparator();
virtual ~MapKeyComparator();
@@ -313,7 +315,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// field IsIgnored is called on each added IgnoreCriteria until one returns
// true or all return false.
// IsIgnored is called for fields where at least one side has a value.
- class LIBPROTOBUF_EXPORT IgnoreCriteria {
+ class PROTOBUF_EXPORT IgnoreCriteria {
public:
IgnoreCriteria();
virtual ~IgnoreCriteria();
@@ -579,7 +581,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// Automatically creates a reporter that will output the differences
// found (if any) to the specified output string pointer. Note that this
// method must be called before Compare.
- void ReportDifferencesToString(string* output);
+ void ReportDifferencesToString(std::string* output);
// Tells the MessageDifferencer to report differences via the specified
// reporter. Note that this method must be called before Compare for
@@ -599,7 +601,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// complete until after you destroy the reporter. For example, if you use a
// StreamReporter to write to a StringOutputStream, the target string may
// contain uninitialized data until the reporter is destroyed.
- class LIBPROTOBUF_EXPORT StreamReporter : public Reporter {
+ class PROTOBUF_EXPORT StreamReporter : public Reporter {
public:
explicit StreamReporter(io::ZeroCopyOutputStream* output);
explicit StreamReporter(io::Printer* printer); // delimiter '$'
@@ -659,7 +661,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
virtual void PrintUnknownFieldValue(const UnknownField* unknown_field);
// Just print a string
- void Print(const string& str);
+ void Print(const std::string& str);
private:
io::Printer* printer_;
@@ -679,7 +681,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
class MultipleFieldsMapKeyComparator;
// A MapKeyComparator for use with map_entries.
- class LIBPROTOBUF_EXPORT MapEntryKeyComparator : public MapKeyComparator {
+ class PROTOBUF_EXPORT MapEntryKeyComparator : public MapKeyComparator {
public:
explicit MapEntryKeyComparator(MessageDifferencer* message_differencer);
bool IsMatch(
@@ -863,7 +865,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
bool report_moves_;
bool report_ignores_;
- string* output_string_;
+ std::string* output_string_;
std::unique_ptr<DynamicMessageFactory> dynamic_message_factory_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageDifferencer);
@@ -871,7 +873,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// This class provides extra information to the FieldComparator::Compare
// function.
-class LIBPROTOBUF_EXPORT FieldContext {
+class PROTOBUF_EXPORT FieldContext {
public:
explicit FieldContext(
std::vector<MessageDifferencer::SpecificField>* parent_fields)
@@ -889,4 +891,6 @@ class LIBPROTOBUF_EXPORT FieldContext {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_MESSAGE_DIFFERENCER_H__
diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc
index 1f50ea21..848290b1 100644
--- a/src/google/protobuf/util/message_differencer_unittest.cc
+++ b/src/google/protobuf/util/message_differencer_unittest.cc
@@ -35,6 +35,7 @@
// TODO(ksroka): Move some of these tests to field_comparator_test.cc.
#include <algorithm>
+#include <random>
#include <string>
#include <vector>
@@ -906,8 +907,9 @@ TEST(MessageDifferencerTest, SpecifiedFieldsEqualityAllShuffledTest) {
msg1.GetReflection()->ListFields(msg1, &fields1);
msg2.GetReflection()->ListFields(msg2, &fields2);
- std::random_shuffle(fields1.begin(), fields1.end());
- std::random_shuffle(fields2.begin(), fields2.end());
+ std::default_random_engine rng;
+ std::shuffle(fields1.begin(), fields1.end(), rng);
+ std::shuffle(fields2.begin(), fields2.end(), rng);
util::MessageDifferencer differencer;
EXPECT_TRUE(differencer.CompareWithFields(msg1, msg2, fields1, fields2));
diff --git a/src/google/protobuf/util/time_util.cc b/src/google/protobuf/util/time_util.cc
index 9321a23a..a7cba004 100644
--- a/src/google/protobuf/util/time_util.cc
+++ b/src/google/protobuf/util/time_util.cc
@@ -375,8 +375,8 @@ timeval TimeUtil::DurationToTimeval(const Duration& value) {
namespace google {
namespace protobuf {
namespace {
-using ::GOOGLE_PROTOBUF_NAMESPACE_ID::util::CreateNormalized;
-using ::GOOGLE_PROTOBUF_NAMESPACE_ID::util::kNanosPerSecond;
+using ::PROTOBUF_NAMESPACE_ID::util::CreateNormalized;
+using ::PROTOBUF_NAMESPACE_ID::util::kNanosPerSecond;
// Convert a Duration to uint128.
void ToUint128(const Duration& value, uint128* result, bool* negative) {
diff --git a/src/google/protobuf/util/time_util.h b/src/google/protobuf/util/time_util.h
index b0e19173..bbda5380 100644
--- a/src/google/protobuf/util/time_util.h
+++ b/src/google/protobuf/util/time_util.h
@@ -52,7 +52,7 @@ namespace protobuf {
namespace util {
// Utility functions for Timestamp and Duration.
-class LIBPROTOBUF_EXPORT TimeUtil {
+class PROTOBUF_EXPORT TimeUtil {
typedef google::protobuf::Timestamp Timestamp;
typedef google::protobuf::Duration Duration;
@@ -81,8 +81,8 @@ class LIBPROTOBUF_EXPORT TimeUtil {
//
// Example of accepted format:
// "1972-01-01T10:00:20.021-05:00"
- static string ToString(const Timestamp& timestamp);
- static bool FromString(const string& value, Timestamp* timestamp);
+ static std::string ToString(const Timestamp& timestamp);
+ static bool FromString(const std::string& value, Timestamp* timestamp);
// Converts Duration to/from string format. The string format will contains
// 3, 6, or 9 fractional digits depending on the precision required to
@@ -90,8 +90,8 @@ class LIBPROTOBUF_EXPORT TimeUtil {
// "1s", "1.010s", "1.000000100s", "-3.100s"
// The range that can be represented by Duration is from -315,576,000,000
// to +315,576,000,000 inclusive (in seconds).
- static string ToString(const Duration& duration);
- static bool FromString(const string& value, Duration* timestamp);
+ static std::string ToString(const Duration& duration);
+ static bool FromString(const std::string& value, Duration* timestamp);
#ifdef GetCurrentTime
#undef GetCurrentTime // Visual Studio has macro GetCurrentTime
@@ -165,12 +165,14 @@ namespace protobuf {
// Overloaded operators for Duration.
//
// Assignment operators.
-LIBPROTOBUF_EXPORT Duration& operator+=(Duration& d1, const Duration& d2); // NOLINT
-LIBPROTOBUF_EXPORT Duration& operator-=(Duration& d1, const Duration& d2); // NOLINT
-LIBPROTOBUF_EXPORT Duration& operator*=(Duration& d, int64 r); // NOLINT
-LIBPROTOBUF_EXPORT Duration& operator*=(Duration& d, double r); // NOLINT
-LIBPROTOBUF_EXPORT Duration& operator/=(Duration& d, int64 r); // NOLINT
-LIBPROTOBUF_EXPORT Duration& operator/=(Duration& d, double r); // NOLINT
+PROTOBUF_EXPORT Duration& operator+=(Duration& d1,
+ const Duration& d2); // NOLINT
+PROTOBUF_EXPORT Duration& operator-=(Duration& d1,
+ const Duration& d2); // NOLINT
+PROTOBUF_EXPORT Duration& operator*=(Duration& d, int64 r); // NOLINT
+PROTOBUF_EXPORT Duration& operator*=(Duration& d, double r); // NOLINT
+PROTOBUF_EXPORT Duration& operator/=(Duration& d, int64 r); // NOLINT
+PROTOBUF_EXPORT Duration& operator/=(Duration& d, double r); // NOLINT
// Overload for other integer types.
template <typename T>
Duration& operator*=(Duration& d, T r) { // NOLINT
@@ -182,7 +184,8 @@ Duration& operator/=(Duration& d, T r) { // NOLINT
int64 x = r;
return d /= x;
}
-LIBPROTOBUF_EXPORT Duration& operator%=(Duration& d1, const Duration& d2); // NOLINT
+PROTOBUF_EXPORT Duration& operator%=(Duration& d1,
+ const Duration& d2); // NOLINT
// Relational operators.
inline bool operator<(const Duration& d1, const Duration& d2) {
if (d1.seconds() == d2.seconds()) {
@@ -233,7 +236,7 @@ template<typename T>
inline Duration operator/(Duration d, T r) {
return d /= r;
}
-LIBPROTOBUF_EXPORT int64 operator/(const Duration& d1, const Duration& d2);
+PROTOBUF_EXPORT int64 operator/(const Duration& d1, const Duration& d2);
inline Duration operator%(const Duration& d1, const Duration& d2) {
Duration result = d1;
@@ -241,15 +244,17 @@ inline Duration operator%(const Duration& d1, const Duration& d2) {
}
inline std::ostream& operator<<(std::ostream& out, const Duration& d) {
- out << ::GOOGLE_PROTOBUF_NAMESPACE_ID::util::TimeUtil::ToString(d);
+ out << ::PROTOBUF_NAMESPACE_ID::util::TimeUtil::ToString(d);
return out;
}
// Overloaded operators for Timestamp
//
// Assignement operators.
-LIBPROTOBUF_EXPORT Timestamp& operator+=(Timestamp& t, const Duration& d); // NOLINT
-LIBPROTOBUF_EXPORT Timestamp& operator-=(Timestamp& t, const Duration& d); // NOLINT
+PROTOBUF_EXPORT Timestamp& operator+=(Timestamp& t,
+ const Duration& d); // NOLINT
+PROTOBUF_EXPORT Timestamp& operator-=(Timestamp& t,
+ const Duration& d); // NOLINT
// Relational operators.
inline bool operator<(const Timestamp& t1, const Timestamp& t2) {
if (t1.seconds() == t2.seconds()) {
@@ -285,10 +290,10 @@ inline Timestamp operator-(const Timestamp& t, const Duration& d) {
Timestamp result = t;
return result -= d;
}
-LIBPROTOBUF_EXPORT Duration operator-(const Timestamp& t1, const Timestamp& t2);
+PROTOBUF_EXPORT Duration operator-(const Timestamp& t1, const Timestamp& t2);
inline std::ostream& operator<<(std::ostream& out, const Timestamp& t) {
- out << ::GOOGLE_PROTOBUF_NAMESPACE_ID::util::TimeUtil::ToString(t);
+ out << ::PROTOBUF_NAMESPACE_ID::util::TimeUtil::ToString(t);
return out;
}
diff --git a/src/google/protobuf/util/type_resolver.h b/src/google/protobuf/util/type_resolver.h
index 9c9a7444..bc5f0960 100644
--- a/src/google/protobuf/util/type_resolver.h
+++ b/src/google/protobuf/util/type_resolver.h
@@ -38,6 +38,8 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/status.h>
+#include <google/protobuf/port_def.inc>
+
namespace google {
namespace protobuf {
class Type;
@@ -53,17 +55,17 @@ namespace util {
// Abstract interface for a type resovler.
//
// Implementations of this interface must be thread-safe.
-class LIBPROTOBUF_EXPORT TypeResolver {
+class PROTOBUF_EXPORT TypeResolver {
public:
TypeResolver() {}
virtual ~TypeResolver() {}
// Resolves a type url for a message type.
virtual util::Status ResolveMessageType(
- const string& type_url, google::protobuf::Type* message_type) = 0;
+ const std::string& type_url, google::protobuf::Type* message_type) = 0;
// Resolves a type url for an enum type.
- virtual util::Status ResolveEnumType(const string& type_url,
+ virtual util::Status ResolveEnumType(const std::string& type_url,
google::protobuf::Enum* enum_type) = 0;
private:
@@ -74,4 +76,6 @@ class LIBPROTOBUF_EXPORT TypeResolver {
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_H__
diff --git a/src/google/protobuf/util/type_resolver_util.h b/src/google/protobuf/util/type_resolver_util.h
index c512e6fd..fa912b60 100644
--- a/src/google/protobuf/util/type_resolver_util.h
+++ b/src/google/protobuf/util/type_resolver_util.h
@@ -35,20 +35,23 @@
#include <string>
-#include <google/protobuf/stubs/common.h>
namespace google {
namespace protobuf {
class DescriptorPool;
namespace util {
class TypeResolver;
+#include <google/protobuf/port_def.inc>
+
// Creates a TypeResolver that serves type information in the given descriptor
// pool. Caller takes ownership of the returned TypeResolver.
-LIBPROTOBUF_EXPORT TypeResolver* NewTypeResolverForDescriptorPool(
- const string& url_prefix, const DescriptorPool* pool);
+PROTOBUF_EXPORT TypeResolver* NewTypeResolverForDescriptorPool(
+ const std::string& url_prefix, const DescriptorPool* pool);
} // namespace util
} // namespace protobuf
} // namespace google
+#include <google/protobuf/port_undef.inc>
+
#endif // GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_UTIL_H__