| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 bytecode_estimate += | 113 bytecode_estimate += |
| 114 ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) | 114 ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) |
| 115 .GenerateStaticVariableInitializers(printer); | 115 .GenerateStaticVariableInitializers(printer); |
| 116 } | 116 } |
| 117 return bytecode_estimate; | 117 return bytecode_estimate; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // =================================================================== | 120 // =================================================================== |
| 121 | 121 |
| 122 void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { | 122 void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { |
| 123 MaybePrintGeneratedAnnotation(context_, printer, descriptor_, | |
| 124 /* immutable = */ true, "OrBuilder"); | |
| 125 if (descriptor_->extension_range_count() > 0) { | 123 if (descriptor_->extension_range_count() > 0) { |
| 126 printer->Print( | 124 printer->Print( |
| 127 "public interface $classname$OrBuilder$idend$ extends \n" | 125 "public interface $classname$OrBuilder extends \n" |
| 128 " $extra_interfaces$\n" | 126 " $extra_interfaces$\n" |
| 129 " com.google.protobuf.GeneratedMessageLite.\n" | 127 " com.google.protobuf.GeneratedMessageLite.\n" |
| 130 " ExtendableMessageOrBuilder<\n" | 128 " ExtendableMessageOrBuilder<\n" |
| 131 " $classname$, $classname$.Builder> {\n", | 129 " $classname$, $classname$.Builder> {\n", |
| 132 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), | 130 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
| 133 "classname", descriptor_->name(), | 131 "classname", descriptor_->name()); |
| 134 "idend", ""); | |
| 135 } else { | 132 } else { |
| 136 printer->Print( | 133 printer->Print( |
| 137 "public interface $classname$OrBuilder$idend$ extends\n" | 134 "public interface $classname$OrBuilder extends\n" |
| 138 " $extra_interfaces$\n" | 135 " $extra_interfaces$\n" |
| 139 " com.google.protobuf.MessageLiteOrBuilder {\n", | 136 " com.google.protobuf.MessageLiteOrBuilder {\n", |
| 140 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), | 137 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
| 141 "classname", descriptor_->name(), | 138 "classname", descriptor_->name()); |
| 142 "idend", ""); | |
| 143 } | 139 } |
| 144 printer->Annotate("classname", "idend", descriptor_); | |
| 145 | 140 |
| 146 printer->Indent(); | 141 printer->Indent(); |
| 147 for (int i = 0; i < descriptor_->field_count(); i++) { | 142 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 148 printer->Print("\n"); | 143 printer->Print("\n"); |
| 149 field_generators_.get(descriptor_->field(i)) | 144 field_generators_.get(descriptor_->field(i)) |
| 150 .GenerateInterfaceMembers(printer); | 145 .GenerateInterfaceMembers(printer); |
| 151 } | 146 } |
| 152 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { | 147 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { |
| 153 printer->Print( | 148 printer->Print( |
| 154 "\n" | 149 "\n" |
| 155 "public $classname$.$oneof_capitalized_name$Case " | 150 "public $classname$.$oneof_capitalized_name$Case " |
| 156 "get$oneof_capitalized_name$Case();\n", | 151 "get$oneof_capitalized_name$Case();\n", |
| 157 "oneof_capitalized_name", | 152 "oneof_capitalized_name", |
| 158 context_->GetOneofGeneratorInfo( | 153 context_->GetOneofGeneratorInfo( |
| 159 descriptor_->oneof_decl(i))->capitalized_name, | 154 descriptor_->oneof_decl(i))->capitalized_name, |
| 160 "classname", | 155 "classname", |
| 161 context_->GetNameResolver()->GetImmutableClassName(descriptor_)); | 156 context_->GetNameResolver()->GetImmutableClassName(descriptor_)); |
| 162 } | 157 } |
| 163 printer->Outdent(); | 158 printer->Outdent(); |
| 164 | 159 |
| 165 printer->Print("}\n"); | 160 printer->Print("}\n"); |
| 166 } | 161 } |
| 167 | 162 |
| 168 // =================================================================== | 163 // =================================================================== |
| 169 | 164 |
| 170 void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { | 165 void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { |
| 171 bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); | 166 bool is_own_file = |
| 167 descriptor_->containing_type() == NULL && |
| 168 MultipleJavaFiles(descriptor_->file(), /* immutable = */ true); |
| 172 | 169 |
| 173 std::map<string, string> variables; | 170 map<string, string> variables; |
| 174 variables["static"] = is_own_file ? " " : " static "; | 171 variables["static"] = is_own_file ? " " : " static "; |
| 175 variables["classname"] = descriptor_->name(); | 172 variables["classname"] = descriptor_->name(); |
| 176 variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); | 173 variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); |
| 177 | 174 |
| 178 WriteMessageDocComment(printer, descriptor_); | 175 WriteMessageDocComment(printer, descriptor_); |
| 179 MaybePrintGeneratedAnnotation(context_, printer, descriptor_, | |
| 180 /* immutable = */ true); | |
| 181 | |
| 182 | 176 |
| 183 // The builder_type stores the super type name of the nested Builder class. | 177 // The builder_type stores the super type name of the nested Builder class. |
| 184 string builder_type; | 178 string builder_type; |
| 185 if (descriptor_->extension_range_count() > 0) { | 179 if (descriptor_->extension_range_count() > 0) { |
| 186 printer->Print(variables, | 180 printer->Print(variables, |
| 187 "public $static$final class $classname$ extends\n" | 181 "public $static$final class $classname$ extends\n" |
| 188 " com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n" | 182 " com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n" |
| 189 " $classname$, $classname$.Builder> implements\n" | 183 " $classname$, $classname$.Builder> implements\n" |
| 190 " $extra_interfaces$\n" | 184 " $extra_interfaces$\n" |
| 191 " $classname$OrBuilder {\n"); | 185 " $classname$OrBuilder {\n"); |
| 192 builder_type = strings::Substitute( | 186 builder_type = strings::Substitute( |
| 193 "com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>", | 187 "com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>", |
| 194 name_resolver_->GetImmutableClassName(descriptor_)); | 188 name_resolver_->GetImmutableClassName(descriptor_)); |
| 195 } else { | 189 } else { |
| 196 printer->Print(variables, | 190 printer->Print(variables, |
| 197 "public $static$final class $classname$ extends\n" | 191 "public $static$final class $classname$ extends\n" |
| 198 " com.google.protobuf.GeneratedMessageLite<\n" | 192 " com.google.protobuf.GeneratedMessageLite<\n" |
| 199 " $classname$, $classname$.Builder> implements\n" | 193 " $classname$, $classname$.Builder> implements\n" |
| 200 " $extra_interfaces$\n" | 194 " $extra_interfaces$\n" |
| 201 " $classname$OrBuilder {\n"); | 195 " $classname$OrBuilder {\n"); |
| 202 | 196 |
| 203 builder_type = "com.google.protobuf.GeneratedMessageLite.Builder"; | 197 builder_type = "com.google.protobuf.GeneratedMessageLite.Builder"; |
| 204 } | 198 } |
| 205 printer->Indent(); | 199 printer->Indent(); |
| 206 | 200 |
| 201 |
| 207 GenerateConstructor(printer); | 202 GenerateConstructor(printer); |
| 208 | 203 |
| 209 // Nested types | 204 // Nested types |
| 210 for (int i = 0; i < descriptor_->enum_type_count(); i++) { | 205 for (int i = 0; i < descriptor_->enum_type_count(); i++) { |
| 211 EnumLiteGenerator(descriptor_->enum_type(i), true, context_) | 206 EnumLiteGenerator(descriptor_->enum_type(i), true, context_) |
| 212 .Generate(printer); | 207 .Generate(printer); |
| 213 } | 208 } |
| 214 | 209 |
| 215 for (int i = 0; i < descriptor_->nested_type_count(); i++) { | 210 for (int i = 0; i < descriptor_->nested_type_count(); i++) { |
| 216 // Don't generate Java classes for map entry messages. | 211 // Don't generate Java classes for map entry messages. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 229 .GetNumBitsForMessage(); | 224 .GetNumBitsForMessage(); |
| 230 } | 225 } |
| 231 int totalInts = (totalBits + 31) / 32; | 226 int totalInts = (totalBits + 31) / 32; |
| 232 for (int i = 0; i < totalInts; i++) { | 227 for (int i = 0; i < totalInts; i++) { |
| 233 printer->Print("private int $bit_field_name$;\n", | 228 printer->Print("private int $bit_field_name$;\n", |
| 234 "bit_field_name", GetBitFieldName(i)); | 229 "bit_field_name", GetBitFieldName(i)); |
| 235 } | 230 } |
| 236 } | 231 } |
| 237 | 232 |
| 238 // oneof | 233 // oneof |
| 239 std::map<string, string> vars; | 234 map<string, string> vars; |
| 240 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { | 235 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { |
| 241 const OneofDescriptor* oneof = descriptor_->oneof_decl(i); | 236 vars["oneof_name"] = context_->GetOneofGeneratorInfo( |
| 242 vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; | 237 descriptor_->oneof_decl(i))->name; |
| 243 vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( | 238 vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( |
| 244 oneof)->capitalized_name; | 239 descriptor_->oneof_decl(i))->capitalized_name; |
| 245 vars["oneof_index"] = SimpleItoa(oneof->index()); | 240 vars["oneof_index"] = SimpleItoa(descriptor_->oneof_decl(i)->index()); |
| 246 // oneofCase_ and oneof_ | 241 // oneofCase_ and oneof_ |
| 247 printer->Print(vars, | 242 printer->Print(vars, |
| 248 "private int $oneof_name$Case_ = 0;\n" | 243 "private int $oneof_name$Case_ = 0;\n" |
| 249 "private java.lang.Object $oneof_name$_;\n"); | 244 "private java.lang.Object $oneof_name$_;\n"); |
| 250 // OneofCase enum | 245 // OneofCase enum |
| 251 printer->Print(vars, | 246 printer->Print(vars, |
| 252 "public enum $oneof_capitalized_name$Case\n" | 247 "public enum $oneof_capitalized_name$Case\n" |
| 253 " implements com.google.protobuf.Internal.EnumLite {\n"); | 248 " implements com.google.protobuf.Internal.EnumLite {\n"); |
| 254 printer->Indent(); | 249 printer->Indent(); |
| 255 for (int j = 0; j < oneof->field_count(); j++) { | 250 for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { |
| 256 const FieldDescriptor* field = oneof->field(j); | 251 const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); |
| 257 printer->Print( | 252 printer->Print( |
| 258 "$field_name$($field_number$),\n", | 253 "$field_name$($field_number$),\n", |
| 259 "field_name", | 254 "field_name", |
| 260 ToUpper(field->name()), | 255 ToUpper(field->name()), |
| 261 "field_number", | 256 "field_number", |
| 262 SimpleItoa(field->number())); | 257 SimpleItoa(field->number())); |
| 263 } | 258 } |
| 264 printer->Print( | 259 printer->Print( |
| 265 "$cap_oneof_name$_NOT_SET(0);\n", | 260 "$cap_oneof_name$_NOT_SET(0);\n", |
| 266 "cap_oneof_name", | 261 "cap_oneof_name", |
| 267 ToUpper(vars["oneof_name"])); | 262 ToUpper(vars["oneof_name"])); |
| 268 printer->Print(vars, | 263 printer->Print(vars, |
| 269 "private final int value;\n" | 264 "private final int value;\n" |
| 270 "private $oneof_capitalized_name$Case(int value) {\n" | 265 "private $oneof_capitalized_name$Case(int value) {\n" |
| 271 " this.value = value;\n" | 266 " this.value = value;\n" |
| 272 "}\n"); | 267 "}\n"); |
| 273 printer->Print(vars, | 268 printer->Print(vars, |
| 274 "/**\n" | 269 "/**\n" |
| 275 " * @deprecated Use {@link #forNumber(int)} instead.\n" | 270 " * @deprecated Use {@link #forNumber(int)} instead.\n" |
| 276 " */\n" | 271 " */\n" |
| 277 "@java.lang.Deprecated\n" | 272 "@java.lang.Deprecated\n" |
| 278 "public static $oneof_capitalized_name$Case valueOf(int value) {\n" | 273 "public static $oneof_capitalized_name$Case valueOf(int value) {\n" |
| 279 " return forNumber(value);\n" | 274 " return forNumber(value);\n" |
| 280 "}\n" | 275 "}\n" |
| 281 "\n" | 276 "\n" |
| 282 "public static $oneof_capitalized_name$Case forNumber(int value) {\n" | 277 "public static $oneof_capitalized_name$Case forNumber(int value) {\n" |
| 283 " switch (value) {\n"); | 278 " switch (value) {\n"); |
| 284 for (int j = 0; j < oneof->field_count(); j++) { | 279 for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { |
| 285 const FieldDescriptor* field = oneof->field(j); | 280 const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); |
| 286 printer->Print( | 281 printer->Print( |
| 287 " case $field_number$: return $field_name$;\n", | 282 " case $field_number$: return $field_name$;\n", |
| 288 "field_number", | 283 "field_number", |
| 289 SimpleItoa(field->number()), | 284 SimpleItoa(field->number()), |
| 290 "field_name", | 285 "field_name", |
| 291 ToUpper(field->name())); | 286 ToUpper(field->name())); |
| 292 } | 287 } |
| 293 printer->Print( | 288 printer->Print( |
| 294 " case 0: return $cap_oneof_name$_NOT_SET;\n" | 289 " case 0: return $cap_oneof_name$_NOT_SET;\n" |
| 295 " default: return null;\n" | 290 " default: return null;\n" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 printer->Print("}\n\n"); | 455 printer->Print("}\n\n"); |
| 461 } | 456 } |
| 462 | 457 |
| 463 // =================================================================== | 458 // =================================================================== |
| 464 | 459 |
| 465 void ImmutableMessageLiteGenerator:: | 460 void ImmutableMessageLiteGenerator:: |
| 466 GenerateMessageSerializationMethods(io::Printer* printer) { | 461 GenerateMessageSerializationMethods(io::Printer* printer) { |
| 467 google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields( | 462 google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields( |
| 468 SortFieldsByNumber(descriptor_)); | 463 SortFieldsByNumber(descriptor_)); |
| 469 | 464 |
| 470 std::vector<const Descriptor::ExtensionRange*> sorted_extensions; | 465 vector<const Descriptor::ExtensionRange*> sorted_extensions; |
| 471 for (int i = 0; i < descriptor_->extension_range_count(); ++i) { | 466 for (int i = 0; i < descriptor_->extension_range_count(); ++i) { |
| 472 sorted_extensions.push_back(descriptor_->extension_range(i)); | 467 sorted_extensions.push_back(descriptor_->extension_range(i)); |
| 473 } | 468 } |
| 474 std::sort(sorted_extensions.begin(), sorted_extensions.end(), | 469 std::sort(sorted_extensions.begin(), sorted_extensions.end(), |
| 475 ExtensionRangeOrdering()); | 470 ExtensionRangeOrdering()); |
| 476 | 471 |
| 477 printer->Print( | 472 printer->Print( |
| 478 "public void writeTo(com.google.protobuf.CodedOutputStream output)\n" | 473 "public void writeTo(com.google.protobuf.CodedOutputStream output)\n" |
| 479 " throws java.io.IOException {\n"); | 474 " throws java.io.IOException {\n"); |
| 480 printer->Indent(); | 475 printer->Indent(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } else if (j == sorted_extensions.size()) { | 511 } else if (j == sorted_extensions.size()) { |
| 517 GenerateSerializeOneField(printer, sorted_fields[i++]); | 512 GenerateSerializeOneField(printer, sorted_fields[i++]); |
| 518 } else if (sorted_fields[i]->number() < sorted_extensions[j]->start) { | 513 } else if (sorted_fields[i]->number() < sorted_extensions[j]->start) { |
| 519 GenerateSerializeOneField(printer, sorted_fields[i++]); | 514 GenerateSerializeOneField(printer, sorted_fields[i++]); |
| 520 } else { | 515 } else { |
| 521 GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); | 516 GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); |
| 522 } | 517 } |
| 523 } | 518 } |
| 524 | 519 |
| 525 if (PreserveUnknownFields(descriptor_)) { | 520 if (PreserveUnknownFields(descriptor_)) { |
| 526 if (descriptor_->options().message_set_wire_format()) { | 521 printer->Print( |
| 527 printer->Print( | 522 "unknownFields.writeTo(output);\n"); |
| 528 "unknownFields.writeAsMessageSetTo(output);\n"); | |
| 529 } else { | |
| 530 printer->Print( | |
| 531 "unknownFields.writeTo(output);\n"); | |
| 532 } | |
| 533 } | 523 } |
| 534 | 524 |
| 535 printer->Outdent(); | 525 printer->Outdent(); |
| 536 printer->Print( | 526 printer->Print( |
| 537 "}\n" | 527 "}\n" |
| 538 "\n" | 528 "\n" |
| 539 "public int getSerializedSize() {\n" | 529 "public int getSerializedSize() {\n" |
| 540 " int size = memoizedSerializedSize;\n" | 530 " int size = memoizedSerializedSize;\n" |
| 541 " if (size != -1) return size;\n" | 531 " if (size != -1) return size;\n" |
| 542 "\n" | 532 "\n" |
| 543 " size = 0;\n"); | 533 " size = 0;\n"); |
| 544 printer->Indent(); | 534 printer->Indent(); |
| 545 | 535 |
| 546 for (int i = 0; i < descriptor_->field_count(); i++) { | 536 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 547 field_generators_.get(sorted_fields[i]).GenerateSerializedSizeCode(printer); | 537 field_generators_.get(sorted_fields[i]).GenerateSerializedSizeCode(printer); |
| 548 } | 538 } |
| 549 | 539 |
| 550 if (descriptor_->extension_range_count() > 0) { | 540 if (descriptor_->extension_range_count() > 0) { |
| 551 if (descriptor_->options().message_set_wire_format()) { | 541 if (descriptor_->options().message_set_wire_format()) { |
| 552 printer->Print( | 542 printer->Print( |
| 553 "size += extensionsSerializedSizeAsMessageSet();\n"); | 543 "size += extensionsSerializedSizeAsMessageSet();\n"); |
| 554 } else { | 544 } else { |
| 555 printer->Print( | 545 printer->Print( |
| 556 "size += extensionsSerializedSize();\n"); | 546 "size += extensionsSerializedSize();\n"); |
| 557 } | 547 } |
| 558 } | 548 } |
| 559 | 549 |
| 560 if (PreserveUnknownFields(descriptor_)) { | 550 if (PreserveUnknownFields(descriptor_)) { |
| 561 if (descriptor_->options().message_set_wire_format()) { | 551 printer->Print( |
| 562 printer->Print( | 552 "size += unknownFields.getSerializedSize();\n"); |
| 563 "size += unknownFields.getSerializedSizeAsMessageSet();\n"); | |
| 564 } else { | |
| 565 printer->Print( | |
| 566 "size += unknownFields.getSerializedSize();\n"); | |
| 567 } | |
| 568 } | 553 } |
| 569 | 554 |
| 570 printer->Outdent(); | 555 printer->Outdent(); |
| 571 printer->Print( | 556 printer->Print( |
| 572 " memoizedSerializedSize = size;\n" | 557 " memoizedSerializedSize = size;\n" |
| 573 " return size;\n" | 558 " return size;\n" |
| 574 "}\n" | 559 "}\n" |
| 575 "\n"); | 560 "\n"); |
| 576 } | 561 } |
| 577 | 562 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 " memoizedIsInitialized = 0;\n" | 736 " memoizedIsInitialized = 0;\n" |
| 752 " }\n" | 737 " }\n" |
| 753 " return null;\n" | 738 " return null;\n" |
| 754 " }\n" | 739 " }\n" |
| 755 "}\n", | 740 "}\n", |
| 756 "name", info->capitalized_name); | 741 "name", info->capitalized_name); |
| 757 break; | 742 break; |
| 758 case FieldDescriptor::LABEL_REPEATED: | 743 case FieldDescriptor::LABEL_REPEATED: |
| 759 if (IsMapEntry(field->message_type())) { | 744 if (IsMapEntry(field->message_type())) { |
| 760 printer->Print( | 745 printer->Print( |
| 761 "for ($type$ item : get$name$Map().values()) {\n" | 746 "for ($type$ item : get$name$().values()) {\n" |
| 762 " if (!item.isInitialized()) {\n" | 747 " if (!item.isInitialized()) {\n" |
| 763 " if (shouldMemoize) {\n" | 748 " if (shouldMemoize) {\n" |
| 764 " memoizedIsInitialized = 0;\n" | 749 " memoizedIsInitialized = 0;\n" |
| 765 " }\n" | 750 " }\n" |
| 766 " return null;\n" | 751 " return null;\n" |
| 767 " }\n" | 752 " }\n" |
| 768 "}\n", | 753 "}\n", |
| 769 "type", MapValueImmutableClassdName(field->message_type(), | 754 "type", MapValueImmutableClassdName(field->message_type(), |
| 770 name_resolver_), | 755 name_resolver_), |
| 771 "name", info->capitalized_name); | 756 "name", info->capitalized_name); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 "switch (tag) {\n"); | 927 "switch (tag) {\n"); |
| 943 printer->Indent(); | 928 printer->Indent(); |
| 944 | 929 |
| 945 printer->Print( | 930 printer->Print( |
| 946 "case 0:\n" // zero signals EOF / limit reached | 931 "case 0:\n" // zero signals EOF / limit reached |
| 947 " done = true;\n" | 932 " done = true;\n" |
| 948 " break;\n"); | 933 " break;\n"); |
| 949 | 934 |
| 950 if (PreserveUnknownFields(descriptor_)) { | 935 if (PreserveUnknownFields(descriptor_)) { |
| 951 if (descriptor_->extension_range_count() > 0) { | 936 if (descriptor_->extension_range_count() > 0) { |
| 952 if (descriptor_->options().message_set_wire_format()) { | 937 printer->Print( |
| 953 printer->Print( | 938 "default: {\n" |
| 954 "default: {\n" | 939 " if (!parseUnknownField(getDefaultInstanceForType(),\n" |
| 955 " if (!parseUnknownFieldAsMessageSet(\n" | 940 " input, extensionRegistry, tag)) {\n" |
| 956 " getDefaultInstanceForType(), input, extensionRegistry,\n" | 941 " done = true;\n" // it's an endgroup tag |
| 957 " tag)) {\n" | 942 " }\n" |
| 958 " done = true;\n" // it's an endgroup tag | 943 " break;\n" |
| 959 " }\n" | 944 "}\n"); |
| 960 " break;\n" | |
| 961 "}\n"); | |
| 962 } else { | |
| 963 printer->Print( | |
| 964 "default: {\n" | |
| 965 " if (!parseUnknownField(getDefaultInstanceForType(),\n" | |
| 966 " input, extensionRegistry, tag)) {\n" | |
| 967 " done = true;\n" // it's an endgroup tag | |
| 968 " }\n" | |
| 969 " break;\n" | |
| 970 "}\n"); | |
| 971 } | |
| 972 } else { | 945 } else { |
| 973 printer->Print( | 946 printer->Print( |
| 974 "default: {\n" | 947 "default: {\n" |
| 975 " if (!parseUnknownField(tag, input)) {\n" | 948 " if (!parseUnknownField(tag, input)) {\n" |
| 976 " done = true;\n" // it's an endgroup tag | 949 " done = true;\n" // it's an endgroup tag |
| 977 " }\n" | 950 " }\n" |
| 978 " break;\n" | 951 " break;\n" |
| 979 "}\n"); | 952 "}\n"); |
| 980 } | 953 } |
| 981 } else { | 954 } else { |
| 982 printer->Print( | 955 printer->Print( |
| 983 "default: {\n" | 956 "default: {\n" |
| 984 " if (!input.skipField(tag)) {\n" | 957 " if (!input.skipField(tag)) {\n" |
| 985 " done = true;\n" // it's an endgroup tag | 958 " done = true;\n" // it's an endgroup tag |
| 986 " }\n" | 959 " }\n" |
| 987 " break;\n" | 960 " break;\n" |
| 988 "}\n"); | 961 "}\n"); |
| 989 } | 962 } |
| 990 | 963 |
| 991 google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields( | 964 google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields( |
| 992 SortFieldsByNumber(descriptor_)); | 965 SortFieldsByNumber(descriptor_)); |
| 993 for (int i = 0; i < descriptor_->field_count(); i++) { | 966 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 994 const FieldDescriptor* field = sorted_fields[i]; | 967 const FieldDescriptor* field = sorted_fields[i]; |
| 995 uint32 tag = WireFormatLite::MakeTag(field->number(), | 968 uint32 tag = WireFormatLite::MakeTag(field->number(), |
| 996 WireFormat::WireTypeForFieldType(field->type())); | 969 WireFormat::WireTypeForFieldType(field->type())); |
| 997 | 970 |
| 998 printer->Print( | 971 printer->Print( |
| 999 "case $tag$: {\n", | 972 "case $tag$: {\n", |
| 1000 "tag", SimpleItoa(static_cast<int32>(tag))); | 973 "tag", SimpleItoa(tag)); |
| 1001 printer->Indent(); | 974 printer->Indent(); |
| 1002 | 975 |
| 1003 field_generators_.get(field).GenerateParsingCode(printer); | 976 field_generators_.get(field).GenerateParsingCode(printer); |
| 1004 | 977 |
| 1005 printer->Outdent(); | 978 printer->Outdent(); |
| 1006 printer->Print( | 979 printer->Print( |
| 1007 " break;\n" | 980 " break;\n" |
| 1008 "}\n"); | 981 "}\n"); |
| 1009 | 982 |
| 1010 if (field->is_packable()) { | 983 if (field->is_packable()) { |
| 1011 // To make packed = true wire compatible, we generate parsing code from a | 984 // To make packed = true wire compatible, we generate parsing code from a |
| 1012 // packed version of this field regardless of field->options().packed(). | 985 // packed version of this field regardless of field->options().packed(). |
| 1013 uint32 packed_tag = WireFormatLite::MakeTag(field->number(), | 986 uint32 packed_tag = WireFormatLite::MakeTag(field->number(), |
| 1014 WireFormatLite::WIRETYPE_LENGTH_DELIMITED); | 987 WireFormatLite::WIRETYPE_LENGTH_DELIMITED); |
| 1015 printer->Print( | 988 printer->Print( |
| 1016 "case $tag$: {\n", | 989 "case $tag$: {\n", |
| 1017 "tag", SimpleItoa(static_cast<int32>(packed_tag))); | 990 "tag", SimpleItoa(packed_tag)); |
| 1018 printer->Indent(); | 991 printer->Indent(); |
| 1019 | 992 |
| 1020 field_generators_.get(field).GenerateParsingCodeFromPacked(printer); | 993 field_generators_.get(field).GenerateParsingCodeFromPacked(printer); |
| 1021 | 994 |
| 1022 printer->Outdent(); | 995 printer->Outdent(); |
| 1023 printer->Print( | 996 printer->Print( |
| 1024 " break;\n" | 997 " break;\n" |
| 1025 "}\n"); | 998 "}\n"); |
| 1026 } | 999 } |
| 1027 } | 1000 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 field_generators_.get(descriptor_->field(i)) | 1085 field_generators_.get(descriptor_->field(i)) |
| 1113 .GenerateInitializationCode(printer); | 1086 .GenerateInitializationCode(printer); |
| 1114 } | 1087 } |
| 1115 } | 1088 } |
| 1116 } | 1089 } |
| 1117 | 1090 |
| 1118 } // namespace java | 1091 } // namespace java |
| 1119 } // namespace compiler | 1092 } // namespace compiler |
| 1120 } // namespace protobuf | 1093 } // namespace protobuf |
| 1121 } // namespace google | 1094 } // namespace google |
| OLD | NEW |