aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/util/internal/default_value_objectwriter.h
diff options
context:
space:
mode:
authorGravatar stone4774 <stone4774@qq.com>2018-03-19 15:57:07 +0800
committerGravatar stone4774 <stone4774@qq.com>2018-03-19 15:57:07 +0800
commit773d8c3329d1a28732d9f9c4b21c02e302052e4f (patch)
treeed014e4978d3ea968d2a1861707cdc87d9e09f4a /src/google/protobuf/util/internal/default_value_objectwriter.h
parenta48d58df9643781947da57bdc13a23ac8d868346 (diff)
Fix bug: whether always_print_enums_as_ints is true or false, it always print the default value of enums as strings
Diffstat (limited to 'src/google/protobuf/util/internal/default_value_objectwriter.h')
-rw-r--r--src/google/protobuf/util/internal/default_value_objectwriter.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h
index 09c6d23f..59f508cd 100644
--- a/src/google/protobuf/util/internal/default_value_objectwriter.h
+++ b/src/google/protobuf/util/internal/default_value_objectwriter.h
@@ -131,6 +131,12 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
preserve_proto_field_names_ = value;
}
+ // If set to true, enums are rendered as ints from output when default values
+ // are written.
+ void set_print_enums_as_ints(bool value) {
+ use_ints_for_enums_ = value;
+ }
+
protected:
enum NodeKind {
PRIMITIVE = 0,
@@ -150,7 +156,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
Node(const string& name, const google::protobuf::Type* type, NodeKind kind,
const DataPiece& data, bool is_placeholder,
const std::vector<string>& path, bool suppress_empty_list,
- bool preserve_proto_field_names,
+ bool preserve_proto_field_names, bool use_ints_for_enums,
FieldScrubCallBack* field_scrub_callback);
virtual ~Node() {
for (int i = 0; i < children_.size(); ++i) {
@@ -233,6 +239,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// Whether to preserve original proto field names
bool preserve_proto_field_names_;
+ // Whether to always print enums as ints
+ bool use_ints_for_enums_;
+
// Pointer to function for determining whether a field needs to be scrubbed
// or not. This callback is owned by the creator of this node.
FieldScrubCallBack* field_scrub_callback_;
@@ -256,11 +265,12 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
const std::vector<string>& path,
bool suppress_empty_list,
bool preserve_proto_field_names,
+ bool use_ints_for_enums,
FieldScrubCallBack* field_scrub_callback);
// Creates a DataPiece containing the default value of the type of the field.
static DataPiece CreateDefaultDataPieceForField(
- const google::protobuf::Field& field, const TypeInfo* typeinfo);
+ const google::protobuf::Field& field, const TypeInfo* typeinfo, bool use_ints_for_enums);
protected:
// Returns a pointer to current Node in tree.
@@ -282,7 +292,8 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// there is no default. For proto3, where we cannot specify an explicit
// default, a zero value will always be returned.
static DataPiece FindEnumDefault(const google::protobuf::Field& field,
- const TypeInfo* typeinfo);
+ const TypeInfo* typeinfo,
+ bool use_ints_for_enums);
// Type information for all the types used in the descriptor. Used to find
// google::protobuf::Type of nested messages/enums.
@@ -307,6 +318,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// Whether to preserve original proto field names
bool preserve_proto_field_names_;
+ // Whether to always print enums as ints
+ bool use_ints_for_enums_;
+
// Unique Pointer to function for determining whether a field needs to be
// scrubbed or not.
FieldScrubCallBackPtr field_scrub_callback_;