aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
diff options
context:
space:
mode:
authorGravatar Ulas Kirazci <ulas@google.com>2013-04-01 11:29:43 -0700
committerGravatar Ulas Kirazci <ulas@google.com>2013-07-29 09:35:44 -0700
commite83bbbbe4213e9b7bcc0529c305b821da8d7a136 (patch)
tree51bf9bf0b8b6c39eeedd3dbb042da2f28ccbce5b /src/google/protobuf/compiler/javanano/javanano_enum_field.cc
parenta91e2fc467033f975211e8d88582a3d706ee862d (diff)
Add an option to inspect "has" state upon parse.
If has is set, also always serialize. Change-Id: I2c8450f7ab9e837d722123dd1042991c0258ede3
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_enum_field.cc')
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_enum_field.cc26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
index 215f3419..9c4acb92 100644
--- a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
@@ -82,12 +82,22 @@ void EnumFieldGenerator::
GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"public int $name$ = $default$;\n");
+
+ if (params_.generate_has()) {
+ printer->Print(variables_,
+ "public boolean has$capitalized_name$ = false;\n");
+ }
}
void EnumFieldGenerator::
GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
" this.$name$ = input.readInt32();\n");
+
+ if (params_.generate_has()) {
+ printer->Print(variables_,
+ " has$capitalized_name$ = true;\n");
+ }
}
void EnumFieldGenerator::
@@ -96,8 +106,14 @@ GenerateSerializationCode(io::Printer* printer) const {
printer->Print(variables_,
"output.writeInt32($number$, this.$name$);\n");
} else {
+ if (params_.generate_has()) {
+ printer->Print(variables_,
+ "if (this.$name$ != $default$ || has$capitalized_name$) {\n");
+ } else {
+ printer->Print(variables_,
+ "if (this.$name$ != $default$) {\n");
+ }
printer->Print(variables_,
- "if (this.$name$ != $default$) {\n"
" output.writeInt32($number$, this.$name$);\n"
"}\n");
}
@@ -110,8 +126,14 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
"size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
" .computeInt32Size($number$, this.$name$);\n");
} else {
+ if (params_.generate_has()) {
+ printer->Print(variables_,
+ "if (this.$name$ != $default$ || has$capitalized_name$) {\n");
+ } else {
+ printer->Print(variables_,
+ "if (this.$name$ != $default$) {\n");
+ }
printer->Print(variables_,
- "if (this.$name$ != $default$) {\n"
" size += com.google.protobuf.nano.CodedOutputByteBufferNano\n"
" .computeInt32Size($number$, this.$name$);\n"
"}\n");