Skip to content

Commit

Permalink
protobuf: add unknown field retention to protobuf-lite.
Browse files Browse the repository at this point in the history
BUG=56579
TEST=sync_unit_tests

Review URL: http://codereview.chromium.org/3544012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62331 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
agl@chromium.org committed Oct 12, 2010
1 parent 1bbb76e commit b0ccb8c
Show file tree
Hide file tree
Showing 19 changed files with 589 additions and 622 deletions.
2 changes: 2 additions & 0 deletions third_party/protobuf/protobuf.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
'src/google/protobuf/generated_message_util.h',
'src/google/protobuf/message_lite.h',
'src/google/protobuf/repeated_field.h',
'src/google/protobuf/unknown_field_set.cc',
'src/google/protobuf/unknown_field_set.h',
'src/google/protobuf/wire_format_lite.h',
'src/google/protobuf/wire_format_lite_inl.h',
'src/google/protobuf/io/coded_stream.h',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"#include <google/protobuf/repeated_field.h>\n"
"#include <google/protobuf/extension_set.h>\n");

if (HasUnknownFields(file_)) {
printer->Print(
"#include <google/protobuf/unknown_field_set.h>\n");
}

if (HasDescriptorMethods(file_)) {
printer->Print(
"#include <google/protobuf/generated_message_reflection.h>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ string GlobalShutdownFileName(const string& filename);

// Do message classes in this file keep track of unknown fields?
inline bool HasUnknownFields(const FileDescriptor *file) {
return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
return file->options().optimize_for() != FileOptions::LITE_RUNTIME ||
file->options().retain_unknown_fields();
}

// Does this file have generated parsing, serialization, and other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
" mutable_unknown_fields()));\n");
} else {
printer->Print(
" DO_(_extensions_.ParseField(tag, input, default_instance_));\n");
" DO_(_extensions_.ParseField(tag, input, default_instance_, NULL));\n");
}
printer->Print(
" continue;\n"
Expand All @@ -1393,11 +1393,10 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
// We really don't recognize this tag. Skip it.
if (HasUnknownFields(descriptor_->file())) {
printer->Print(
"DO_(::google::protobuf::internal::WireFormat::SkipField(\n"
" input, tag, mutable_unknown_fields()));\n");
"DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag, mutable_unknown_fields()));\n");
} else {
printer->Print(
"DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));\n");
"DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag, NULL));\n");
}

if (descriptor_->field_count() > 0) {
Expand Down Expand Up @@ -1472,7 +1471,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) {
"classname", classname_);
if (HasUnknownFields(descriptor_->file())) {
printer->Print(
" ::google::protobuf::internal::WireFormat::SerializeUnknownMessageSetItems(\n"
" ::google::protobuf::internal::WireFormatLite::SerializeUnknownMessageSetItems(\n"
" unknown_fields(), output);\n");
}
printer->Print(
Expand Down Expand Up @@ -1505,7 +1504,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) {
"classname", classname_);
if (HasUnknownFields(descriptor_->file())) {
printer->Print(
" target = ::google::protobuf::internal::WireFormat::\n"
" target = ::google::protobuf::internal::WireFormatLite::\n"
" SerializeUnknownMessageSetItemsToArray(\n"
" unknown_fields(), target);\n");
}
Expand Down Expand Up @@ -1567,11 +1566,11 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) {
if (to_array) {
printer->Print(
"target = "
"::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(\n"
"::google::protobuf::internal::WireFormatLite::SerializeUnknownFieldsToArray(\n"
" unknown_fields(), target);\n");
} else {
printer->Print(
"::google::protobuf::internal::WireFormat::SerializeUnknownFields(\n"
"::google::protobuf::internal::WireFormatLite::SerializeUnknownFields(\n"
" unknown_fields(), output);\n");
}
printer->Outdent();
Expand All @@ -1591,7 +1590,7 @@ GenerateByteSize(io::Printer* printer) {
"classname", classname_);
if (HasUnknownFields(descriptor_->file())) {
printer->Print(
" total_size += ::google::protobuf::internal::WireFormat::\n"
" total_size += ::google::protobuf::internal::WireFormatLite::\n"
" ComputeUnknownMessageSetItemsSize(unknown_fields());\n");
}
printer->Print(
Expand Down Expand Up @@ -1677,7 +1676,7 @@ GenerateByteSize(io::Printer* printer) {
printer->Indent();
printer->Print(
"total_size +=\n"
" ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(\n"
" ::google::protobuf::internal::WireFormatLite::ComputeUnknownFieldsSize(\n"
" unknown_fields());\n");
printer->Outdent();
printer->Print("}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ string DefaultValue(const FieldDescriptor* field);
// Does this message class keep track of unknown fields?
inline bool HasUnknownFields(const Descriptor* descriptor) {
return descriptor->file()->options().optimize_for() !=
FileOptions::LITE_RUNTIME;
FileOptions::LITE_RUNTIME ||
descriptor->file()->options().retain_unknown_fields();
}

// Does this message class have generated parsing, serialization, and other
Expand Down
27 changes: 12 additions & 15 deletions third_party/protobuf/src/google/protobuf/compiler/plugin.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion third_party/protobuf/src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4014,7 +4014,7 @@ bool DescriptorBuilder::OptionInterpreter::InterpretSingleOption(
io::StringOutputStream outstr(
parent_unknown_fields->AddLengthDelimited((*iter)->number()));
io::CodedOutputStream out(&outstr);
internal::WireFormat::SerializeUnknownFields(*unknown_fields, &out);
internal::WireFormatLite::SerializeUnknownFields(*unknown_fields, &out);
GOOGLE_CHECK(!out.HadError())
<< "Unexpected failure while serializing option submessage "
<< debug_msg_name << "\".";
Expand Down
Loading

0 comments on commit b0ccb8c

Please sign in to comment.