diff options
Diffstat (limited to 'src/google/protobuf/util/internal/protostream_objectwriter.h')
-rw-r--r-- | src/google/protobuf/util/internal/protostream_objectwriter.h | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.h b/src/google/protobuf/util/internal/protostream_objectwriter.h index d9bb432e..fe8170d1 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.h +++ b/src/google/protobuf/util/internal/protostream_objectwriter.h @@ -32,8 +32,9 @@ #define GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTOSTREAM_OBJECTWRITER_H__ #include <deque> -#include <google/protobuf/stubs/hash.h> #include <string> +#include <unordered_map> +#include <unordered_set> #include <google/protobuf/stubs/common.h> #include <google/protobuf/io/coded_stream.h> @@ -46,6 +47,9 @@ #include <google/protobuf/util/internal/structured_objectwriter.h> #include <google/protobuf/util/type_resolver.h> #include <google/protobuf/stubs/bytestream.h> +#include <google/protobuf/stubs/hash.h> + +#include <google/protobuf/port_def.inc> namespace google { namespace protobuf { @@ -53,14 +57,16 @@ namespace io { class CodedOutputStream; } // namespace io } // namespace protobuf +} // namespace google - +namespace google { namespace protobuf { class Type; class Field; } // namespace protobuf +} // namespace google - +namespace google { namespace protobuf { namespace util { namespace converter { @@ -72,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 { @@ -87,17 +93,27 @@ 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; + // If true, skips rendering the map entry if map value is null unless the + // value type is google.protobuf.NullType. + bool ignore_null_value_map_entry; + Options() : struct_integers_as_strings(false), ignore_unknown_fields(false), - use_lower_camel_for_enums(false) {} + ignore_unknown_enum_values(false), + use_lower_camel_for_enums(false), + ignore_null_value_map_entry(false) {} // Default instance of Options with all options set to defaults. static const Options& Defaults() { @@ -112,18 +128,18 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { strings::ByteSink* output, ErrorListener* listener, const ProtoStreamObjectWriter::Options& options = ProtoStreamObjectWriter::Options::Defaults()); - virtual ~ProtoStreamObjectWriter() override; + ~ProtoStreamObjectWriter() override; // ObjectWriter methods. - virtual ProtoStreamObjectWriter* StartObject(StringPiece name) override; - virtual ProtoStreamObjectWriter* EndObject() override; - virtual ProtoStreamObjectWriter* StartList(StringPiece name) override; - virtual ProtoStreamObjectWriter* EndList() override; + ProtoStreamObjectWriter* StartObject(StringPiece name) override; + ProtoStreamObjectWriter* EndObject() override; + ProtoStreamObjectWriter* StartList(StringPiece name) override; + ProtoStreamObjectWriter* EndList() override; // Renders a DataPiece 'value' into a field whose wire type is determined // from the given field 'name'. - virtual ProtoStreamObjectWriter* RenderDataPiece(StringPiece name, - const DataPiece& value) override; + ProtoStreamObjectWriter* RenderDataPiece(StringPiece name, + const DataPiece& data) override; protected: // Function that renders a well known type with modified behavior. @@ -131,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(); @@ -156,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, @@ -171,13 +187,11 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { // Constructor for START_OBJECT and START_LIST events. explicit Event(Type type, StringPiece name) - : type_(type), - name_(name.ToString()), - value_(DataPiece::NullData()) {} + : type_(type), name_(name), value_(DataPiece::NullData()) {} // Constructor for RENDER_DATA_PIECE events. explicit Event(StringPiece name, const DataPiece& value) - : type_(RENDER_DATA_PIECE), name_(name.ToString()), value_(value) { + : type_(RENDER_DATA_PIECE), name_(name), value_(value) { DeepCopy(); } @@ -200,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. @@ -219,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. @@ -247,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 { @@ -263,7 +277,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { // Constructor for a field of a message. Item(Item* parent, ItemType item_type, bool is_placeholder, bool is_list); - virtual ~Item() override {} + ~Item() override {} // These functions return true if the element type is corresponding to the // type in function name. @@ -272,7 +286,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { AnyWriter* any() const { return any_.get(); } - virtual Item* parent() const override { + Item* parent() const override { return static_cast<Item*>(BaseElement::parent()); } @@ -299,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<hash_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. @@ -316,6 +330,11 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { const google::protobuf::Type& type, strings::ByteSink* output, ErrorListener* listener); + ProtoStreamObjectWriter(const TypeInfo* typeinfo, + const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener, + const ProtoStreamObjectWriter::Options& options); + // Returns true if the field is a map. inline bool IsMap(const google::protobuf::Field& field); @@ -355,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. @@ -371,8 +390,8 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { // is_placeholder conveys whether the item is a placeholder item or not. // Placeholder items are pushed when adding auxillary types' StartObject or // StartList calls. - void Push(StringPiece name, Item::ItemType item_type, bool is_placeholder, - bool is_list); + void Push(StringPiece name, Item::ItemType item_type, + bool is_placeholder, bool is_list); // Pops items from the stack. All placeholder items are popped until a // non-placeholder item is found. @@ -385,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 hash_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. @@ -403,6 +422,8 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { } // namespace converter } // namespace util } // namespace protobuf - } // namespace google + +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTOSTREAM_OBJECTWRITER_H__ |