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