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