| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 void ImmutableMessageGenerator::GenerateStaticVariables( | 104 void ImmutableMessageGenerator::GenerateStaticVariables( |
| 105 io::Printer* printer, int* bytecode_estimate) { | 105 io::Printer* printer, int* bytecode_estimate) { |
| 106 // Because descriptor.proto (com.google.protobuf.DescriptorProtos) is | 106 // Because descriptor.proto (com.google.protobuf.DescriptorProtos) is |
| 107 // used in the construction of descriptors, we have a tricky bootstrapping | 107 // used in the construction of descriptors, we have a tricky bootstrapping |
| 108 // problem. To help control static initialization order, we make sure all | 108 // problem. To help control static initialization order, we make sure all |
| 109 // descriptors and other static data that depends on them are members of | 109 // descriptors and other static data that depends on them are members of |
| 110 // the outermost class in the file. This way, they will be initialized in | 110 // the outermost class in the file. This way, they will be initialized in |
| 111 // a deterministic order. | 111 // a deterministic order. |
| 112 | 112 |
| 113 std::map<string, string> vars; | 113 map<string, string> vars; |
| 114 vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); | 114 vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); |
| 115 vars["index"] = SimpleItoa(descriptor_->index()); | 115 vars["index"] = SimpleItoa(descriptor_->index()); |
| 116 vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); | 116 vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); |
| 117 if (descriptor_->containing_type() != NULL) { | 117 if (descriptor_->containing_type() != NULL) { |
| 118 vars["parent"] = UniqueFileScopeIdentifier( | 118 vars["parent"] = UniqueFileScopeIdentifier( |
| 119 descriptor_->containing_type()); | 119 descriptor_->containing_type()); |
| 120 } | 120 } |
| 121 if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { | 121 if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { |
| 122 // We can only make these package-private since the classes that use them | 122 // We can only make these package-private since the classes that use them |
| 123 // are in separate files. | 123 // are in separate files. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 147 for (int i = 0; i < descriptor_->nested_type_count(); i++) { | 147 for (int i = 0; i < descriptor_->nested_type_count(); i++) { |
| 148 // TODO(kenton): Reuse MessageGenerator objects? | 148 // TODO(kenton): Reuse MessageGenerator objects? |
| 149 ImmutableMessageGenerator(descriptor_->nested_type(i), context_) | 149 ImmutableMessageGenerator(descriptor_->nested_type(i), context_) |
| 150 .GenerateStaticVariables(printer, bytecode_estimate); | 150 .GenerateStaticVariables(printer, bytecode_estimate); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 int ImmutableMessageGenerator::GenerateStaticVariableInitializers( | 154 int ImmutableMessageGenerator::GenerateStaticVariableInitializers( |
| 155 io::Printer* printer) { | 155 io::Printer* printer) { |
| 156 int bytecode_estimate = 0; | 156 int bytecode_estimate = 0; |
| 157 std::map<string, string> vars; | 157 map<string, string> vars; |
| 158 vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); | 158 vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); |
| 159 vars["index"] = SimpleItoa(descriptor_->index()); | 159 vars["index"] = SimpleItoa(descriptor_->index()); |
| 160 vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); | 160 vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); |
| 161 if (descriptor_->containing_type() != NULL) { | 161 if (descriptor_->containing_type() != NULL) { |
| 162 vars["parent"] = UniqueFileScopeIdentifier( | 162 vars["parent"] = UniqueFileScopeIdentifier( |
| 163 descriptor_->containing_type()); | 163 descriptor_->containing_type()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // The descriptor for this type. | 166 // The descriptor for this type. |
| 167 if (descriptor_->containing_type() == NULL) { | 167 if (descriptor_->containing_type() == NULL) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 184 // TODO(kenton): Reuse MessageGenerator objects? | 184 // TODO(kenton): Reuse MessageGenerator objects? |
| 185 bytecode_estimate += | 185 bytecode_estimate += |
| 186 ImmutableMessageGenerator(descriptor_->nested_type(i), context_) | 186 ImmutableMessageGenerator(descriptor_->nested_type(i), context_) |
| 187 .GenerateStaticVariableInitializers(printer); | 187 .GenerateStaticVariableInitializers(printer); |
| 188 } | 188 } |
| 189 return bytecode_estimate; | 189 return bytecode_estimate; |
| 190 } | 190 } |
| 191 | 191 |
| 192 void ImmutableMessageGenerator:: | 192 void ImmutableMessageGenerator:: |
| 193 GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate) { | 193 GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate) { |
| 194 std::map<string, string> vars; | 194 map<string, string> vars; |
| 195 vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); | 195 vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); |
| 196 if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { | 196 if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { |
| 197 // We can only make these package-private since the classes that use them | 197 // We can only make these package-private since the classes that use them |
| 198 // are in separate files. | 198 // are in separate files. |
| 199 vars["private"] = ""; | 199 vars["private"] = ""; |
| 200 } else { | 200 } else { |
| 201 vars["private"] = "private "; | 201 vars["private"] = "private "; |
| 202 } | 202 } |
| 203 if (*bytecode_estimate <= kMaxStaticSize) { | 203 if (*bytecode_estimate <= kMaxStaticSize) { |
| 204 vars["final"] = "final "; | 204 vars["final"] = "final "; |
| 205 } else { | 205 } else { |
| 206 vars["final"] = ""; | 206 vars["final"] = ""; |
| 207 } | 207 } |
| 208 vars["ver"] = GeneratedCodeVersionSuffix(); | |
| 209 printer->Print(vars, | 208 printer->Print(vars, |
| 210 "$private$static $final$\n" | 209 "$private$static $final$\n" |
| 211 " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" | 210 " com.google.protobuf.GeneratedMessage.FieldAccessorTable\n" |
| 212 " internal_$identifier$_fieldAccessorTable;\n"); | 211 " internal_$identifier$_fieldAccessorTable;\n"); |
| 213 | 212 |
| 214 // 6 bytes per field and oneof | 213 // 6 bytes per field and oneof |
| 215 *bytecode_estimate += 10 + 6 * descriptor_->field_count() | 214 *bytecode_estimate += 10 + 6 * descriptor_->field_count() |
| 216 + 6 * descriptor_->oneof_decl_count(); | 215 + 6 * descriptor_->oneof_decl_count(); |
| 217 } | 216 } |
| 218 | 217 |
| 219 int ImmutableMessageGenerator:: | 218 int ImmutableMessageGenerator:: |
| 220 GenerateFieldAccessorTableInitializer(io::Printer* printer) { | 219 GenerateFieldAccessorTableInitializer(io::Printer* printer) { |
| 221 int bytecode_estimate = 10; | 220 int bytecode_estimate = 10; |
| 222 printer->Print( | 221 printer->Print( |
| 223 "internal_$identifier$_fieldAccessorTable = new\n" | 222 "internal_$identifier$_fieldAccessorTable = new\n" |
| 224 " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable(\n" | 223 " com.google.protobuf.GeneratedMessage.FieldAccessorTable(\n" |
| 225 " internal_$identifier$_descriptor,\n" | 224 " internal_$identifier$_descriptor,\n" |
| 226 " new java.lang.String[] { ", | 225 " new java.lang.String[] { ", |
| 227 "identifier", UniqueFileScopeIdentifier(descriptor_), | 226 "identifier", |
| 228 "ver", GeneratedCodeVersionSuffix()); | 227 UniqueFileScopeIdentifier(descriptor_)); |
| 229 for (int i = 0; i < descriptor_->field_count(); i++) { | 228 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 230 const FieldDescriptor* field = descriptor_->field(i); | 229 const FieldDescriptor* field = descriptor_->field(i); |
| 231 const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); | 230 const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); |
| 232 bytecode_estimate += 6; | 231 bytecode_estimate += 6; |
| 233 printer->Print( | 232 printer->Print( |
| 234 "\"$field_name$\", ", | 233 "\"$field_name$\", ", |
| 235 "field_name", info->capitalized_name); | 234 "field_name", info->capitalized_name); |
| 236 } | 235 } |
| 237 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { | 236 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { |
| 238 const OneofDescriptor* oneof = descriptor_->oneof_decl(i); | 237 const OneofDescriptor* oneof = descriptor_->oneof_decl(i); |
| 239 const OneofGeneratorInfo* info = context_->GetOneofGeneratorInfo(oneof); | 238 const OneofGeneratorInfo* info = context_->GetOneofGeneratorInfo(oneof); |
| 240 bytecode_estimate += 6; | 239 bytecode_estimate += 6; |
| 241 printer->Print( | 240 printer->Print( |
| 242 "\"$oneof_name$\", ", | 241 "\"$oneof_name$\", ", |
| 243 "oneof_name", info->capitalized_name); | 242 "oneof_name", info->capitalized_name); |
| 244 } | 243 } |
| 245 printer->Print("});\n"); | 244 printer->Print("});\n"); |
| 246 return bytecode_estimate; | 245 return bytecode_estimate; |
| 247 } | 246 } |
| 248 | 247 |
| 249 // =================================================================== | 248 // =================================================================== |
| 250 | 249 |
| 251 void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { | 250 void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { |
| 252 MaybePrintGeneratedAnnotation(context_, printer, descriptor_, | |
| 253 /* immutable = */ true, "OrBuilder"); | |
| 254 if (descriptor_->extension_range_count() > 0) { | 251 if (descriptor_->extension_range_count() > 0) { |
| 255 printer->Print( | 252 printer->Print( |
| 256 "public interface $classname$OrBuilder$idend$ extends\n" | 253 "public interface $classname$OrBuilder extends\n" |
| 257 " $extra_interfaces$\n" | 254 " $extra_interfaces$\n" |
| 258 " com.google.protobuf.GeneratedMessage$ver$.\n" | 255 " com.google.protobuf.GeneratedMessage.\n" |
| 259 " ExtendableMessageOrBuilder<$classname$> {\n", | 256 " ExtendableMessageOrBuilder<$classname$> {\n", |
| 260 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), | 257 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
| 261 "classname", descriptor_->name(), | 258 "classname", descriptor_->name()); |
| 262 "idend", "", "ver", GeneratedCodeVersionSuffix()); | |
| 263 } else { | 259 } else { |
| 264 printer->Print( | 260 printer->Print( |
| 265 "public interface $classname$OrBuilder$idend$ extends\n" | 261 "public interface $classname$OrBuilder extends\n" |
| 266 " $extra_interfaces$\n" | 262 " $extra_interfaces$\n" |
| 267 " com.google.protobuf.MessageOrBuilder {\n", | 263 " com.google.protobuf.MessageOrBuilder {\n", |
| 268 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), | 264 "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
| 269 "classname", descriptor_->name(), | 265 "classname", descriptor_->name()); |
| 270 "idend", ""); | |
| 271 } | 266 } |
| 272 printer->Annotate("classname", "idend", descriptor_); | |
| 273 | 267 |
| 274 printer->Indent(); | 268 printer->Indent(); |
| 275 for (int i = 0; i < descriptor_->field_count(); i++) { | 269 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 276 printer->Print("\n"); | 270 printer->Print("\n"); |
| 277 field_generators_.get(descriptor_->field(i)) | 271 field_generators_.get(descriptor_->field(i)) |
| 278 .GenerateInterfaceMembers(printer); | 272 .GenerateInterfaceMembers(printer); |
| 279 } | 273 } |
| 280 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { | 274 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { |
| 281 printer->Print( | 275 printer->Print( |
| 282 "\n" | 276 "\n" |
| 283 "public $classname$.$oneof_capitalized_name$Case " | 277 "public $classname$.$oneof_capitalized_name$Case " |
| 284 "get$oneof_capitalized_name$Case();\n", | 278 "get$oneof_capitalized_name$Case();\n", |
| 285 "oneof_capitalized_name", | 279 "oneof_capitalized_name", |
| 286 context_->GetOneofGeneratorInfo( | 280 context_->GetOneofGeneratorInfo( |
| 287 descriptor_->oneof_decl(i))->capitalized_name, | 281 descriptor_->oneof_decl(i))->capitalized_name, |
| 288 "classname", | 282 "classname", |
| 289 context_->GetNameResolver()->GetImmutableClassName( | 283 context_->GetNameResolver()->GetImmutableClassName( |
| 290 descriptor_)); | 284 descriptor_)); |
| 291 } | 285 } |
| 292 printer->Outdent(); | 286 printer->Outdent(); |
| 293 | 287 |
| 294 printer->Print("}\n"); | 288 printer->Print("}\n"); |
| 295 } | 289 } |
| 296 | 290 |
| 297 // =================================================================== | 291 // =================================================================== |
| 298 | 292 |
| 299 void ImmutableMessageGenerator::Generate(io::Printer* printer) { | 293 void ImmutableMessageGenerator::Generate(io::Printer* printer) { |
| 300 bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); | 294 bool is_own_file = |
| 295 descriptor_->containing_type() == NULL && |
| 296 MultipleJavaFiles(descriptor_->file(), /* immutable = */ true); |
| 301 | 297 |
| 302 std::map<string, string> variables; | 298 map<string, string> variables; |
| 303 variables["static"] = is_own_file ? " " : " static "; | 299 variables["static"] = is_own_file ? " " : " static "; |
| 304 variables["classname"] = descriptor_->name(); | 300 variables["classname"] = descriptor_->name(); |
| 305 variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); | 301 variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); |
| 306 variables["ver"] = GeneratedCodeVersionSuffix(); | |
| 307 | 302 |
| 308 WriteMessageDocComment(printer, descriptor_); | 303 WriteMessageDocComment(printer, descriptor_); |
| 309 MaybePrintGeneratedAnnotation(context_, printer, descriptor_, | |
| 310 /* immutable = */ true); | |
| 311 | 304 |
| 312 // The builder_type stores the super type name of the nested Builder class. | 305 // The builder_type stores the super type name of the nested Builder class. |
| 313 string builder_type; | 306 string builder_type; |
| 314 if (descriptor_->extension_range_count() > 0) { | 307 if (descriptor_->extension_range_count() > 0) { |
| 315 printer->Print(variables, | 308 printer->Print(variables, |
| 316 "public $static$final class $classname$ extends\n"); | 309 "public $static$final class $classname$ extends\n" |
| 317 printer->Annotate("classname", descriptor_); | 310 " com.google.protobuf.GeneratedMessage.ExtendableMessage<\n" |
| 318 printer->Print( | 311 " $classname$> implements\n" |
| 319 variables, | |
| 320 " com.google.protobuf.GeneratedMessage$ver$.ExtendableMessage<\n" | |
| 321 " $classname$> implements\n" | |
| 322 " $extra_interfaces$\n" | |
| 323 " $classname$OrBuilder {\n"); | |
| 324 builder_type = strings::Substitute( | |
| 325 "com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>", | |
| 326 name_resolver_->GetImmutableClassName(descriptor_), | |
| 327 GeneratedCodeVersionSuffix()); | |
| 328 } else { | |
| 329 printer->Print(variables, | |
| 330 "public $static$final class $classname$ extends\n"); | |
| 331 printer->Annotate("classname", descriptor_); | |
| 332 printer->Print(variables, | |
| 333 " com.google.protobuf.GeneratedMessage$ver$ implements\n" | |
| 334 " $extra_interfaces$\n" | 312 " $extra_interfaces$\n" |
| 335 " $classname$OrBuilder {\n"); | 313 " $classname$OrBuilder {\n"); |
| 336 builder_type = strings::Substitute( | 314 builder_type = strings::Substitute( |
| 337 "com.google.protobuf.GeneratedMessage$0.Builder<?>", | 315 "com.google.protobuf.GeneratedMessage.ExtendableBuilder<$0, ?>", |
| 338 GeneratedCodeVersionSuffix()); | 316 name_resolver_->GetImmutableClassName(descriptor_)); |
| 317 } else { |
| 318 printer->Print(variables, |
| 319 "public $static$final class $classname$ extends\n" |
| 320 " com.google.protobuf.GeneratedMessage implements\n" |
| 321 " $extra_interfaces$\n" |
| 322 " $classname$OrBuilder {\n"); |
| 323 builder_type = "com.google.protobuf.GeneratedMessage.Builder<?>"; |
| 339 } | 324 } |
| 340 printer->Indent(); | 325 printer->Indent(); |
| 341 // Using builder_type, instead of Builder, prevents the Builder class from | 326 // Using builder_type, instead of Builder, prevents the Builder class from |
| 342 // being loaded into PermGen space when the default instance is created. | 327 // being loaded into PermGen space when the default instance is created. |
| 343 // This optimizes the PermGen space usage for clients that do not modify | 328 // This optimizes the PermGen space usage for clients that do not modify |
| 344 // messages. | 329 // messages. |
| 345 printer->Print( | 330 printer->Print( |
| 346 "// Use $classname$.newBuilder() to construct.\n" | 331 "// Use $classname$.newBuilder() to construct.\n" |
| 347 "private $classname$($buildertype$ builder) {\n" | 332 "private $classname$($buildertype$ builder) {\n" |
| 348 " super(builder);\n" | 333 " super(builder);\n" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 .GetNumBitsForMessage(); | 387 .GetNumBitsForMessage(); |
| 403 } | 388 } |
| 404 int totalInts = (totalBits + 31) / 32; | 389 int totalInts = (totalBits + 31) / 32; |
| 405 for (int i = 0; i < totalInts; i++) { | 390 for (int i = 0; i < totalInts; i++) { |
| 406 printer->Print("private int $bit_field_name$;\n", | 391 printer->Print("private int $bit_field_name$;\n", |
| 407 "bit_field_name", GetBitFieldName(i)); | 392 "bit_field_name", GetBitFieldName(i)); |
| 408 } | 393 } |
| 409 } | 394 } |
| 410 | 395 |
| 411 // oneof | 396 // oneof |
| 412 std::map<string, string> vars; | 397 map<string, string> vars; |
| 413 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { | 398 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { |
| 414 vars["oneof_name"] = context_->GetOneofGeneratorInfo( | 399 vars["oneof_name"] = context_->GetOneofGeneratorInfo( |
| 415 descriptor_->oneof_decl(i))->name; | 400 descriptor_->oneof_decl(i))->name; |
| 416 vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( | 401 vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo( |
| 417 descriptor_->oneof_decl(i))->capitalized_name; | 402 descriptor_->oneof_decl(i))->capitalized_name; |
| 418 vars["oneof_index"] = SimpleItoa(descriptor_->oneof_decl(i)->index()); | 403 vars["oneof_index"] = SimpleItoa(descriptor_->oneof_decl(i)->index()); |
| 419 // oneofCase_ and oneof_ | 404 // oneofCase_ and oneof_ |
| 420 printer->Print(vars, | 405 printer->Print(vars, |
| 421 "private int $oneof_name$Case_ = 0;\n" | 406 "private int $oneof_name$Case_ = 0;\n" |
| 422 "private java.lang.Object $oneof_name$_;\n"); | 407 "private java.lang.Object $oneof_name$_;\n"); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 printer->Print("public static final int $constant_name$ = $number$;\n", | 478 printer->Print("public static final int $constant_name$ = $number$;\n", |
| 494 "constant_name", FieldConstantName(descriptor_->field(i)), | 479 "constant_name", FieldConstantName(descriptor_->field(i)), |
| 495 "number", SimpleItoa(descriptor_->field(i)->number())); | 480 "number", SimpleItoa(descriptor_->field(i)->number())); |
| 496 field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); | 481 field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); |
| 497 printer->Print("\n"); | 482 printer->Print("\n"); |
| 498 } | 483 } |
| 499 | 484 |
| 500 if (context_->HasGeneratedMethods(descriptor_)) { | 485 if (context_->HasGeneratedMethods(descriptor_)) { |
| 501 GenerateIsInitialized(printer); | 486 GenerateIsInitialized(printer); |
| 502 GenerateMessageSerializationMethods(printer); | 487 GenerateMessageSerializationMethods(printer); |
| 488 } |
| 489 |
| 490 if (HasEqualsAndHashCode(descriptor_)) { |
| 503 GenerateEqualsAndHashCode(printer); | 491 GenerateEqualsAndHashCode(printer); |
| 504 } | 492 } |
| 505 | 493 |
| 506 | 494 |
| 507 GenerateParseFromMethods(printer); | 495 GenerateParseFromMethods(printer); |
| 508 GenerateBuilder(printer); | 496 GenerateBuilder(printer); |
| 509 | 497 |
| 510 printer->Print( | 498 printer->Print( |
| 511 "\n" | 499 "\n" |
| 512 "// @@protoc_insertion_point(class_scope:$full_name$)\n", | 500 "// @@protoc_insertion_point(class_scope:$full_name$)\n", |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 542 } |
| 555 | 543 |
| 556 | 544 |
| 557 // =================================================================== | 545 // =================================================================== |
| 558 | 546 |
| 559 void ImmutableMessageGenerator:: | 547 void ImmutableMessageGenerator:: |
| 560 GenerateMessageSerializationMethods(io::Printer* printer) { | 548 GenerateMessageSerializationMethods(io::Printer* printer) { |
| 561 google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields( | 549 google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields( |
| 562 SortFieldsByNumber(descriptor_)); | 550 SortFieldsByNumber(descriptor_)); |
| 563 | 551 |
| 564 std::vector<const Descriptor::ExtensionRange*> sorted_extensions; | 552 vector<const Descriptor::ExtensionRange*> sorted_extensions; |
| 565 for (int i = 0; i < descriptor_->extension_range_count(); ++i) { | 553 for (int i = 0; i < descriptor_->extension_range_count(); ++i) { |
| 566 sorted_extensions.push_back(descriptor_->extension_range(i)); | 554 sorted_extensions.push_back(descriptor_->extension_range(i)); |
| 567 } | 555 } |
| 568 std::sort(sorted_extensions.begin(), sorted_extensions.end(), | 556 std::sort(sorted_extensions.begin(), sorted_extensions.end(), |
| 569 ExtensionRangeOrdering()); | 557 ExtensionRangeOrdering()); |
| 558 |
| 570 printer->Print( | 559 printer->Print( |
| 571 "public void writeTo(com.google.protobuf.CodedOutputStream output)\n" | 560 "public void writeTo(com.google.protobuf.CodedOutputStream output)\n" |
| 572 " throws java.io.IOException {\n"); | 561 " throws java.io.IOException {\n"); |
| 573 printer->Indent(); | 562 printer->Indent(); |
| 574 if (HasPackedFields(descriptor_)) { | 563 if (HasPackedFields(descriptor_)) { |
| 575 // writeTo(CodedOutputStream output) might be invoked without | 564 // writeTo(CodedOutputStream output) might be invoked without |
| 576 // getSerializedSize() ever being called, but we need the memoized | 565 // getSerializedSize() ever being called, but we need the memoized |
| 577 // sizes in case this message has packed fields. Rather than emit checks for | 566 // sizes in case this message has packed fields. Rather than emit checks for |
| 578 // each packed field, just call getSerializedSize() up front. | 567 // each packed field, just call getSerializedSize() up front. |
| 579 // In most cases, getSerializedSize() will have already been called anyway | 568 // In most cases, getSerializedSize() will have already been called anyway |
| 580 // by one of the wrapper writeTo() methods, making this call cheap. | 569 // by one of the wrapper writeTo() methods, making this call cheap. |
| 581 printer->Print( | 570 printer->Print( |
| 582 "getSerializedSize();\n"); | 571 "getSerializedSize();\n"); |
| 583 } | 572 } |
| 584 | 573 |
| 585 if (descriptor_->extension_range_count() > 0) { | 574 if (descriptor_->extension_range_count() > 0) { |
| 586 if (descriptor_->options().message_set_wire_format()) { | 575 if (descriptor_->options().message_set_wire_format()) { |
| 587 printer->Print( | 576 printer->Print( |
| 588 "com.google.protobuf.GeneratedMessage$ver$\n" | 577 "com.google.protobuf.GeneratedMessage\n" |
| 589 " .ExtendableMessage<$classname$>.ExtensionWriter\n" | 578 " .ExtendableMessage<$classname$>.ExtensionWriter\n" |
| 590 " extensionWriter = newMessageSetExtensionWriter();\n", | 579 " extensionWriter = newMessageSetExtensionWriter();\n", |
| 591 "classname", name_resolver_->GetImmutableClassName(descriptor_), | 580 "classname", name_resolver_->GetImmutableClassName(descriptor_)); |
| 592 "ver", GeneratedCodeVersionSuffix()); | |
| 593 } else { | 581 } else { |
| 594 printer->Print( | 582 printer->Print( |
| 595 "com.google.protobuf.GeneratedMessage$ver$\n" | 583 "com.google.protobuf.GeneratedMessage\n" |
| 596 " .ExtendableMessage<$classname$>.ExtensionWriter\n" | 584 " .ExtendableMessage<$classname$>.ExtensionWriter\n" |
| 597 " extensionWriter = newExtensionWriter();\n", | 585 " extensionWriter = newExtensionWriter();\n", |
| 598 "classname", name_resolver_->GetImmutableClassName(descriptor_), | 586 "classname", name_resolver_->GetImmutableClassName(descriptor_)); |
| 599 "ver", GeneratedCodeVersionSuffix()); | |
| 600 } | 587 } |
| 601 } | 588 } |
| 602 | 589 |
| 603 // Merge the fields and the extension ranges, both sorted by field number. | 590 // Merge the fields and the extension ranges, both sorted by field number. |
| 604 for (int i = 0, j = 0; | 591 for (int i = 0, j = 0; |
| 605 i < descriptor_->field_count() || j < sorted_extensions.size(); | 592 i < descriptor_->field_count() || j < sorted_extensions.size(); |
| 606 ) { | 593 ) { |
| 607 if (i == descriptor_->field_count()) { | 594 if (i == descriptor_->field_count()) { |
| 608 GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); | 595 GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); |
| 609 } else if (j == sorted_extensions.size()) { | 596 } else if (j == sorted_extensions.size()) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 " return PARSER.parseFrom(data);\n" | 680 " return PARSER.parseFrom(data);\n" |
| 694 "}\n" | 681 "}\n" |
| 695 "public static $classname$ parseFrom(\n" | 682 "public static $classname$ parseFrom(\n" |
| 696 " byte[] data,\n" | 683 " byte[] data,\n" |
| 697 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" | 684 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" |
| 698 " throws com.google.protobuf.InvalidProtocolBufferException {\n" | 685 " throws com.google.protobuf.InvalidProtocolBufferException {\n" |
| 699 " return PARSER.parseFrom(data, extensionRegistry);\n" | 686 " return PARSER.parseFrom(data, extensionRegistry);\n" |
| 700 "}\n" | 687 "}\n" |
| 701 "public static $classname$ parseFrom(java.io.InputStream input)\n" | 688 "public static $classname$ parseFrom(java.io.InputStream input)\n" |
| 702 " throws java.io.IOException {\n" | 689 " throws java.io.IOException {\n" |
| 703 " return com.google.protobuf.GeneratedMessage$ver$\n" | 690 " return com.google.protobuf.GeneratedMessage\n" |
| 704 " .parseWithIOException(PARSER, input);\n" | 691 " .parseWithIOException(PARSER, input);\n" |
| 705 "}\n" | 692 "}\n" |
| 706 "public static $classname$ parseFrom(\n" | 693 "public static $classname$ parseFrom(\n" |
| 707 " java.io.InputStream input,\n" | 694 " java.io.InputStream input,\n" |
| 708 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" | 695 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" |
| 709 " throws java.io.IOException {\n" | 696 " throws java.io.IOException {\n" |
| 710 " return com.google.protobuf.GeneratedMessage$ver$\n" | 697 " return com.google.protobuf.GeneratedMessage\n" |
| 711 " .parseWithIOException(PARSER, input, extensionRegistry);\n" | 698 " .parseWithIOException(PARSER, input, extensionRegistry);\n" |
| 712 "}\n" | 699 "}\n" |
| 713 "public static $classname$ parseDelimitedFrom(java.io.InputStream input)\n" | 700 "public static $classname$ parseDelimitedFrom(java.io.InputStream input)\n" |
| 714 " throws java.io.IOException {\n" | 701 " throws java.io.IOException {\n" |
| 715 " return com.google.protobuf.GeneratedMessage$ver$\n" | 702 " return com.google.protobuf.GeneratedMessage\n" |
| 716 " .parseDelimitedWithIOException(PARSER, input);\n" | 703 " .parseDelimitedWithIOException(PARSER, input);\n" |
| 717 "}\n" | 704 "}\n" |
| 718 "public static $classname$ parseDelimitedFrom(\n" | 705 "public static $classname$ parseDelimitedFrom(\n" |
| 719 " java.io.InputStream input,\n" | 706 " java.io.InputStream input,\n" |
| 720 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" | 707 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" |
| 721 " throws java.io.IOException {\n" | 708 " throws java.io.IOException {\n" |
| 722 " return com.google.protobuf.GeneratedMessage$ver$\n" | 709 " return com.google.protobuf.GeneratedMessage\n" |
| 723 " .parseDelimitedWithIOException(PARSER, input, extensionRegistry);\n" | 710 " .parseDelimitedWithIOException(PARSER, input, extensionRegistry);\n" |
| 724 "}\n" | 711 "}\n" |
| 725 "public static $classname$ parseFrom(\n" | 712 "public static $classname$ parseFrom(\n" |
| 726 " com.google.protobuf.CodedInputStream input)\n" | 713 " com.google.protobuf.CodedInputStream input)\n" |
| 727 " throws java.io.IOException {\n" | 714 " throws java.io.IOException {\n" |
| 728 " return com.google.protobuf.GeneratedMessage$ver$\n" | 715 " return com.google.protobuf.GeneratedMessage\n" |
| 729 " .parseWithIOException(PARSER, input);\n" | 716 " .parseWithIOException(PARSER, input);\n" |
| 730 "}\n" | 717 "}\n" |
| 731 "public static $classname$ parseFrom(\n" | 718 "public static $classname$ parseFrom(\n" |
| 732 " com.google.protobuf.CodedInputStream input,\n" | 719 " com.google.protobuf.CodedInputStream input,\n" |
| 733 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" | 720 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" |
| 734 " throws java.io.IOException {\n" | 721 " throws java.io.IOException {\n" |
| 735 " return com.google.protobuf.GeneratedMessage$ver$\n" | 722 " return com.google.protobuf.GeneratedMessage\n" |
| 736 " .parseWithIOException(PARSER, input, extensionRegistry);\n" | 723 " .parseWithIOException(PARSER, input, extensionRegistry);\n" |
| 737 "}\n" | 724 "}\n" |
| 738 "\n", | 725 "\n", |
| 739 "classname", name_resolver_->GetImmutableClassName(descriptor_), | 726 "classname", name_resolver_->GetImmutableClassName(descriptor_)); |
| 740 "ver", GeneratedCodeVersionSuffix()); | |
| 741 } | 727 } |
| 742 | 728 |
| 743 void ImmutableMessageGenerator::GenerateSerializeOneField( | 729 void ImmutableMessageGenerator::GenerateSerializeOneField( |
| 744 io::Printer* printer, const FieldDescriptor* field) { | 730 io::Printer* printer, const FieldDescriptor* field) { |
| 745 field_generators_.get(field).GenerateSerializationCode(printer); | 731 field_generators_.get(field).GenerateSerializationCode(printer); |
| 746 } | 732 } |
| 747 | 733 |
| 748 void ImmutableMessageGenerator::GenerateSerializeOneExtensionRange( | 734 void ImmutableMessageGenerator::GenerateSerializeOneExtensionRange( |
| 749 io::Printer* printer, const Descriptor::ExtensionRange* range) { | 735 io::Printer* printer, const Descriptor::ExtensionRange* range) { |
| 750 printer->Print( | 736 printer->Print( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 769 "public Builder toBuilder() {\n" | 755 "public Builder toBuilder() {\n" |
| 770 " return this == DEFAULT_INSTANCE\n" | 756 " return this == DEFAULT_INSTANCE\n" |
| 771 " ? new Builder() : new Builder().mergeFrom(this);\n" | 757 " ? new Builder() : new Builder().mergeFrom(this);\n" |
| 772 "}\n" | 758 "}\n" |
| 773 "\n", | 759 "\n", |
| 774 "classname", name_resolver_->GetImmutableClassName(descriptor_)); | 760 "classname", name_resolver_->GetImmutableClassName(descriptor_)); |
| 775 | 761 |
| 776 printer->Print( | 762 printer->Print( |
| 777 "@java.lang.Override\n" | 763 "@java.lang.Override\n" |
| 778 "protected Builder newBuilderForType(\n" | 764 "protected Builder newBuilderForType(\n" |
| 779 " com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n" | 765 " com.google.protobuf.GeneratedMessage.BuilderParent parent) {\n" |
| 780 " Builder builder = new Builder(parent);\n" | 766 " Builder builder = new Builder(parent);\n" |
| 781 " return builder;\n" | 767 " return builder;\n" |
| 782 "}\n", | 768 "}\n"); |
| 783 "ver", GeneratedCodeVersionSuffix()); | |
| 784 | 769 |
| 785 MessageBuilderGenerator builderGenerator(descriptor_, context_); | 770 MessageBuilderGenerator builderGenerator(descriptor_, context_); |
| 786 builderGenerator.Generate(printer); | 771 builderGenerator.Generate(printer); |
| 787 } | 772 } |
| 788 | 773 |
| 789 void ImmutableMessageGenerator:: | 774 void ImmutableMessageGenerator:: |
| 790 GenerateDescriptorMethods(io::Printer* printer) { | 775 GenerateDescriptorMethods(io::Printer* printer) { |
| 791 if (!descriptor_->options().no_standard_descriptor_accessor()) { | 776 if (!descriptor_->options().no_standard_descriptor_accessor()) { |
| 792 printer->Print( | 777 printer->Print( |
| 793 "public static final com.google.protobuf.Descriptors.Descriptor\n" | 778 "public static final com.google.protobuf.Descriptors.Descriptor\n" |
| 794 " getDescriptor() {\n" | 779 " getDescriptor() {\n" |
| 795 " return $fileclass$.internal_$identifier$_descriptor;\n" | 780 " return $fileclass$.internal_$identifier$_descriptor;\n" |
| 796 "}\n" | 781 "}\n" |
| 797 "\n", | 782 "\n", |
| 798 "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), | 783 "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), |
| 799 "identifier", UniqueFileScopeIdentifier(descriptor_)); | 784 "identifier", UniqueFileScopeIdentifier(descriptor_)); |
| 800 } | 785 } |
| 801 std::vector<const FieldDescriptor*> map_fields; | 786 vector<const FieldDescriptor*> map_fields; |
| 802 for (int i = 0; i < descriptor_->field_count(); i++) { | 787 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 803 const FieldDescriptor* field = descriptor_->field(i); | 788 const FieldDescriptor* field = descriptor_->field(i); |
| 804 if (GetJavaType(field) == JAVATYPE_MESSAGE && | 789 if (GetJavaType(field) == JAVATYPE_MESSAGE && |
| 805 IsMapEntry(field->message_type())) { | 790 IsMapEntry(field->message_type())) { |
| 806 map_fields.push_back(field); | 791 map_fields.push_back(field); |
| 807 } | 792 } |
| 808 } | 793 } |
| 809 if (!map_fields.empty()) { | 794 if (!map_fields.empty()) { |
| 810 printer->Print( | 795 printer->Print( |
| 811 "@SuppressWarnings({\"rawtypes\"})\n" | 796 "@SuppressWarnings({\"rawtypes\"})\n" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 827 "default:\n" | 812 "default:\n" |
| 828 " throw new RuntimeException(\n" | 813 " throw new RuntimeException(\n" |
| 829 " \"Invalid map field number: \" + number);\n"); | 814 " \"Invalid map field number: \" + number);\n"); |
| 830 printer->Outdent(); | 815 printer->Outdent(); |
| 831 printer->Outdent(); | 816 printer->Outdent(); |
| 832 printer->Print( | 817 printer->Print( |
| 833 " }\n" | 818 " }\n" |
| 834 "}\n"); | 819 "}\n"); |
| 835 } | 820 } |
| 836 printer->Print( | 821 printer->Print( |
| 837 "protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" | 822 "protected com.google.protobuf.GeneratedMessage.FieldAccessorTable\n" |
| 838 " internalGetFieldAccessorTable() {\n" | 823 " internalGetFieldAccessorTable() {\n" |
| 839 " return $fileclass$.internal_$identifier$_fieldAccessorTable\n" | 824 " return $fileclass$.internal_$identifier$_fieldAccessorTable\n" |
| 840 " .ensureFieldAccessorsInitialized(\n" | 825 " .ensureFieldAccessorsInitialized(\n" |
| 841 " $classname$.class, $classname$.Builder.class);\n" | 826 " $classname$.class, $classname$.Builder.class);\n" |
| 842 "}\n" | 827 "}\n" |
| 843 "\n", | 828 "\n", |
| 844 "classname", name_resolver_->GetImmutableClassName(descriptor_), | 829 "classname", name_resolver_->GetImmutableClassName(descriptor_), |
| 845 "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), | 830 "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), |
| 846 "identifier", UniqueFileScopeIdentifier(descriptor_), | 831 "identifier", UniqueFileScopeIdentifier(descriptor_)); |
| 847 "ver", GeneratedCodeVersionSuffix()); | |
| 848 } | 832 } |
| 849 | 833 |
| 850 // =================================================================== | 834 // =================================================================== |
| 851 | 835 |
| 852 void ImmutableMessageGenerator::GenerateIsInitialized( | 836 void ImmutableMessageGenerator::GenerateIsInitialized( |
| 853 io::Printer* printer) { | 837 io::Printer* printer) { |
| 854 // Memoizes whether the protocol buffer is fully initialized (has all | 838 // Memoizes whether the protocol buffer is fully initialized (has all |
| 855 // required fields). -1 means not yet computed. 0 means false and 1 means | 839 // required fields). -1 means not yet computed. 0 means false and 1 means |
| 856 // true. | 840 // true. |
| 857 printer->Print( | 841 printer->Print( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 " if (!get$name$().isInitialized()) {\n" | 904 " if (!get$name$().isInitialized()) {\n" |
| 921 " memoizedIsInitialized = 0;\n" | 905 " memoizedIsInitialized = 0;\n" |
| 922 " return false;\n" | 906 " return false;\n" |
| 923 " }\n" | 907 " }\n" |
| 924 "}\n", | 908 "}\n", |
| 925 "name", info->capitalized_name); | 909 "name", info->capitalized_name); |
| 926 break; | 910 break; |
| 927 case FieldDescriptor::LABEL_REPEATED: | 911 case FieldDescriptor::LABEL_REPEATED: |
| 928 if (IsMapEntry(field->message_type())) { | 912 if (IsMapEntry(field->message_type())) { |
| 929 printer->Print( | 913 printer->Print( |
| 930 "for ($type$ item : get$name$Map().values()) {\n" | 914 "for ($type$ item : get$name$().values()) {\n" |
| 931 " if (!item.isInitialized()) {\n" | 915 " if (!item.isInitialized()) {\n" |
| 932 " memoizedIsInitialized = 0;\n" | 916 " memoizedIsInitialized = 0;\n" |
| 933 " return false;\n" | 917 " return false;\n" |
| 934 " }\n" | 918 " }\n" |
| 935 "}\n", | 919 "}\n", |
| 936 "type", MapValueImmutableClassdName(field->message_type(), | 920 "type", MapValueImmutableClassdName(field->message_type(), |
| 937 name_resolver_), | 921 name_resolver_), |
| 938 "name", info->capitalized_name); | 922 "name", info->capitalized_name); |
| 939 } else { | 923 } else { |
| 940 printer->Print( | 924 printer->Print( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 printer->Print( | 1069 printer->Print( |
| 1086 "if (memoizedHashCode != 0) {\n"); | 1070 "if (memoizedHashCode != 0) {\n"); |
| 1087 printer->Indent(); | 1071 printer->Indent(); |
| 1088 printer->Print( | 1072 printer->Print( |
| 1089 "return memoizedHashCode;\n"); | 1073 "return memoizedHashCode;\n"); |
| 1090 printer->Outdent(); | 1074 printer->Outdent(); |
| 1091 printer->Print( | 1075 printer->Print( |
| 1092 "}\n" | 1076 "}\n" |
| 1093 "int hash = 41;\n"); | 1077 "int hash = 41;\n"); |
| 1094 | 1078 |
| 1095 // If we output a getDescriptor() method, use that as it is more efficient. | 1079 printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n"); |
| 1096 if (descriptor_->options().no_standard_descriptor_accessor()) { | |
| 1097 printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n"); | |
| 1098 } else { | |
| 1099 printer->Print("hash = (19 * hash) + getDescriptor().hashCode();\n"); | |
| 1100 } | |
| 1101 | 1080 |
| 1102 // hashCode non-oneofs. | 1081 // hashCode non-oneofs. |
| 1103 for (int i = 0; i < descriptor_->field_count(); i++) { | 1082 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 1104 const FieldDescriptor* field = descriptor_->field(i); | 1083 const FieldDescriptor* field = descriptor_->field(i); |
| 1105 if (field->containing_oneof() == NULL) { | 1084 if (field->containing_oneof() == NULL) { |
| 1106 const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); | 1085 const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); |
| 1107 bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field); | 1086 bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field); |
| 1108 if (check_has_bits) { | 1087 if (check_has_bits) { |
| 1109 printer->Print( | 1088 printer->Print( |
| 1110 "if (has$name$()) {\n", | 1089 "if (has$name$()) {\n", |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 " extensionRegistry, tag)) {\n" | 1218 " extensionRegistry, tag)) {\n" |
| 1240 " done = true;\n" // it's an endgroup tag | 1219 " done = true;\n" // it's an endgroup tag |
| 1241 " }\n" | 1220 " }\n" |
| 1242 " break;\n" | 1221 " break;\n" |
| 1243 "}\n"); | 1222 "}\n"); |
| 1244 } else { | 1223 } else { |
| 1245 printer->Print( | 1224 printer->Print( |
| 1246 "default: {\n" | 1225 "default: {\n" |
| 1247 " if (!input.skipField(tag)) {\n" | 1226 " if (!input.skipField(tag)) {\n" |
| 1248 " done = true;\n" // it's an endgroup tag | 1227 " done = true;\n" // it's an endgroup tag |
| 1249 " }\n" | 1228 " }\n"); |
| 1229 printer->Print( |
| 1250 " break;\n" | 1230 " break;\n" |
| 1251 "}\n"); | 1231 "}\n"); |
| 1252 } | 1232 } |
| 1253 | 1233 |
| 1254 for (int i = 0; i < descriptor_->field_count(); i++) { | 1234 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 1255 const FieldDescriptor* field = sorted_fields[i]; | 1235 const FieldDescriptor* field = sorted_fields[i]; |
| 1256 uint32 tag = WireFormatLite::MakeTag(field->number(), | 1236 uint32 tag = WireFormatLite::MakeTag(field->number(), |
| 1257 WireFormat::WireTypeForFieldType(field->type())); | 1237 WireFormat::WireTypeForFieldType(field->type())); |
| 1258 | 1238 |
| 1259 printer->Print( | 1239 printer->Print( |
| 1260 "case $tag$: {\n", | 1240 "case $tag$: {\n", |
| 1261 "tag", SimpleItoa(static_cast<int32>(tag))); | 1241 "tag", SimpleItoa(tag)); |
| 1262 printer->Indent(); | 1242 printer->Indent(); |
| 1263 | 1243 |
| 1264 field_generators_.get(field).GenerateParsingCode(printer); | 1244 field_generators_.get(field).GenerateParsingCode(printer); |
| 1265 | 1245 |
| 1266 printer->Outdent(); | 1246 printer->Outdent(); |
| 1267 printer->Print( | 1247 printer->Print( |
| 1268 " break;\n" | 1248 " break;\n" |
| 1269 "}\n"); | 1249 "}\n"); |
| 1270 | 1250 |
| 1271 if (field->is_packable()) { | 1251 if (field->is_packable()) { |
| 1272 // To make packed = true wire compatible, we generate parsing code from a | 1252 // To make packed = true wire compatible, we generate parsing code from a |
| 1273 // packed version of this field regardless of field->options().packed(). | 1253 // packed version of this field regardless of field->options().packed(). |
| 1274 uint32 packed_tag = WireFormatLite::MakeTag(field->number(), | 1254 uint32 packed_tag = WireFormatLite::MakeTag(field->number(), |
| 1275 WireFormatLite::WIRETYPE_LENGTH_DELIMITED); | 1255 WireFormatLite::WIRETYPE_LENGTH_DELIMITED); |
| 1276 printer->Print( | 1256 printer->Print( |
| 1277 "case $tag$: {\n", | 1257 "case $tag$: {\n", |
| 1278 "tag", SimpleItoa(static_cast<int32>(packed_tag))); | 1258 "tag", SimpleItoa(packed_tag)); |
| 1279 printer->Indent(); | 1259 printer->Indent(); |
| 1280 | 1260 |
| 1281 field_generators_.get(field).GenerateParsingCodeFromPacked(printer); | 1261 field_generators_.get(field).GenerateParsingCodeFromPacked(printer); |
| 1282 | 1262 |
| 1283 printer->Outdent(); | 1263 printer->Outdent(); |
| 1284 printer->Print( | 1264 printer->Print( |
| 1285 " break;\n" | 1265 " break;\n" |
| 1286 "}\n"); | 1266 "}\n"); |
| 1287 } | 1267 } |
| 1288 } | 1268 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 "public static <T extends com.google.protobuf.Message> Any pack(\n" | 1394 "public static <T extends com.google.protobuf.Message> Any pack(\n" |
| 1415 " T message) {\n" | 1395 " T message) {\n" |
| 1416 " return Any.newBuilder()\n" | 1396 " return Any.newBuilder()\n" |
| 1417 " .setTypeUrl(getTypeUrl(\"type.googleapis.com\",\n" | 1397 " .setTypeUrl(getTypeUrl(\"type.googleapis.com\",\n" |
| 1418 " message.getDescriptorForType()))\n" | 1398 " message.getDescriptorForType()))\n" |
| 1419 " .setValue(message.toByteString())\n" | 1399 " .setValue(message.toByteString())\n" |
| 1420 " .build();\n" | 1400 " .build();\n" |
| 1421 "}\n" | 1401 "}\n" |
| 1422 "\n" | 1402 "\n" |
| 1423 "/**\n" | 1403 "/**\n" |
| 1424 " * Packs a message using the given type URL prefix. The type URL will\n" | 1404 " * Packs a message uisng the given type URL prefix. The type URL will\n" |
| 1425 " * be constructed by concatenating the message type's full name to the\n" | 1405 " * be constructed by concatenating the message type's full name to the\n" |
| 1426 " * prefix with an optional \"/\" separator if the prefix doesn't end\n" | 1406 " * prefix with an optional \"/\" separator if the prefix doesn't end\n" |
| 1427 " * with \"/\" already.\n" | 1407 " * with \"/\" already.\n" |
| 1428 " */\n" | 1408 " */\n" |
| 1429 "public static <T extends com.google.protobuf.Message> Any pack(\n" | 1409 "public static <T extends com.google.protobuf.Message> Any pack(\n" |
| 1430 " T message, java.lang.String typeUrlPrefix) {\n" | 1410 " T message, java.lang.String typeUrlPrefix) {\n" |
| 1431 " return Any.newBuilder()\n" | 1411 " return Any.newBuilder()\n" |
| 1432 " .setTypeUrl(getTypeUrl(typeUrlPrefix,\n" | 1412 " .setTypeUrl(getTypeUrl(typeUrlPrefix,\n" |
| 1433 " message.getDescriptorForType()))\n" | 1413 " message.getDescriptorForType()))\n" |
| 1434 " .setValue(message.toByteString())\n" | 1414 " .setValue(message.toByteString())\n" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1461 " .parseFrom(getValue());\n" | 1441 " .parseFrom(getValue());\n" |
| 1462 " cachedUnpackValue = result;\n" | 1442 " cachedUnpackValue = result;\n" |
| 1463 " return result;\n" | 1443 " return result;\n" |
| 1464 "}\n"); | 1444 "}\n"); |
| 1465 } | 1445 } |
| 1466 | 1446 |
| 1467 } // namespace java | 1447 } // namespace java |
| 1468 } // namespace compiler | 1448 } // namespace compiler |
| 1469 } // namespace protobuf | 1449 } // namespace protobuf |
| 1470 } // namespace google | 1450 } // namespace google |
| OLD | NEW |