|
|
@ -65,6 +65,7 @@ DefaultValueObjectWriter::DefaultValueObjectWriter( |
|
|
|
current_(NULL), |
|
|
|
current_(NULL), |
|
|
|
root_(NULL), |
|
|
|
root_(NULL), |
|
|
|
suppress_empty_list_(false), |
|
|
|
suppress_empty_list_(false), |
|
|
|
|
|
|
|
preserve_proto_field_names_(false), |
|
|
|
field_scrub_callback_(NULL), |
|
|
|
field_scrub_callback_(NULL), |
|
|
|
ow_(ow) {} |
|
|
|
ow_(ow) {} |
|
|
|
|
|
|
|
|
|
|
@ -191,7 +192,8 @@ void DefaultValueObjectWriter::RegisterFieldScrubCallBack( |
|
|
|
DefaultValueObjectWriter::Node::Node( |
|
|
|
DefaultValueObjectWriter::Node::Node( |
|
|
|
const string& name, const google::protobuf::Type* type, NodeKind kind, |
|
|
|
const string& name, const google::protobuf::Type* type, NodeKind kind, |
|
|
|
const DataPiece& data, bool is_placeholder, const std::vector<string>& path, |
|
|
|
const DataPiece& data, bool is_placeholder, const std::vector<string>& path, |
|
|
|
bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback) |
|
|
|
bool suppress_empty_list, bool preserve_proto_field_names, |
|
|
|
|
|
|
|
FieldScrubCallBack* field_scrub_callback) |
|
|
|
: name_(name), |
|
|
|
: name_(name), |
|
|
|
type_(type), |
|
|
|
type_(type), |
|
|
|
kind_(kind), |
|
|
|
kind_(kind), |
|
|
@ -200,6 +202,7 @@ DefaultValueObjectWriter::Node::Node( |
|
|
|
is_placeholder_(is_placeholder), |
|
|
|
is_placeholder_(is_placeholder), |
|
|
|
path_(path), |
|
|
|
path_(path), |
|
|
|
suppress_empty_list_(suppress_empty_list), |
|
|
|
suppress_empty_list_(suppress_empty_list), |
|
|
|
|
|
|
|
preserve_proto_field_names_(preserve_proto_field_names), |
|
|
|
field_scrub_callback_(field_scrub_callback) {} |
|
|
|
field_scrub_callback_(field_scrub_callback) {} |
|
|
|
|
|
|
|
|
|
|
|
DefaultValueObjectWriter::Node* DefaultValueObjectWriter::Node::FindChild( |
|
|
|
DefaultValueObjectWriter::Node* DefaultValueObjectWriter::Node::FindChild( |
|
|
@ -370,10 +373,12 @@ void DefaultValueObjectWriter::Node::PopulateChildren( |
|
|
|
// If the child field is of primitive type, sets its data to the default
|
|
|
|
// If the child field is of primitive type, sets its data to the default
|
|
|
|
// value of its type.
|
|
|
|
// value of its type.
|
|
|
|
google::protobuf::scoped_ptr<Node> child(new Node( |
|
|
|
google::protobuf::scoped_ptr<Node> child(new Node( |
|
|
|
field.json_name(), field_type, kind, |
|
|
|
preserve_proto_field_names_ ? field.name() : field.json_name(), |
|
|
|
|
|
|
|
field_type, kind, |
|
|
|
kind == PRIMITIVE ? CreateDefaultDataPieceForField(field, typeinfo) |
|
|
|
kind == PRIMITIVE ? CreateDefaultDataPieceForField(field, typeinfo) |
|
|
|
: DataPiece::NullData(), |
|
|
|
: DataPiece::NullData(), |
|
|
|
true, path, suppress_empty_list_, field_scrub_callback_)); |
|
|
|
true, path, suppress_empty_list_, preserve_proto_field_names_, |
|
|
|
|
|
|
|
field_scrub_callback_)); |
|
|
|
new_children.push_back(child.release()); |
|
|
|
new_children.push_back(child.release()); |
|
|
|
} |
|
|
|
} |
|
|
|
// Adds all leftover nodes in children_ to the beginning of new_child.
|
|
|
|
// Adds all leftover nodes in children_ to the beginning of new_child.
|
|
|
@ -470,6 +475,7 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( |
|
|
|
std::vector<string> path; |
|
|
|
std::vector<string> path; |
|
|
|
root_.reset(new Node(name.ToString(), &type_, OBJECT, DataPiece::NullData(), |
|
|
|
root_.reset(new Node(name.ToString(), &type_, OBJECT, DataPiece::NullData(), |
|
|
|
false, path, suppress_empty_list_, |
|
|
|
false, path, suppress_empty_list_, |
|
|
|
|
|
|
|
preserve_proto_field_names_, |
|
|
|
field_scrub_callback_.get())); |
|
|
|
field_scrub_callback_.get())); |
|
|
|
root_->PopulateChildren(typeinfo_); |
|
|
|
root_->PopulateChildren(typeinfo_); |
|
|
|
current_ = root_.get(); |
|
|
|
current_ = root_.get(); |
|
|
@ -486,7 +492,8 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( |
|
|
|
: NULL), |
|
|
|
: NULL), |
|
|
|
OBJECT, DataPiece::NullData(), false, |
|
|
|
OBJECT, DataPiece::NullData(), false, |
|
|
|
child == NULL ? current_->path() : child->path(), |
|
|
|
child == NULL ? current_->path() : child->path(), |
|
|
|
suppress_empty_list_, field_scrub_callback_.get())); |
|
|
|
suppress_empty_list_, preserve_proto_field_names_, |
|
|
|
|
|
|
|
field_scrub_callback_.get())); |
|
|
|
child = node.get(); |
|
|
|
child = node.get(); |
|
|
|
current_->AddChild(node.release()); |
|
|
|
current_->AddChild(node.release()); |
|
|
|
} |
|
|
|
} |
|
|
@ -518,6 +525,7 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( |
|
|
|
std::vector<string> path; |
|
|
|
std::vector<string> path; |
|
|
|
root_.reset(new Node(name.ToString(), &type_, LIST, DataPiece::NullData(), |
|
|
|
root_.reset(new Node(name.ToString(), &type_, LIST, DataPiece::NullData(), |
|
|
|
false, path, suppress_empty_list_, |
|
|
|
false, path, suppress_empty_list_, |
|
|
|
|
|
|
|
preserve_proto_field_names_, |
|
|
|
field_scrub_callback_.get())); |
|
|
|
field_scrub_callback_.get())); |
|
|
|
current_ = root_.get(); |
|
|
|
current_ = root_.get(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
@ -528,7 +536,8 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( |
|
|
|
google::protobuf::scoped_ptr<Node> node( |
|
|
|
google::protobuf::scoped_ptr<Node> node( |
|
|
|
new Node(name.ToString(), NULL, LIST, DataPiece::NullData(), false, |
|
|
|
new Node(name.ToString(), NULL, LIST, DataPiece::NullData(), false, |
|
|
|
child == NULL ? current_->path() : child->path(), |
|
|
|
child == NULL ? current_->path() : child->path(), |
|
|
|
suppress_empty_list_, field_scrub_callback_.get())); |
|
|
|
suppress_empty_list_, preserve_proto_field_names_, |
|
|
|
|
|
|
|
field_scrub_callback_.get())); |
|
|
|
child = node.get(); |
|
|
|
child = node.get(); |
|
|
|
current_->AddChild(node.release()); |
|
|
|
current_->AddChild(node.release()); |
|
|
|
} |
|
|
|
} |
|
|
@ -589,7 +598,8 @@ void DefaultValueObjectWriter::RenderDataPiece(StringPiece name, |
|
|
|
google::protobuf::scoped_ptr<Node> node( |
|
|
|
google::protobuf::scoped_ptr<Node> node( |
|
|
|
new Node(name.ToString(), NULL, PRIMITIVE, data, false, |
|
|
|
new Node(name.ToString(), NULL, PRIMITIVE, data, false, |
|
|
|
child == NULL ? current_->path() : child->path(), |
|
|
|
child == NULL ? current_->path() : child->path(), |
|
|
|
suppress_empty_list_, field_scrub_callback_.get())); |
|
|
|
suppress_empty_list_, preserve_proto_field_names_, |
|
|
|
|
|
|
|
field_scrub_callback_.get())); |
|
|
|
current_->AddChild(node.release()); |
|
|
|
current_->AddChild(node.release()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
child->set_data(data); |
|
|
|
child->set_data(data); |
|
|
|