diff options
Diffstat (limited to 'src/google/protobuf/util/internal/proto_writer.h')
-rw-r--r-- | src/google/protobuf/util/internal/proto_writer.h | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h index 28496963..1a8df982 100644 --- a/src/google/protobuf/util/internal/proto_writer.h +++ b/src/google/protobuf/util/internal/proto_writer.h @@ -46,6 +46,9 @@ #include <google/protobuf/util/type_resolver.h> #include <google/protobuf/stubs/bytestream.h> #include <google/protobuf/stubs/hash.h> +#include <google/protobuf/stubs/status.h> + +#include <google/protobuf/port_def.inc> namespace google { namespace protobuf { @@ -53,14 +56,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 { @@ -73,12 +78,12 @@ 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, strings::ByteSink* output, ErrorListener* listener); - virtual ~ProtoWriter(); + ~ProtoWriter() override; // ObjectWriter methods. ProtoWriter* StartObject(StringPiece name) override; @@ -106,11 +111,12 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { ProtoWriter* RenderFloat(StringPiece name, float value) override { return RenderDataPiece(name, DataPiece(value)); } - ProtoWriter* RenderString(StringPiece name, StringPiece value) override { + ProtoWriter* RenderString(StringPiece name, + StringPiece value) override { return RenderDataPiece(name, DataPiece(value, use_strict_base64_decoding())); } - virtual ProtoWriter* RenderBytes(StringPiece name, StringPiece value) { + ProtoWriter* RenderBytes(StringPiece name, StringPiece value) override { return RenderDataPiece( name, DataPiece(value, false, use_strict_base64_decoding())); } @@ -133,7 +139,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { bool done() override { return done_; } // Returns the proto stream object. - google::protobuf::io::CodedOutputStream* stream() { return stream_.get(); } + io::CodedOutputStream* stream() { return stream_.get(); } // Getters and mutators of invalid_depth_. void IncrementInvalidDepth() { ++invalid_depth_; } @@ -148,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, @@ -163,7 +174,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { ProtoElement(ProtoElement* parent, const google::protobuf::Field* field, const google::protobuf::Type& type, bool is_list); - virtual ~ProtoElement() {} + ~ProtoElement() override {} // Called just before the destructor for clean up: // - reports any missing required fields @@ -183,9 +194,9 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { void RegisterField(const google::protobuf::Field* field); // To report location on error messages. - virtual string ToString() const; + std::string ToString() const override; - virtual ProtoElement* parent() const { + ProtoElement* parent() const override { return static_cast<ProtoElement*>(BaseElement::parent()); } @@ -251,7 +262,8 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { // Common code for BeginObject() and BeginList() that does invalid_depth_ // bookkeeping associated with name lookup. - const google::protobuf::Field* BeginNamed(StringPiece name, bool is_list); + const google::protobuf::Field* BeginNamed(StringPiece name, + bool is_list); // Lookup the field in the current element. Looks in the base descriptor // and in any extension. This will report an error if the field cannot be @@ -298,6 +310,13 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { const DataPiece& value); private: + // Writes an ENUM field, including tag, to the stream. + static util::Status WriteEnum(int field_number, const DataPiece& data, + const google::protobuf::Enum* enum_type, + io::CodedOutputStream* stream, + bool use_lower_camel_for_enums, + bool ignore_unknown_values); + // Variables for describing the structure of the input tree: // master_type_: descriptor for the whole protobuf message. // typeinfo_ : the TypeInfo object to lookup types. @@ -309,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_; @@ -330,9 +352,9 @@ 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_; - google::protobuf::io::StringOutputStream adapter_; - std::unique_ptr<google::protobuf::io::CodedOutputStream> stream_; + std::string buffer_; + io::StringOutputStream adapter_; + std::unique_ptr<io::CodedOutputStream> stream_; // Variables for error tracking and reporting: // listener_ : a place to report any errors found. @@ -348,6 +370,8 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { } // namespace converter } // namespace util } // namespace protobuf - } // namespace google + +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTO_WRITER_H__ |