aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Cai <maxtroy@google.com>2014-01-10 13:26:51 +0000
committerMax Cai <maxtroy@google.com>2014-01-10 14:43:32 +0000
commitf84177299a76759be1eb925093b059aef246fc0e (patch)
tree3f0a89be66567dc56bf422403517336544527776 /src
parente7741c064ee4cdc5fa41e6444ed45131672fed97 (diff)
downloadexternal_protobuf-f84177299a76759be1eb925093b059aef246fc0e.zip
external_protobuf-f84177299a76759be1eb925093b059aef246fc0e.tar.gz
external_protobuf-f84177299a76759be1eb925093b059aef246fc0e.tar.bz2
Don't serialize required fields whose 'has' flags are unset.
Change-Id: Ibbe944fff83e44a8f2206e18ee9ec6f10661297a
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_enum_field.cc5
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_primitive_field.cc7
-rw-r--r--src/google/protobuf/unittest_has_nano.proto2
3 files changed, 9 insertions, 5 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
index 5d3511b..eb73232 100644
--- a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
@@ -121,7 +121,8 @@ GenerateMergingCode(io::Printer* printer) const {
void EnumFieldGenerator::
GenerateSerializationCode(io::Printer* printer) const {
- if (descriptor_->is_required()) {
+ if (descriptor_->is_required() && !params_.generate_has()) {
+ // Always serialize a required field if we don't have the 'has' signal.
printer->Print(variables_,
"output.writeInt32($number$, this.$name$);\n");
} else {
@@ -140,7 +141,7 @@ GenerateSerializationCode(io::Printer* printer) const {
void EnumFieldGenerator::
GenerateSerializedSizeCode(io::Printer* printer) const {
- if (descriptor_->is_required()) {
+ if (descriptor_->is_required() && !params_.generate_has()) {
printer->Print(variables_,
"size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
" .computeInt32Size($number$, this.$name$);\n");
diff --git a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
index 3428f69..b6c98b4 100644
--- a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
@@ -342,7 +342,7 @@ GenerateMembers(io::Printer* printer, bool lazy_init) const {
if (params_.generate_has()) {
printer->Print(variables_,
- "public boolean has$capitalized_name$ = false;\n");
+ "public boolean has$capitalized_name$;\n");
}
}
@@ -401,7 +401,8 @@ GenerateSerializationConditional(io::Printer* printer) const {
void PrimitiveFieldGenerator::
GenerateSerializationCode(io::Printer* printer) const {
- if (descriptor_->is_required()) {
+ if (descriptor_->is_required() && !params_.generate_has()) {
+ // Always serialize a required field if we don't have the 'has' signal.
printer->Print(variables_,
"output.write$capitalized_type$($number$, this.$name$);\n");
} else {
@@ -414,7 +415,7 @@ GenerateSerializationCode(io::Printer* printer) const {
void PrimitiveFieldGenerator::
GenerateSerializedSizeCode(io::Printer* printer) const {
- if (descriptor_->is_required()) {
+ if (descriptor_->is_required() && !params_.generate_has()) {
printer->Print(variables_,
"size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
" .compute$capitalized_type$Size($number$, this.$name$);\n");
diff --git a/src/google/protobuf/unittest_has_nano.proto b/src/google/protobuf/unittest_has_nano.proto
index 3a1e5b5..61800f2 100644
--- a/src/google/protobuf/unittest_has_nano.proto
+++ b/src/google/protobuf/unittest_has_nano.proto
@@ -75,4 +75,6 @@ message TestAllTypesNanoHas {
optional NestedEnum default_nested_enum = 81 [default = BAR];
required int32 id = 86;
+ required NestedEnum required_enum = 87;
+
}