protobuf/src/google/protobuf/compiler/java/java_message.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34 
35 #include <google/protobuf/compiler/java/java_message.h>
36 
37 #include <algorithm>
38 #include <cstdint>
39 #include <map>
40 #include <memory>
41 #include <vector>
42 
43 #include <google/protobuf/compiler/java/java_context.h>
44 #include <google/protobuf/compiler/java/java_doc_comment.h>
45 #include <google/protobuf/compiler/java/java_enum.h>
46 #include <google/protobuf/compiler/java/java_extension.h>
47 #include <google/protobuf/compiler/java/java_generator_factory.h>
48 #include <google/protobuf/compiler/java/java_helpers.h>
49 #include <google/protobuf/compiler/java/java_message_builder.h>
50 #include <google/protobuf/compiler/java/java_message_builder_lite.h>
51 #include <google/protobuf/compiler/java/java_name_resolver.h>
52 #include <google/protobuf/descriptor.pb.h>
53 #include <google/protobuf/io/coded_stream.h>
54 #include <google/protobuf/io/printer.h>
55 #include <google/protobuf/wire_format.h>
56 #include <google/protobuf/stubs/strutil.h>
57 #include <google/protobuf/stubs/substitute.h>
58 
59 namespace google {
60 namespace protobuf {
61 namespace compiler {
62 namespace java {
63 
64 using internal::WireFormat;
65 using internal::WireFormatLite;
66 
67 namespace {
68 std::string MapValueImmutableClassdName(const Descriptor* descriptor,
69  ClassNameResolver* name_resolver) {
70  const FieldDescriptor* value_field = descriptor->FindFieldByName("value");
71  GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type());
72  return name_resolver->GetImmutableClassName(value_field->message_type());
73 }
74 } // namespace
75 
76 // ===================================================================
77 
80  for (int i = 0; i < descriptor_->field_count(); i++) {
81  if (IsRealOneof(descriptor_->field(i))) {
83  }
84  }
85 }
86 
88 
89 // ===================================================================
91  const Descriptor* descriptor, Context* context)
92  : MessageGenerator(descriptor),
94  name_resolver_(context->GetNameResolver()),
95  field_generators_(descriptor, context_) {
96  GOOGLE_CHECK(HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
97  << "Generator factory error: A non-lite message generator is used to "
98  "generate lite messages.";
99 }
100 
102 
104  io::Printer* printer, int* bytecode_estimate) {
105  // Because descriptor.proto (com.google.protobuf.DescriptorProtos) is
106  // used in the construction of descriptors, we have a tricky bootstrapping
107  // problem. To help control static initialization order, we make sure all
108  // descriptors and other static data that depends on them are members of
109  // the outermost class in the file. This way, they will be initialized in
110  // a deterministic order.
111 
112  std::map<std::string, std::string> vars;
113  vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
114  vars["index"] = StrCat(descriptor_->index());
115  vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
116  if (descriptor_->containing_type() != NULL) {
118  }
119  if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) {
120  // We can only make these package-private since the classes that use them
121  // are in separate files.
122  vars["private"] = "";
123  } else {
124  vars["private"] = "private ";
125  }
126  if (*bytecode_estimate <= kMaxStaticSize) {
127  vars["final"] = "final ";
128  } else {
129  vars["final"] = "";
130  }
131 
132  // The descriptor for this type.
133  printer->Print(
134  vars,
135  // TODO(teboring): final needs to be added back. The way to fix it is to
136  // generate methods that can construct the types, and then still declare
137  // the types, and then init them in clinit with the new method calls.
138  "$private$static $final$com.google.protobuf.Descriptors.Descriptor\n"
139  " internal_$identifier$_descriptor;\n");
140  *bytecode_estimate += 30;
141 
142  // And the FieldAccessorTable.
143  GenerateFieldAccessorTable(printer, bytecode_estimate);
144 
145  // Generate static members for all nested types.
146  for (int i = 0; i < descriptor_->nested_type_count(); i++) {
147  // TODO(kenton): Reuse MessageGenerator objects?
149  .GenerateStaticVariables(printer, bytecode_estimate);
150  }
151 }
152 
154  io::Printer* printer) {
155  int bytecode_estimate = 0;
156  std::map<std::string, std::string> vars;
157  vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
158  vars["index"] = StrCat(descriptor_->index());
159  vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
160  if (descriptor_->containing_type() != NULL) {
162  }
163 
164  // The descriptor for this type.
165  if (descriptor_->containing_type() == NULL) {
166  printer->Print(vars,
167  "internal_$identifier$_descriptor =\n"
168  " getDescriptor().getMessageTypes().get($index$);\n");
169  bytecode_estimate += 30;
170  } else {
171  printer->Print(
172  vars,
173  "internal_$identifier$_descriptor =\n"
174  " internal_$parent$_descriptor.getNestedTypes().get($index$);\n");
175  bytecode_estimate += 30;
176  }
177 
178  // And the FieldAccessorTable.
179  bytecode_estimate += GenerateFieldAccessorTableInitializer(printer);
180 
181  // Generate static member initializers for all nested types.
182  for (int i = 0; i < descriptor_->nested_type_count(); i++) {
183  // TODO(kenton): Reuse MessageGenerator objects?
184  bytecode_estimate +=
186  .GenerateStaticVariableInitializers(printer);
187  }
188  return bytecode_estimate;
189 }
190 
192  io::Printer* printer, int* bytecode_estimate) {
193  std::map<std::string, std::string> vars;
194  vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
195  if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) {
196  // We can only make these package-private since the classes that use them
197  // are in separate files.
198  vars["private"] = "";
199  } else {
200  vars["private"] = "private ";
201  }
202  if (*bytecode_estimate <= kMaxStaticSize) {
203  vars["final"] = "final ";
204  } else {
205  vars["final"] = "";
206  }
207  vars["ver"] = GeneratedCodeVersionSuffix();
208  printer->Print(
209  vars,
210  "$private$static $final$\n"
211  " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n"
212  " internal_$identifier$_fieldAccessorTable;\n");
213 
214  // The following bytecode_estimate calculation logic must stay in sync with
215  // the similar logic in the GenerateFieldAccessorTableInitializer method below
216  // to make sure that the generated static final fields are initialized in the
217  // static initialization block directly.
218  //
219  // 6 bytes per field and oneof
220  *bytecode_estimate +=
222 }
223 
225  io::Printer* printer) {
226  int bytecode_estimate = 10;
227  printer->Print(
228  "internal_$identifier$_fieldAccessorTable = new\n"
229  " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable(\n"
230  " internal_$identifier$_descriptor,\n"
231  " new java.lang.String[] { ",
232  "identifier", UniqueFileScopeIdentifier(descriptor_), "ver",
234  // All the bytecode_estimate calculation logic in this method must stay in
235  // sync with the similar logic in the GenerateFieldAccessorTable method
236  // above. See the corresponding comment in GenerateFieldAccessorTable for
237  // details.
238  for (int i = 0; i < descriptor_->field_count(); i++) {
239  const FieldDescriptor* field = descriptor_->field(i);
240  const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
241  bytecode_estimate += 6;
242  printer->Print("\"$field_name$\", ", "field_name", info->capitalized_name);
243  }
244  // We reproduce synthetic oneofs here since proto reflection needs these.
245  for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
246  const OneofDescriptor* oneof = descriptor_->oneof_decl(i);
247  const OneofGeneratorInfo* info = context_->GetOneofGeneratorInfo(oneof);
248  bytecode_estimate += 6;
249  printer->Print("\"$oneof_name$\", ", "oneof_name", info->capitalized_name);
250  }
251  printer->Print("});\n");
252  return bytecode_estimate;
253 }
254 
255 // ===================================================================
256 
259  /* immutable = */ true, "OrBuilder");
260  if (descriptor_->extension_range_count() > 0) {
261  printer->Print(
262  "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
263  " $extra_interfaces$\n"
264  " com.google.protobuf.GeneratedMessage$ver$.\n"
265  " ExtendableMessageOrBuilder<$classname$> {\n",
266  "deprecation",
267  descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "",
268  "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
269  "classname", descriptor_->name(), "{", "", "}", "", "ver",
271  } else {
272  printer->Print(
273  "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
274  " $extra_interfaces$\n"
275  " com.google.protobuf.MessageOrBuilder {\n",
276  "deprecation",
277  descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "",
278  "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
279  "classname", descriptor_->name(), "{", "", "}", "");
280  }
281  printer->Annotate("{", "}", descriptor_);
282 
283  printer->Indent();
284  for (int i = 0; i < descriptor_->field_count(); i++) {
285  printer->Print("\n");
287  .GenerateInterfaceMembers(printer);
288  }
289  for (auto oneof : oneofs_) {
290  printer->Print(
291  "\n"
292  "public $classname$.$oneof_capitalized_name$Case "
293  "get$oneof_capitalized_name$Case();\n",
294  "oneof_capitalized_name",
295  context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname",
297  }
298  printer->Outdent();
299 
300  printer->Print("}\n");
301 }
302 
303 // ===================================================================
304 
306  bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
307 
308  std::map<std::string, std::string> variables;
309  variables["static"] = is_own_file ? "" : "static ";
310  variables["classname"] = descriptor_->name();
311  variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
312  variables["ver"] = GeneratedCodeVersionSuffix();
313  variables["deprecation"] =
314  descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "";
315 
318  /* immutable = */ true);
319  // The builder_type stores the super type name of the nested Builder class.
320  std::string builder_type;
321  if (descriptor_->extension_range_count() > 0) {
322  printer->Print(
323  variables,
324  "$deprecation$public $static$final class $classname$ extends\n");
325  printer->Annotate("classname", descriptor_);
326  printer->Print(
327  variables,
328  " com.google.protobuf.GeneratedMessage$ver$.ExtendableMessage<\n"
329  " $classname$> implements\n"
330  " $extra_interfaces$\n"
331  " $classname$OrBuilder {\n");
332  builder_type = strings::Substitute(
333  "com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>",
336  } else {
337  printer->Print(
338  variables,
339  "$deprecation$public $static$final class $classname$ extends\n");
340  printer->Annotate("classname", descriptor_);
341  printer->Print(variables,
342  " com.google.protobuf.GeneratedMessage$ver$ implements\n"
343  " $extra_interfaces$\n"
344  " $classname$OrBuilder {\n");
345  builder_type =
346  strings::Substitute("com.google.protobuf.GeneratedMessage$0.Builder<?>",
348  }
349  printer->Print("private static final long serialVersionUID = 0L;\n");
350 
351  printer->Indent();
352  // Using builder_type, instead of Builder, prevents the Builder class from
353  // being loaded into PermGen space when the default instance is created.
354  // This optimizes the PermGen space usage for clients that do not modify
355  // messages.
356  printer->Print(
357  "// Use $classname$.newBuilder() to construct.\n"
358  "private $classname$($buildertype$ builder) {\n"
359  " super(builder);\n"
360  "}\n",
361  "classname", descriptor_->name(), "buildertype", builder_type);
362  printer->Print("private $classname$() {\n", "classname", descriptor_->name());
363  printer->Indent();
364  GenerateInitializers(printer);
365  printer->Outdent();
366  printer->Print(
367  "}\n"
368  "\n");
369 
370  printer->Print(variables,
371  "@java.lang.Override\n"
372  "@SuppressWarnings({\"unused\"})\n"
373  "protected java.lang.Object newInstance(\n"
374  " UnusedPrivateParameter unused) {\n"
375  " return new $classname$();\n"
376  "}\n"
377  "\n");
378 
379  printer->Print(
380  "@java.lang.Override\n"
381  "public final com.google.protobuf.UnknownFieldSet\n"
382  "getUnknownFields() {\n"
383  " return this.unknownFields;\n"
384  "}\n");
385 
388  }
389 
390  GenerateDescriptorMethods(printer);
391 
392  // Nested types
393  for (int i = 0; i < descriptor_->enum_type_count(); i++) {
394  EnumGenerator(descriptor_->enum_type(i), true, context_).Generate(printer);
395  }
396 
397  for (int i = 0; i < descriptor_->nested_type_count(); i++) {
398  // Don't generate Java classes for map entry messages.
399  if (IsMapEntry(descriptor_->nested_type(i))) continue;
401  context_);
402  messageGenerator.GenerateInterface(printer);
403  messageGenerator.Generate(printer);
404  }
405 
406  // Integers for bit fields.
407  int totalBits = 0;
408  for (int i = 0; i < descriptor_->field_count(); i++) {
409  totalBits +=
410  field_generators_.get(descriptor_->field(i)).GetNumBitsForMessage();
411  }
412  int totalInts = (totalBits + 31) / 32;
413  for (int i = 0; i < totalInts; i++) {
414  printer->Print("private int $bit_field_name$;\n", "bit_field_name",
415  GetBitFieldName(i));
416  }
417 
418  // oneof
419  std::map<std::string, std::string> vars;
420  for (auto oneof : oneofs_) {
421  vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
422  vars["oneof_capitalized_name"] =
424  vars["oneof_index"] = StrCat((oneof)->index());
425  // oneofCase_ and oneof_
426  printer->Print(vars,
427  "private int $oneof_name$Case_ = 0;\n"
428  "private java.lang.Object $oneof_name$_;\n");
429  // OneofCase enum
430  printer->Print(
431  vars,
432  "public enum $oneof_capitalized_name$Case\n"
433  // TODO(dweis): Remove EnumLite when we want to break compatibility with
434  // 3.x users
435  " implements com.google.protobuf.Internal.EnumLite,\n"
436  " com.google.protobuf.AbstractMessage.InternalOneOfEnum {\n");
437  printer->Indent();
438  for (int j = 0; j < (oneof)->field_count(); j++) {
439  const FieldDescriptor* field = (oneof)->field(j);
440  printer->Print(
441  "$deprecation$$field_name$($field_number$),\n", "deprecation",
442  field->options().deprecated() ? "@java.lang.Deprecated " : "",
443  "field_name", ToUpper(field->name()), "field_number",
444  StrCat(field->number()));
445  }
446  printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name",
447  ToUpper(vars["oneof_name"]));
448  printer->Print(vars,
449  "private final int value;\n"
450  "private $oneof_capitalized_name$Case(int value) {\n"
451  " this.value = value;\n"
452  "}\n");
453  printer->Print(
454  vars,
455  "/**\n"
456  " * @param value The number of the enum to look for.\n"
457  " * @return The enum associated with the given number.\n"
458  " * @deprecated Use {@link #forNumber(int)} instead.\n"
459  " */\n"
460  "@java.lang.Deprecated\n"
461  "public static $oneof_capitalized_name$Case valueOf(int value) {\n"
462  " return forNumber(value);\n"
463  "}\n"
464  "\n"
465  "public static $oneof_capitalized_name$Case forNumber(int value) {\n"
466  " switch (value) {\n");
467  for (int j = 0; j < (oneof)->field_count(); j++) {
468  const FieldDescriptor* field = (oneof)->field(j);
469  printer->Print(" case $field_number$: return $field_name$;\n",
470  "field_number", StrCat(field->number()),
471  "field_name", ToUpper(field->name()));
472  }
473  printer->Print(
474  " case 0: return $cap_oneof_name$_NOT_SET;\n"
475  " default: return null;\n"
476  " }\n"
477  "}\n"
478  "public int getNumber() {\n"
479  " return this.value;\n"
480  "}\n",
481  "cap_oneof_name", ToUpper(vars["oneof_name"]));
482  printer->Outdent();
483  printer->Print("};\n\n");
484  // oneofCase()
485  printer->Print(vars,
486  "public $oneof_capitalized_name$Case\n"
487  "get$oneof_capitalized_name$Case() {\n"
488  " return $oneof_capitalized_name$Case.forNumber(\n"
489  " $oneof_name$Case_);\n"
490  "}\n"
491  "\n");
492  }
493 
494  if (IsAnyMessage(descriptor_)) {
495  GenerateAnyMethods(printer);
496  }
497 
498  // Fields
499  for (int i = 0; i < descriptor_->field_count(); i++) {
500  printer->Print("public static final int $constant_name$ = $number$;\n",
501  "constant_name", FieldConstantName(descriptor_->field(i)),
502  "number", StrCat(descriptor_->field(i)->number()));
503  printer->Annotate("constant_name", descriptor_->field(i));
504  field_generators_.get(descriptor_->field(i)).GenerateMembers(printer);
505  printer->Print("\n");
506  }
507 
509  GenerateIsInitialized(printer);
511  GenerateEqualsAndHashCode(printer);
512  }
513 
514 
515  GenerateParseFromMethods(printer);
516  GenerateBuilder(printer);
517 
518  printer->Print(
519  "\n"
520  "// @@protoc_insertion_point(class_scope:$full_name$)\n",
521  "full_name", descriptor_->full_name());
522 
523  // Carefully initialize the default instance in such a way that it doesn't
524  // conflict with other initialization.
525  printer->Print("private static final $classname$ DEFAULT_INSTANCE;\n",
526  "classname",
528  printer->Print(
529  "static {\n"
530  " DEFAULT_INSTANCE = new $classname$();\n"
531  "}\n"
532  "\n",
534 
535  printer->Print(
536  "public static $classname$ getDefaultInstance() {\n"
537  " return DEFAULT_INSTANCE;\n"
538  "}\n"
539  "\n",
541 
542  // 'of' method for Wrappers
544  printer->Print(
545  "public static $classname$ of($field_type$ value) {\n"
546  " return newBuilder().setValue(value).build();\n"
547  "}\n"
548  "\n",
550  "field_type", PrimitiveTypeName(GetJavaType(descriptor_->field(0))));
551  }
552 
553  GenerateParser(printer);
554 
555  printer->Print(
556  "@java.lang.Override\n"
557  "public $classname$ getDefaultInstanceForType() {\n"
558  " return DEFAULT_INSTANCE;\n"
559  "}\n"
560  "\n",
562 
563  // Extensions must be declared after the DEFAULT_INSTANCE is initialized
564  // because the DEFAULT_INSTANCE is used by the extension to lazily retrieve
565  // the outer class's FileDescriptor.
566  for (int i = 0; i < descriptor_->extension_count(); i++) {
567  ImmutableExtensionGenerator(descriptor_->extension(i), context_)
568  .Generate(printer);
569  }
570 
571  printer->Outdent();
572  printer->Print("}\n\n");
573 }
574 
575 // ===================================================================
576 
578  io::Printer* printer) {
579  std::unique_ptr<const FieldDescriptor*[]> sorted_fields(
581 
582  std::vector<const Descriptor::ExtensionRange*> sorted_extensions;
583  sorted_extensions.reserve(descriptor_->extension_range_count());
584  for (int i = 0; i < descriptor_->extension_range_count(); ++i) {
585  sorted_extensions.push_back(descriptor_->extension_range(i));
586  }
587  std::sort(sorted_extensions.begin(), sorted_extensions.end(),
588  ExtensionRangeOrdering());
589  printer->Print(
590  "@java.lang.Override\n"
591  "public void writeTo(com.google.protobuf.CodedOutputStream output)\n"
592  " throws java.io.IOException {\n");
593  printer->Indent();
594 
596  // writeTo(CodedOutputStream output) might be invoked without
597  // getSerializedSize() ever being called, but we need the memoized
598  // sizes in case this message has packed fields. Rather than emit checks
599  // for each packed field, just call getSerializedSize() up front. In most
600  // cases, getSerializedSize() will have already been called anyway by one
601  // of the wrapper writeTo() methods, making this call cheap.
602  printer->Print("getSerializedSize();\n");
603  }
604 
605  if (descriptor_->extension_range_count() > 0) {
607  printer->Print(
608  "com.google.protobuf.GeneratedMessage$ver$\n"
609  " .ExtendableMessage<$classname$>.ExtensionWriter\n"
610  " extensionWriter = newMessageSetExtensionWriter();\n",
612  "ver", GeneratedCodeVersionSuffix());
613  } else {
614  printer->Print(
615  "com.google.protobuf.GeneratedMessage$ver$\n"
616  " .ExtendableMessage<$classname$>.ExtensionWriter\n"
617  " extensionWriter = newExtensionWriter();\n",
619  "ver", GeneratedCodeVersionSuffix());
620  }
621  }
622 
623  // Merge the fields and the extension ranges, both sorted by field number.
624  for (int i = 0, j = 0;
625  i < descriptor_->field_count() || j < sorted_extensions.size();) {
626  if (i == descriptor_->field_count()) {
627  GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]);
628  } else if (j == sorted_extensions.size()) {
629  GenerateSerializeOneField(printer, sorted_fields[i++]);
630  } else if (sorted_fields[i]->number() < sorted_extensions[j]->start) {
631  GenerateSerializeOneField(printer, sorted_fields[i++]);
632  } else {
633  GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]);
634  }
635  }
636 
638  printer->Print("unknownFields.writeAsMessageSetTo(output);\n");
639  } else {
640  printer->Print("unknownFields.writeTo(output);\n");
641  }
642 
643  printer->Outdent();
644  printer->Print(
645  "}\n"
646  "\n"
647  "@java.lang.Override\n"
648  "public int getSerializedSize() {\n"
649  " int size = memoizedSize;\n"
650  " if (size != -1) return size;\n"
651  "\n");
652  printer->Indent();
653 
654  printer->Print("size = 0;\n");
655 
656  for (int i = 0; i < descriptor_->field_count(); i++) {
657  field_generators_.get(sorted_fields[i]).GenerateSerializedSizeCode(printer);
658  }
659 
660  if (descriptor_->extension_range_count() > 0) {
662  printer->Print("size += extensionsSerializedSizeAsMessageSet();\n");
663  } else {
664  printer->Print("size += extensionsSerializedSize();\n");
665  }
666  }
667 
669  printer->Print("size += unknownFields.getSerializedSizeAsMessageSet();\n");
670  } else {
671  printer->Print("size += unknownFields.getSerializedSize();\n");
672  }
673 
674  printer->Print(
675  "memoizedSize = size;\n"
676  "return size;\n");
677 
678  printer->Outdent();
679  printer->Print(
680  "}\n"
681  "\n");
682 }
683 
685  // Note: These are separate from GenerateMessageSerializationMethods()
686  // because they need to be generated even for messages that are optimized
687  // for code size.
688  printer->Print(
689  "public static $classname$ parseFrom(\n"
690  " java.nio.ByteBuffer data)\n"
691  " throws com.google.protobuf.InvalidProtocolBufferException {\n"
692  " return PARSER.parseFrom(data);\n"
693  "}\n"
694  "public static $classname$ parseFrom(\n"
695  " java.nio.ByteBuffer data,\n"
696  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
697  " throws com.google.protobuf.InvalidProtocolBufferException {\n"
698  " return PARSER.parseFrom(data, extensionRegistry);\n"
699  "}\n"
700  "public static $classname$ parseFrom(\n"
701  " com.google.protobuf.ByteString data)\n"
702  " throws com.google.protobuf.InvalidProtocolBufferException {\n"
703  " return PARSER.parseFrom(data);\n"
704  "}\n"
705  "public static $classname$ parseFrom(\n"
706  " com.google.protobuf.ByteString data,\n"
707  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
708  " throws com.google.protobuf.InvalidProtocolBufferException {\n"
709  " return PARSER.parseFrom(data, extensionRegistry);\n"
710  "}\n"
711  "public static $classname$ parseFrom(byte[] data)\n"
712  " throws com.google.protobuf.InvalidProtocolBufferException {\n"
713  " return PARSER.parseFrom(data);\n"
714  "}\n"
715  "public static $classname$ parseFrom(\n"
716  " byte[] data,\n"
717  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
718  " throws com.google.protobuf.InvalidProtocolBufferException {\n"
719  " return PARSER.parseFrom(data, extensionRegistry);\n"
720  "}\n"
721  "public static $classname$ parseFrom(java.io.InputStream input)\n"
722  " throws java.io.IOException {\n"
723  " return com.google.protobuf.GeneratedMessage$ver$\n"
724  " .parseWithIOException(PARSER, input);\n"
725  "}\n"
726  "public static $classname$ parseFrom(\n"
727  " java.io.InputStream input,\n"
728  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
729  " throws java.io.IOException {\n"
730  " return com.google.protobuf.GeneratedMessage$ver$\n"
731  " .parseWithIOException(PARSER, input, extensionRegistry);\n"
732  "}\n"
733  "public static $classname$ parseDelimitedFrom(java.io.InputStream "
734  "input)\n"
735  " throws java.io.IOException {\n"
736  " return com.google.protobuf.GeneratedMessage$ver$\n"
737  " .parseDelimitedWithIOException(PARSER, input);\n"
738  "}\n"
739  "public static $classname$ parseDelimitedFrom(\n"
740  " java.io.InputStream input,\n"
741  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
742  " throws java.io.IOException {\n"
743  " return com.google.protobuf.GeneratedMessage$ver$\n"
744  " .parseDelimitedWithIOException(PARSER, input, "
745  "extensionRegistry);\n"
746  "}\n"
747  "public static $classname$ parseFrom(\n"
748  " com.google.protobuf.CodedInputStream input)\n"
749  " throws java.io.IOException {\n"
750  " return com.google.protobuf.GeneratedMessage$ver$\n"
751  " .parseWithIOException(PARSER, input);\n"
752  "}\n"
753  "public static $classname$ parseFrom(\n"
754  " com.google.protobuf.CodedInputStream input,\n"
755  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
756  " throws java.io.IOException {\n"
757  " return com.google.protobuf.GeneratedMessage$ver$\n"
758  " .parseWithIOException(PARSER, input, extensionRegistry);\n"
759  "}\n"
760  "\n",
761  "classname", name_resolver_->GetImmutableClassName(descriptor_), "ver",
763 }
764 
766  io::Printer* printer, const FieldDescriptor* field) {
767  field_generators_.get(field).GenerateSerializationCode(printer);
768 }
769 
771  io::Printer* printer, const Descriptor::ExtensionRange* range) {
772  printer->Print("extensionWriter.writeUntil($end$, output);\n", "end",
773  StrCat(range->end));
774 }
775 
776 // ===================================================================
777 
779  // LITE_RUNTIME implements this at the GeneratedMessageLite level.
780  printer->Print(
781  "@java.lang.Override\n"
782  "public Builder newBuilderForType() { return newBuilder(); }\n");
783 
784  printer->Print(
785  "public static Builder newBuilder() {\n"
786  " return DEFAULT_INSTANCE.toBuilder();\n"
787  "}\n"
788  "public static Builder newBuilder($classname$ prototype) {\n"
789  " return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);\n"
790  "}\n"
791  "@java.lang.Override\n"
792  "public Builder toBuilder() {\n"
793  " return this == DEFAULT_INSTANCE\n"
794  " ? new Builder() : new Builder().mergeFrom(this);\n"
795  "}\n"
796  "\n",
798 
799  printer->Print(
800  "@java.lang.Override\n"
801  "protected Builder newBuilderForType(\n"
802  " com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n"
803  " Builder builder = new Builder(parent);\n"
804  " return builder;\n"
805  "}\n",
806  "ver", GeneratedCodeVersionSuffix());
807 
808  MessageBuilderGenerator builderGenerator(descriptor_, context_);
809  builderGenerator.Generate(printer);
810 }
811 
813  io::Printer* printer) {
815  printer->Print(
816  "public static final com.google.protobuf.Descriptors.Descriptor\n"
817  " getDescriptor() {\n"
818  " return $fileclass$.internal_$identifier$_descriptor;\n"
819  "}\n"
820  "\n",
822  "identifier", UniqueFileScopeIdentifier(descriptor_));
823  }
824  std::vector<const FieldDescriptor*> map_fields;
825  for (int i = 0; i < descriptor_->field_count(); i++) {
826  const FieldDescriptor* field = descriptor_->field(i);
828  IsMapEntry(field->message_type())) {
829  map_fields.push_back(field);
830  }
831  }
832  if (!map_fields.empty()) {
833  printer->Print(
834  "@SuppressWarnings({\"rawtypes\"})\n"
835  "@java.lang.Override\n"
836  "protected com.google.protobuf.MapField internalGetMapField(\n"
837  " int number) {\n"
838  " switch (number) {\n");
839  printer->Indent();
840  printer->Indent();
841  for (int i = 0; i < map_fields.size(); ++i) {
842  const FieldDescriptor* field = map_fields[i];
843  const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
844  printer->Print(
845  "case $number$:\n"
846  " return internalGet$capitalized_name$();\n",
847  "number", StrCat(field->number()), "capitalized_name",
848  info->capitalized_name);
849  }
850  printer->Print(
851  "default:\n"
852  " throw new RuntimeException(\n"
853  " \"Invalid map field number: \" + number);\n");
854  printer->Outdent();
855  printer->Outdent();
856  printer->Print(
857  " }\n"
858  "}\n");
859  }
860  printer->Print(
861  "@java.lang.Override\n"
862  "protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n"
863  " internalGetFieldAccessorTable() {\n"
864  " return $fileclass$.internal_$identifier$_fieldAccessorTable\n"
865  " .ensureFieldAccessorsInitialized(\n"
866  " $classname$.class, $classname$.Builder.class);\n"
867  "}\n"
868  "\n",
871  "identifier", UniqueFileScopeIdentifier(descriptor_), "ver",
873 }
874 
875 // ===================================================================
876 
878  // Memoizes whether the protocol buffer is fully initialized (has all
879  // required fields). -1 means not yet computed. 0 means false and 1 means
880  // true.
881  printer->Print("private byte memoizedIsInitialized = -1;\n");
882  printer->Print(
883  "@java.lang.Override\n"
884  "public final boolean isInitialized() {\n");
885  printer->Indent();
886 
887  // Don't directly compare to -1 to avoid an Android x86 JIT bug.
888  printer->Print(
889  "byte isInitialized = memoizedIsInitialized;\n"
890  "if (isInitialized == 1) return true;\n"
891  "if (isInitialized == 0) return false;\n"
892  "\n");
893 
894  // Check that all required fields in this message are set.
895  // TODO(kenton): We can optimize this when we switch to putting all the
896  // "has" fields into a single bitfield.
897  for (int i = 0; i < descriptor_->field_count(); i++) {
898  const FieldDescriptor* field = descriptor_->field(i);
899  const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
900 
901  if (field->is_required()) {
902  printer->Print(
903  "if (!has$name$()) {\n"
904  " memoizedIsInitialized = 0;\n"
905  " return false;\n"
906  "}\n",
907  "name", info->capitalized_name);
908  }
909  }
910 
911  // Now check that all embedded messages are initialized.
912  for (int i = 0; i < descriptor_->field_count(); i++) {
913  const FieldDescriptor* field = descriptor_->field(i);
914  const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
916  HasRequiredFields(field->message_type())) {
917  switch (field->label()) {
919  printer->Print(
920  "if (!get$name$().isInitialized()) {\n"
921  " memoizedIsInitialized = 0;\n"
922  " return false;\n"
923  "}\n",
924  "type",
925  name_resolver_->GetImmutableClassName(field->message_type()),
926  "name", info->capitalized_name);
927  break;
929  printer->Print(
930  "if (has$name$()) {\n"
931  " if (!get$name$().isInitialized()) {\n"
932  " memoizedIsInitialized = 0;\n"
933  " return false;\n"
934  " }\n"
935  "}\n",
936  "name", info->capitalized_name);
937  break;
939  if (IsMapEntry(field->message_type())) {
940  printer->Print(
941  "for ($type$ item : get$name$Map().values()) {\n"
942  " if (!item.isInitialized()) {\n"
943  " memoizedIsInitialized = 0;\n"
944  " return false;\n"
945  " }\n"
946  "}\n",
947  "type",
948  MapValueImmutableClassdName(field->message_type(),
950  "name", info->capitalized_name);
951  } else {
952  printer->Print(
953  "for (int i = 0; i < get$name$Count(); i++) {\n"
954  " if (!get$name$(i).isInitialized()) {\n"
955  " memoizedIsInitialized = 0;\n"
956  " return false;\n"
957  " }\n"
958  "}\n",
959  "type",
960  name_resolver_->GetImmutableClassName(field->message_type()),
961  "name", info->capitalized_name);
962  }
963  break;
964  }
965  }
966  }
967 
968  if (descriptor_->extension_range_count() > 0) {
969  printer->Print(
970  "if (!extensionsAreInitialized()) {\n"
971  " memoizedIsInitialized = 0;\n"
972  " return false;\n"
973  "}\n");
974  }
975 
976  printer->Outdent();
977 
978  printer->Print(" memoizedIsInitialized = 1;\n");
979 
980  printer->Print(
981  " return true;\n"
982  "}\n"
983  "\n");
984 }
985 
986 // ===================================================================
987 
988 namespace {
989 bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) {
990  if (field->is_repeated()) {
991  return false;
992  }
993  if (HasHasbit(field)) {
994  return true;
995  }
997 }
998 } // namespace
999 
1001  io::Printer* printer) {
1002  printer->Print(
1003  "@java.lang.Override\n"
1004  "public boolean equals(");
1005  printer->Print("final java.lang.Object obj) {\n");
1006  printer->Indent();
1007  printer->Print(
1008  "if (obj == this) {\n"
1009  " return true;\n"
1010  "}\n"
1011  "if (!(obj instanceof $classname$)) {\n"
1012  " return super.equals(obj);\n"
1013  "}\n"
1014  "$classname$ other = ($classname$) obj;\n"
1015  "\n",
1017 
1018  for (int i = 0; i < descriptor_->field_count(); i++) {
1019  const FieldDescriptor* field = descriptor_->field(i);
1020  if (!IsRealOneof(field)) {
1021  const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
1022  bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field);
1023  if (check_has_bits) {
1024  printer->Print(
1025  "if (has$name$() != other.has$name$()) return false;\n"
1026  "if (has$name$()) {\n",
1027  "name", info->capitalized_name);
1028  printer->Indent();
1029  }
1030  field_generators_.get(field).GenerateEqualsCode(printer);
1031  if (check_has_bits) {
1032  printer->Outdent();
1033  printer->Print("}\n");
1034  }
1035  }
1036  }
1037 
1038  // Compare oneofs.
1039  for (auto oneof : oneofs_) {
1040  printer->Print(
1041  "if (!get$oneof_capitalized_name$Case().equals("
1042  "other.get$oneof_capitalized_name$Case())) return false;\n",
1043  "oneof_capitalized_name",
1045  printer->Print("switch ($oneof_name$Case_) {\n", "oneof_name",
1047  printer->Indent();
1048  for (int j = 0; j < (oneof)->field_count(); j++) {
1049  const FieldDescriptor* field = (oneof)->field(j);
1050  printer->Print("case $field_number$:\n", "field_number",
1051  StrCat(field->number()));
1052  printer->Indent();
1053  field_generators_.get(field).GenerateEqualsCode(printer);
1054  printer->Print("break;\n");
1055  printer->Outdent();
1056  }
1057  printer->Print(
1058  "case 0:\n"
1059  "default:\n");
1060  printer->Outdent();
1061  printer->Print("}\n");
1062  }
1063 
1064  // Always consider unknown fields for equality. This will sometimes return
1065  // false for non-canonical ordering when running in LITE_RUNTIME but it's
1066  // the best we can do.
1067  printer->Print(
1068  "if (!unknownFields.equals(other.unknownFields)) return false;\n");
1069  if (descriptor_->extension_range_count() > 0) {
1070  printer->Print(
1071  "if (!getExtensionFields().equals(other.getExtensionFields()))\n"
1072  " return false;\n");
1073  }
1074  printer->Print("return true;\n");
1075  printer->Outdent();
1076  printer->Print(
1077  "}\n"
1078  "\n");
1079 
1080  printer->Print(
1081  "@java.lang.Override\n"
1082  "public int hashCode() {\n");
1083  printer->Indent();
1084  printer->Print("if (memoizedHashCode != 0) {\n");
1085  printer->Indent();
1086  printer->Print("return memoizedHashCode;\n");
1087  printer->Outdent();
1088  printer->Print(
1089  "}\n"
1090  "int hash = 41;\n");
1091 
1092  // If we output a getDescriptor() method, use that as it is more efficient.
1094  printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n");
1095  } else {
1096  printer->Print("hash = (19 * hash) + getDescriptor().hashCode();\n");
1097  }
1098 
1099  // hashCode non-oneofs.
1100  for (int i = 0; i < descriptor_->field_count(); i++) {
1101  const FieldDescriptor* field = descriptor_->field(i);
1102  if (!IsRealOneof(field)) {
1103  const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
1104  bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field);
1105  if (check_has_bits) {
1106  printer->Print("if (has$name$()) {\n", "name", info->capitalized_name);
1107  printer->Indent();
1108  }
1109  field_generators_.get(field).GenerateHashCode(printer);
1110  if (check_has_bits) {
1111  printer->Outdent();
1112  printer->Print("}\n");
1113  }
1114  }
1115  }
1116 
1117  // hashCode oneofs.
1118  for (auto oneof : oneofs_) {
1119  printer->Print("switch ($oneof_name$Case_) {\n", "oneof_name",
1121  printer->Indent();
1122  for (int j = 0; j < (oneof)->field_count(); j++) {
1123  const FieldDescriptor* field = (oneof)->field(j);
1124  printer->Print("case $field_number$:\n", "field_number",
1125  StrCat(field->number()));
1126  printer->Indent();
1127  field_generators_.get(field).GenerateHashCode(printer);
1128  printer->Print("break;\n");
1129  printer->Outdent();
1130  }
1131  printer->Print(
1132  "case 0:\n"
1133  "default:\n");
1134  printer->Outdent();
1135  printer->Print("}\n");
1136  }
1137 
1138  if (descriptor_->extension_range_count() > 0) {
1139  printer->Print("hash = hashFields(hash, getExtensionFields());\n");
1140  }
1141 
1142  printer->Print("hash = (29 * hash) + unknownFields.hashCode();\n");
1143  printer->Print(
1144  "memoizedHashCode = hash;\n"
1145  "return hash;\n");
1146  printer->Outdent();
1147  printer->Print(
1148  "}\n"
1149  "\n");
1150 }
1151 
1152 // ===================================================================
1153 
1155  io::Printer* printer) {
1156  for (int i = 0; i < descriptor_->extension_count(); i++) {
1157  ImmutableExtensionGenerator(descriptor_->extension(i), context_)
1158  .GenerateRegistrationCode(printer);
1159  }
1160 
1161  for (int i = 0; i < descriptor_->nested_type_count(); i++) {
1163  .GenerateExtensionRegistrationCode(printer);
1164  }
1165 }
1166 
1167 // ===================================================================
1169  io::Printer* printer) {
1170  std::unique_ptr<const FieldDescriptor*[]> sorted_fields(
1172 
1173  printer->Print(
1174  "private $classname$(\n"
1175  " com.google.protobuf.CodedInputStream input,\n"
1176  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
1177  " throws com.google.protobuf.InvalidProtocolBufferException {\n",
1178  "classname", descriptor_->name());
1179  printer->Indent();
1180 
1181  // Initialize all fields to default.
1182  printer->Print(
1183  "this();\n"
1184  "if (extensionRegistry == null) {\n"
1185  " throw new java.lang.NullPointerException();\n"
1186  "}\n");
1187 
1188  // Use builder bits to track mutable repeated fields.
1189  int totalBuilderBits = 0;
1190  for (int i = 0; i < descriptor_->field_count(); i++) {
1191  const ImmutableFieldGenerator& field =
1193  totalBuilderBits += field.GetNumBitsForBuilder();
1194  }
1195  int totalBuilderInts = (totalBuilderBits + 31) / 32;
1196  for (int i = 0; i < totalBuilderInts; i++) {
1197  printer->Print("int mutable_$bit_field_name$ = 0;\n", "bit_field_name",
1198  GetBitFieldName(i));
1199  }
1200 
1201  printer->Print(
1202  "com.google.protobuf.UnknownFieldSet.Builder unknownFields =\n"
1203  " com.google.protobuf.UnknownFieldSet.newBuilder();\n");
1204 
1205  printer->Print("try {\n");
1206  printer->Indent();
1207 
1208  printer->Print(
1209  "boolean done = false;\n"
1210  "while (!done) {\n");
1211  printer->Indent();
1212 
1213  printer->Print(
1214  "int tag = input.readTag();\n"
1215  "switch (tag) {\n");
1216  printer->Indent();
1217 
1218  printer->Print(
1219  "case 0:\n" // zero signals EOF / limit reached
1220  " done = true;\n"
1221  " break;\n");
1222 
1223  for (int i = 0; i < descriptor_->field_count(); i++) {
1224  const FieldDescriptor* field = sorted_fields[i];
1226  field->number(), WireFormat::WireTypeForFieldType(field->type()));
1227 
1228  printer->Print("case $tag$: {\n", "tag",
1229  StrCat(static_cast<int32_t>(tag)));
1230  printer->Indent();
1231 
1232  field_generators_.get(field).GenerateParsingCode(printer);
1233 
1234  printer->Outdent();
1235  printer->Print(
1236  " break;\n"
1237  "}\n");
1238 
1239  if (field->is_packable()) {
1240  // To make packed = true wire compatible, we generate parsing code from a
1241  // packed version of this field regardless of field->options().packed().
1242  uint32_t packed_tag = WireFormatLite::MakeTag(
1244  printer->Print("case $tag$: {\n", "tag",
1245  StrCat(static_cast<int32_t>(packed_tag)));
1246  printer->Indent();
1247 
1248  field_generators_.get(field).GenerateParsingCodeFromPacked(printer);
1249 
1250  printer->Outdent();
1251  printer->Print(
1252  " break;\n"
1253  "}\n");
1254  }
1255  }
1256 
1257  printer->Print(
1258  "default: {\n"
1259  " if (!parseUnknownField(\n"
1260  " input, unknownFields, extensionRegistry, tag)) {\n"
1261  " done = true;\n" // it's an endgroup tag
1262  " }\n"
1263  " break;\n"
1264  "}\n");
1265 
1266  printer->Outdent();
1267  printer->Outdent();
1268  printer->Print(
1269  " }\n" // switch (tag)
1270  "}\n"); // while (!done)
1271 
1272  printer->Outdent();
1273  printer->Print(
1274  "} catch (com.google.protobuf.InvalidProtocolBufferException e) {\n"
1275  " throw e.setUnfinishedMessage(this);\n"
1276  "} catch (java.io.IOException e) {\n"
1277  " throw new com.google.protobuf.InvalidProtocolBufferException(\n"
1278  " e).setUnfinishedMessage(this);\n"
1279  "} finally {\n");
1280  printer->Indent();
1281 
1282  // Make repeated field list immutable.
1283  for (int i = 0; i < descriptor_->field_count(); i++) {
1284  const FieldDescriptor* field = sorted_fields[i];
1285  field_generators_.get(field).GenerateParsingDoneCode(printer);
1286  }
1287 
1288  // Make unknown fields immutable.
1289  printer->Print("this.unknownFields = unknownFields.build();\n");
1290 
1291  // Make extensions immutable.
1292  printer->Print("makeExtensionsImmutable();\n");
1293 
1294  printer->Outdent();
1295  printer->Outdent();
1296  printer->Print(
1297  " }\n" // finally
1298  "}\n");
1299 }
1300 
1301 // ===================================================================
1303  printer->Print(
1304  "$visibility$ static final com.google.protobuf.Parser<$classname$>\n"
1305  " PARSER = new com.google.protobuf.AbstractParser<$classname$>() {\n",
1306  "visibility",
1307  ExposePublicParser(descriptor_->file()) ? "@java.lang.Deprecated public"
1308  : "private",
1309  "classname", descriptor_->name());
1310  printer->Indent();
1311  printer->Print(
1312  "@java.lang.Override\n"
1313  "public $classname$ parsePartialFrom(\n"
1314  " com.google.protobuf.CodedInputStream input,\n"
1315  " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
1316  " throws com.google.protobuf.InvalidProtocolBufferException {\n",
1317  "classname", descriptor_->name());
1319  printer->Print(" return new $classname$(input, extensionRegistry);\n",
1320  "classname", descriptor_->name());
1321  } else {
1322  // When parsing constructor isn't generated, use builder to parse
1323  // messages. Note, will fallback to use reflection based mergeFieldFrom()
1324  // in AbstractMessage.Builder.
1325  printer->Indent();
1326  printer->Print(
1327  "Builder builder = newBuilder();\n"
1328  "try {\n"
1329  " builder.mergeFrom(input, extensionRegistry);\n"
1330  "} catch (com.google.protobuf.InvalidProtocolBufferException e) {\n"
1331  " throw e.setUnfinishedMessage(builder.buildPartial());\n"
1332  "} catch (java.io.IOException e) {\n"
1333  " throw new com.google.protobuf.InvalidProtocolBufferException(\n"
1334  " e.getMessage()).setUnfinishedMessage(\n"
1335  " builder.buildPartial());\n"
1336  "}\n"
1337  "return builder.buildPartial();\n");
1338  printer->Outdent();
1339  }
1340  printer->Print("}\n");
1341  printer->Outdent();
1342  printer->Print(
1343  "};\n"
1344  "\n");
1345 
1346  printer->Print(
1347  "public static com.google.protobuf.Parser<$classname$> parser() {\n"
1348  " return PARSER;\n"
1349  "}\n"
1350  "\n"
1351  "@java.lang.Override\n"
1352  "public com.google.protobuf.Parser<$classname$> getParserForType() {\n"
1353  " return PARSER;\n"
1354  "}\n"
1355  "\n",
1356  "classname", descriptor_->name());
1357 }
1358 
1359 // ===================================================================
1361  for (int i = 0; i < descriptor_->field_count(); i++) {
1362  if (!IsRealOneof(descriptor_->field(i))) {
1364  .GenerateInitializationCode(printer);
1365  }
1366  }
1367 }
1368 
1369 // ===================================================================
1371  printer->Print(
1372  "protected com.google.protobuf.MutableMessage\n"
1373  " internalMutableDefault() {\n"
1374  " return MutableDefaultLoader.get();\n"
1375  "}\n"
1376  "\n"
1377  "private static final class MutableDefaultLoader {\n"
1378  " private static final java.lang.Object defaultOrRuntimeException;\n"
1379  " static {\n"
1380  " java.lang.Object local;\n"
1381  " try {\n"
1382  " local = internalMutableDefault(\"$mutable_name$\");\n"
1383  " } catch (java.lang.RuntimeException e) {\n"
1384  " local = e;\n"
1385  " }\n"
1386  " defaultOrRuntimeException = local;\n"
1387  " }\n"
1388  "\n"
1389  " private MutableDefaultLoader() {}\n"
1390  "\n"
1391  " public static com.google.protobuf.MutableMessage get() {\n"
1392  " if (defaultOrRuntimeException\n"
1393  " instanceof java.lang.RuntimeException) {\n"
1394  " throw (java.lang.RuntimeException) defaultOrRuntimeException;\n"
1395  " }\n"
1396  " return\n"
1397  " (com.google.protobuf.MutableMessage) "
1398  "defaultOrRuntimeException;\n"
1399  " }\n"
1400  "}\n",
1402 }
1403 
1405  printer->Print(
1406  "@kotlin.OptIn"
1407  "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
1408  "@com.google.protobuf.kotlin.ProtoDslMarker\n");
1409  printer->Print(
1410  "public class Dsl private constructor(\n"
1411  " private val _builder: $message$.Builder\n"
1412  ") {\n"
1413  " public companion object {\n"
1414  " @kotlin.jvm.JvmSynthetic\n"
1415  " @kotlin.PublishedApi\n"
1416  " internal fun _create(builder: $message$.Builder): Dsl = "
1417  "Dsl(builder)\n"
1418  " }\n"
1419  "\n"
1420  " @kotlin.jvm.JvmSynthetic\n"
1421  " @kotlin.PublishedApi\n"
1422  " internal fun _build(): $message$ = _builder.build()\n",
1423  "message", name_resolver_->GetClassName(descriptor_, true));
1424 
1425  printer->Indent();
1426 
1427  for (int i = 0; i < descriptor_->field_count(); i++) {
1428  printer->Print("\n");
1430  .GenerateKotlinDslMembers(printer);
1431  }
1432 
1433  for (auto oneof : oneofs_) {
1434  printer->Print(
1435  "public val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n"
1436  " @JvmName(\"get$oneof_capitalized_name$Case\")\n"
1437  " get() = _builder.get$oneof_capitalized_name$Case()\n\n"
1438  "public fun clear$oneof_capitalized_name$() {\n"
1439  " _builder.clear$oneof_capitalized_name$()\n"
1440  "}\n",
1441  "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name,
1442  "oneof_capitalized_name",
1443  context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "message",
1445  }
1446 
1447  if (descriptor_->extension_range_count() > 0) {
1448  GenerateKotlinExtensions(printer);
1449  }
1450 
1451  printer->Outdent();
1452  printer->Print("}\n");
1453 }
1454 
1456  io::Printer* printer) const {
1457  printer->Print(
1458  "@kotlin.jvm.JvmSynthetic\n"
1459  "public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
1460  "kotlin.Unit): "
1461  "$message$ "
1462  "=\n"
1463  " $message_kt$.Dsl._create($message$.newBuilder()).apply { block() "
1464  "}._build()\n",
1465  "camelcase_name", name_resolver_->GetKotlinFactoryName(descriptor_),
1467  "message", name_resolver_->GetClassName(descriptor_, true));
1468 
1469  printer->Print("public object $name$Kt {\n", "name", descriptor_->name());
1470  printer->Indent();
1471  GenerateKotlinDsl(printer);
1472  for (int i = 0; i < descriptor_->nested_type_count(); i++) {
1473  if (IsMapEntry(descriptor_->nested_type(i))) continue;
1475  .GenerateKotlinMembers(printer);
1476  }
1477  printer->Outdent();
1478  printer->Print("}\n");
1479 }
1480 
1482  io::Printer* printer) const {
1483  printer->Print(
1484  "@kotlin.jvm.JvmSynthetic\n"
1485  "public inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
1486  "kotlin.Unit): "
1487  "$message$ =\n"
1488  " $message_kt$.Dsl._create(this.toBuilder()).apply { block() "
1489  "}._build()\n",
1490  "message", name_resolver_->GetClassName(descriptor_, true), "message_kt",
1492 
1493  for (int i = 0; i < descriptor_->nested_type_count(); i++) {
1494  if (IsMapEntry(descriptor_->nested_type(i))) continue;
1496  .GenerateTopLevelKotlinMembers(printer);
1497  }
1498 }
1499 
1501  io::Printer* printer) const {
1502  std::string message_name = name_resolver_->GetClassName(descriptor_, true);
1503 
1504  printer->Print(
1505  "@Suppress(\"UNCHECKED_CAST\")\n"
1506  "@kotlin.jvm.JvmSynthetic\n"
1507  "public operator fun <T> get(extension: "
1508  "com.google.protobuf.ExtensionLite<$message$, T>): T {\n"
1509  " return if (extension.isRepeated) {\n"
1510  " get(extension as com.google.protobuf.ExtensionLite<$message$, "
1511  "List<*>>) as T\n"
1512  " } else {\n"
1513  " _builder.getExtension(extension)\n"
1514  " }\n"
1515  "}\n\n",
1516  "message", message_name);
1517 
1518  printer->Print(
1519  "@kotlin.jvm.JvmSynthetic\n"
1520  "@kotlin.OptIn"
1521  "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
1522  "@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n"
1523  "public operator fun <E> get(\n"
1524  " extension: com.google.protobuf.ExtensionLite<$message$, List<E>>\n"
1525  "): com.google.protobuf.kotlin.ExtensionList<E, $message$> {\n"
1526  " return com.google.protobuf.kotlin.ExtensionList(extension, "
1527  "_builder.getExtension(extension))\n"
1528  "}\n\n",
1529  "message", message_name);
1530 
1531  printer->Print(
1532  "@kotlin.jvm.JvmSynthetic\n"
1533  "public operator fun contains(extension: "
1534  "com.google.protobuf.ExtensionLite<$message$, *>): "
1535  "Boolean {\n"
1536  " return _builder.hasExtension(extension)\n"
1537  "}\n\n",
1538  "message", message_name);
1539 
1540  printer->Print(
1541  "@kotlin.jvm.JvmSynthetic\n"
1542  "public fun clear(extension: "
1543  "com.google.protobuf.ExtensionLite<$message$, *>) "
1544  "{\n"
1545  " _builder.clearExtension(extension)\n"
1546  "}\n\n",
1547  "message", message_name);
1548 
1549  printer->Print(
1550  "@kotlin.jvm.JvmSynthetic\n"
1551  "@kotlin.PublishedApi\n"
1552  "internal fun <T> setExtension(extension: "
1553  "com.google.protobuf.ExtensionLite<$message$, T>, "
1554  "value: T) {\n"
1555  " _builder.setExtension(extension, value)\n"
1556  "}\n\n",
1557  "message", message_name);
1558 
1559  printer->Print(
1560  "@kotlin.jvm.JvmSynthetic\n"
1561  "@Suppress(\"NOTHING_TO_INLINE\")\n"
1562  "public inline operator fun <T : Comparable<T>> set(\n"
1563  " extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
1564  " value: T\n"
1565  ") {\n"
1566  " setExtension(extension, value)\n"
1567  "}\n\n",
1568  "message", message_name);
1569 
1570  printer->Print(
1571  "@kotlin.jvm.JvmSynthetic\n"
1572  "@Suppress(\"NOTHING_TO_INLINE\")\n"
1573  "public inline operator fun set(\n"
1574  " extension: com.google.protobuf.ExtensionLite<$message$, "
1575  "com.google.protobuf.ByteString>,\n"
1576  " value: com.google.protobuf.ByteString\n"
1577  ") {\n"
1578  " setExtension(extension, value)\n"
1579  "}\n\n",
1580  "message", message_name);
1581 
1582  printer->Print(
1583  "@kotlin.jvm.JvmSynthetic\n"
1584  "@Suppress(\"NOTHING_TO_INLINE\")\n"
1585  "public inline operator fun <T : com.google.protobuf.MessageLite> set(\n"
1586  " extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
1587  " value: T\n"
1588  ") {\n"
1589  " setExtension(extension, value)\n"
1590  "}\n\n",
1591  "message", message_name);
1592 
1593  printer->Print(
1594  "@kotlin.jvm.JvmSynthetic\n"
1595  "public fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
1596  "$message$>.add(value: E) {\n"
1597  " _builder.addExtension(this.extension, value)\n"
1598  "}\n\n",
1599  "message", message_name);
1600 
1601  printer->Print(
1602  "@kotlin.jvm.JvmSynthetic\n"
1603  "@Suppress(\"NOTHING_TO_INLINE\")\n"
1604  "public inline operator fun <E> "
1605  "com.google.protobuf.kotlin.ExtensionList<E, "
1606  "$message$>.plusAssign"
1607  "(value: E) {\n"
1608  " add(value)\n"
1609  "}\n\n",
1610  "message", message_name);
1611 
1612  printer->Print(
1613  "@kotlin.jvm.JvmSynthetic\n"
1614  "public fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
1615  "$message$>.addAll(values: Iterable<E>) {\n"
1616  " for (value in values) {\n"
1617  " add(value)\n"
1618  " }\n"
1619  "}\n\n",
1620  "message", message_name);
1621 
1622  printer->Print(
1623  "@kotlin.jvm.JvmSynthetic\n"
1624  "@Suppress(\"NOTHING_TO_INLINE\")\n"
1625  "public inline operator fun <E> "
1626  "com.google.protobuf.kotlin.ExtensionList<E, "
1627  "$message$>.plusAssign(values: "
1628  "Iterable<E>) {\n"
1629  " addAll(values)\n"
1630  "}\n\n",
1631  "message", message_name);
1632 
1633  printer->Print(
1634  "@kotlin.jvm.JvmSynthetic\n"
1635  "public operator fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
1636  "$message$>.set(index: Int, value: "
1637  "E) {\n"
1638  " _builder.setExtension(this.extension, index, value)\n"
1639  "}\n\n",
1640  "message", message_name);
1641 
1642  printer->Print(
1643  "@kotlin.jvm.JvmSynthetic\n"
1644  "@Suppress(\"NOTHING_TO_INLINE\")\n"
1645  "public inline fun com.google.protobuf.kotlin.ExtensionList<*, "
1646  "$message$>.clear() {\n"
1647  " clear(extension)\n"
1648  "}\n\n",
1649  "message", message_name);
1650 }
1651 
1653  printer->Print(
1654  "private static String getTypeUrl(\n"
1655  " java.lang.String typeUrlPrefix,\n"
1656  " com.google.protobuf.Descriptors.Descriptor descriptor) {\n"
1657  " return typeUrlPrefix.endsWith(\"/\")\n"
1658  " ? typeUrlPrefix + descriptor.getFullName()\n"
1659  " : typeUrlPrefix + \"/\" + descriptor.getFullName();\n"
1660  "}\n"
1661  "\n"
1662  "private static String getTypeNameFromTypeUrl(\n"
1663  " java.lang.String typeUrl) {\n"
1664  " int pos = typeUrl.lastIndexOf('/');\n"
1665  " return pos == -1 ? \"\" : typeUrl.substring(pos + 1);\n"
1666  "}\n"
1667  "\n"
1668  "public static <T extends com.google.protobuf.Message> Any pack(\n"
1669  " T message) {\n"
1670  " return Any.newBuilder()\n"
1671  " .setTypeUrl(getTypeUrl(\"type.googleapis.com\",\n"
1672  " message.getDescriptorForType()))\n"
1673  " .setValue(message.toByteString())\n"
1674  " .build();\n"
1675  "}\n"
1676  "\n"
1677  "/**\n"
1678  " * Packs a message using the given type URL prefix. The type URL will\n"
1679  " * be constructed by concatenating the message type's full name to the\n"
1680  " * prefix with an optional \"/\" separator if the prefix doesn't end\n"
1681  " * with \"/\" already.\n"
1682  " */\n"
1683  "public static <T extends com.google.protobuf.Message> Any pack(\n"
1684  " T message, java.lang.String typeUrlPrefix) {\n"
1685  " return Any.newBuilder()\n"
1686  " .setTypeUrl(getTypeUrl(typeUrlPrefix,\n"
1687  " message.getDescriptorForType()))\n"
1688  " .setValue(message.toByteString())\n"
1689  " .build();\n"
1690  "}\n"
1691  "\n"
1692  "public <T extends com.google.protobuf.Message> boolean is(\n"
1693  " java.lang.Class<T> clazz) {\n"
1694  " T defaultInstance =\n"
1695  " com.google.protobuf.Internal.getDefaultInstance(clazz);\n"
1696  " return getTypeNameFromTypeUrl(getTypeUrl()).equals(\n"
1697  " defaultInstance.getDescriptorForType().getFullName());\n"
1698  "}\n"
1699  "\n"
1700  "private volatile com.google.protobuf.Message cachedUnpackValue;\n"
1701  "\n"
1702  "@java.lang.SuppressWarnings(\"unchecked\")\n"
1703  "public <T extends com.google.protobuf.Message> T unpack(\n"
1704  " java.lang.Class<T> clazz)\n"
1705  " throws com.google.protobuf.InvalidProtocolBufferException {\n"
1706  " boolean invalidClazz = false;\n"
1707  " if (cachedUnpackValue != null) {\n"
1708  " if (cachedUnpackValue.getClass() == clazz) {\n"
1709  " return (T) cachedUnpackValue;\n"
1710  " }\n"
1711  " invalidClazz = true;\n"
1712  " }\n"
1713  " if (invalidClazz || !is(clazz)) {\n"
1714  " throw new com.google.protobuf.InvalidProtocolBufferException(\n"
1715  " \"Type of the Any message does not match the given class.\");\n"
1716  " }\n"
1717  " T defaultInstance =\n"
1718  " com.google.protobuf.Internal.getDefaultInstance(clazz);\n"
1719  " T result = (T) defaultInstance.getParserForType()\n"
1720  " .parseFrom(getValue());\n"
1721  " cachedUnpackValue = result;\n"
1722  " return result;\n"
1723  "}\n");
1724 }
1725 
1726 } // namespace java
1727 } // namespace compiler
1728 } // namespace protobuf
1729 } // namespace google
google::protobuf::Descriptor::full_name
const std::string & full_name() const
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateEqualsAndHashCode
void GenerateEqualsAndHashCode(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:998
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateMessageSerializationMethods
void GenerateMessageSerializationMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:564
google::protobuf::io::Printer::Print
void Print(const std::map< std::string, std::string > &variables, const char *text)
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/printer.cc:113
google::protobuf::compiler::java::MaybePrintGeneratedAnnotation
void MaybePrintGeneratedAnnotation(Context *context, io::Printer *printer, Descriptor *descriptor, bool immutable, const std::string &suffix="")
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:187
descriptor_
string_view descriptor_
Definition: elf.cc:154
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateTopLevelKotlinMembers
void GenerateTopLevelKotlinMembers(io::Printer *printer) const override
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1481
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateInterface
virtual void GenerateInterface(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:240
absl::str_format_internal::LengthMod::j
@ j
google::protobuf::compiler::java::HasDescriptorMethods
bool HasDescriptorMethods(const Descriptor *descriptor, bool enforce_lite)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:242
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateIsInitialized
void GenerateIsInitialized(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:863
google::protobuf::compiler::java::IsMapEntry
bool IsMapEntry(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:375
MessageOptions::deprecated
bool deprecated() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.pb.h:12117
google::protobuf::compiler::java::ImmutableMessageGenerator::context_
Context * context_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:132
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateKotlinMembers
void GenerateKotlinMembers(io::Printer *printer) const override
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1455
capstone.range
range
Definition: third_party/bloaty/third_party/capstone/bindings/python/capstone/__init__.py:6
google::protobuf.internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED
@ WIRETYPE_LENGTH_DELIMITED
Definition: bloaty/third_party/protobuf/src/google/protobuf/wire_format_lite.h:104
GOOGLE_CHECK_EQ
#define GOOGLE_CHECK_EQ(A, B)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:156
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::Descriptor::nested_type_count
int nested_type_count() const
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateParseFromMethods
void GenerateParseFromMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:670
google::protobuf::Descriptor::containing_type
const Descriptor * containing_type() const
google::protobuf::compiler::java::MultipleJavaFiles
bool MultipleJavaFiles(const FileDescriptor *descriptor, bool immutable)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:158
grpc::protobuf::io::Printer
GRPC_CUSTOM_PRINTER Printer
Definition: src/compiler/config.h:54
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateSerializeOneExtensionRange
void GenerateSerializeOneExtensionRange(io::Printer *printer, const Descriptor::ExtensionRange *range)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:756
google::protobuf::compiler::java::ClassNameResolver::GetImmutableClassName
std::string GetImmutableClassName(const DescriptorType *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h:88
google::protobuf::FieldDescriptor::LABEL_OPTIONAL
@ LABEL_OPTIONAL
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:572
google::protobuf::compiler::java::ImmutableMessageGenerator::ImmutableMessageGenerator
ImmutableMessageGenerator(const Descriptor *descriptor, Context *context)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:83
google::protobuf::StrCat
string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil.cc:1482
Descriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:121
google::protobuf::compiler::java::MessageGenerator::MessageGenerator
MessageGenerator(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:77
google::protobuf::compiler::java::IsRealOneof
bool IsRealOneof(const FieldDescriptor *descriptor)
Definition: protobuf/src/google/protobuf/compiler/java/java_helpers.h:364
google::protobuf.internal::WireFormatLite::MakeTag
constexpr static uint32 MakeTag(int field_number, WireType type)
Definition: bloaty/third_party/protobuf/src/google/protobuf/wire_format_lite.h:783
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
google::protobuf::Descriptor::options
const MessageOptions & options() const
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateParsingConstructor
void GenerateParsingConstructor(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1168
google::protobuf::compiler::java::HasHasbit
bool HasHasbit(const FieldDescriptor *descriptor)
Definition: protobuf/src/google/protobuf/compiler/java/java_helpers.h:375
google::protobuf::compiler::java::ExtraMessageOrBuilderInterfaces
std::string ExtraMessageOrBuilderInterfaces(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:303
FieldDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:133
google::protobuf::Descriptor::field
const FieldDescriptor * field(int index) const
google::protobuf::io::Printer::Indent
void Indent()
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/printer.cc:186
start
static uint64_t start
Definition: benchmark-pound.c:74
google::protobuf::compiler::java::WriteMessageDocComment
void WriteMessageDocComment(io::Printer *printer, const Descriptor *message)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc:166
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer
int GenerateFieldAccessorTableInitializer(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:212
google::protobuf::compiler::java::IsWrappersProtoFile
bool IsWrappersProtoFile(const FileDescriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:387
google::protobuf::FieldDescriptor::containing_oneof
const OneofDescriptor * containing_oneof
Definition: protobuf/src/google/protobuf/descriptor.h:932
context_
ScopedContext * context_
Definition: filter_fuzzer.cc:559
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateMutableCopy
void GenerateMutableCopy(io::Printer *printer)
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1370
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateFieldAccessorTable
void GenerateFieldAccessorTable(io::Printer *printer, int *bytecode_estimate)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:184
google::protobuf::Descriptor::extension_range
const ExtensionRange * extension_range(int index) const
google::protobuf::compiler::java::ExposePublicParser
bool ExposePublicParser(const FileDescriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:360
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateStaticVariables
virtual void GenerateStaticVariables(io::Printer *printer, int *bytecode_estimate)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:96
google::protobuf::compiler::java::Context::GetFieldGeneratorInfo
const FieldGeneratorInfo * GetFieldGeneratorInfo(const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_context.cc:169
google::protobuf::Descriptor::oneof_decl
const OneofDescriptor * oneof_decl(int index) const
google::protobuf::compiler::java::GetJavaType
JavaType GetJavaType(const FieldDescriptor *field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:319
google::protobuf::FieldDescriptor::LABEL_REQUIRED
@ LABEL_REQUIRED
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:573
google::protobuf::compiler::java::ExtraMessageInterfaces
std::string ExtraMessageInterfaces(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:290
google::protobuf::Descriptor::oneof_decl_count
int oneof_decl_count() const
number
int32_t number
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:850
google::protobuf::FieldDescriptor::number
int number() const
google::protobuf::Descriptor::extension_count
int extension_count() const
google::protobuf::Descriptor::enum_type
const EnumDescriptor * enum_type(int index) const
google::protobuf::FieldDescriptor::LABEL_REPEATED
@ LABEL_REPEATED
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:574
google::protobuf::compiler::java::MessageGenerator::~MessageGenerator
virtual ~MessageGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:80
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateDescriptorMethods
void GenerateDescriptorMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:798
google::protobuf::compiler::java::GetBitFieldName
std::string GetBitFieldName(int index)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:629
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateBuilder
void GenerateBuilder(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:764
google::protobuf::strings::Substitute
string Substitute(const char *format, const SubstituteArg &arg0, const SubstituteArg &arg1, const SubstituteArg &arg2, const SubstituteArg &arg3, const SubstituteArg &arg4, const SubstituteArg &arg5, const SubstituteArg &arg6, const SubstituteArg &arg7, const SubstituteArg &arg8, const SubstituteArg &arg9)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/substitute.cc:55
google::protobuf::Descriptor::extension
const FieldDescriptor * extension(int index) const
google::protobuf::compiler::java::kMaxStaticSize
static const int kMaxStaticSize
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:61
google::protobuf::Descriptor::extension_range_count
int extension_range_count() const
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateAnyMethods
void GenerateAnyMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1370
google::protobuf::compiler::java::MessageGenerator::oneofs_
std::set< const OneofDescriptor * > oneofs_
Definition: protobuf/src/google/protobuf/compiler/java/java_message.h:94
google::protobuf::Descriptor::field_count
int field_count() const
google::protobuf::compiler::java::ImmutableMessageGenerator::~ImmutableMessageGenerator
virtual ~ImmutableMessageGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:94
google::protobuf::compiler::java::ImmutableMessageGenerator::name_resolver_
ClassNameResolver * name_resolver_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:133
google::protobuf::compiler::java::OneofGeneratorInfo::name
std::string name
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:165
google::protobuf::io::Printer
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/printer.h:181
google::protobuf::compiler::java::Context::HasGeneratedMethods
bool HasGeneratedMethods(const Descriptor *descriptor) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_context.cc:193
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateKotlinDsl
void GenerateKotlinDsl(io::Printer *printer) const override
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1404
google::protobuf::Descriptor::nested_type
const Descriptor * nested_type(int index) const
java
google::protobuf::Descriptor::enum_type_count
int enum_type_count() const
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateSerializeOneField
void GenerateSerializeOneField(io::Printer *printer, const FieldDescriptor *field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:751
google::protobuf::compiler::java::ClassNameResolver::GetJavaMutableClassName
std::string GetJavaMutableClassName(const Descriptor *descriptor)
Definition: protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc:353
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateParser
void GenerateParser(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1302
OneofDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:138
google::protobuf::compiler::java::UniqueFileScopeIdentifier
std::string UniqueFileScopeIdentifier(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:218
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateKotlinExtensions
void GenerateKotlinExtensions(io::Printer *printer) const
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1500
google::protobuf::compiler::java::ImmutableMessageGenerator::field_generators_
FieldGeneratorMap< ImmutableFieldGenerator > field_generators_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:134
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
google::protobuf.internal::WireFormat::WireTypeForFieldType
static WireFormatLite::WireType WireTypeForFieldType(FieldDescriptor::Type type)
Definition: bloaty/third_party/protobuf/src/google/protobuf/wire_format.h:319
google::protobuf::Descriptor::name
const std::string & name() const
google::protobuf::Descriptor::file
const FileDescriptor * file() const
GOOGLE_CHECK
#define GOOGLE_CHECK(EXPRESSION)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:153
google::protobuf::FieldDescriptor::TYPE_MESSAGE
@ TYPE_MESSAGE
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:536
google::protobuf::compiler::java::ClassNameResolver::GetKotlinFactoryName
std::string GetKotlinFactoryName(const Descriptor *descriptor)
Definition: protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc:329
google::protobuf::compiler::java::MessageGenerator::descriptor_
const Descriptor * descriptor_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:90
google::protobuf::ToUpper
string ToUpper(const string &s)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil.h:193
google::protobuf::compiler::java::FieldConstantName
std::string FieldConstantName(const FieldDescriptor *field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:309
MessageOptions::no_standard_descriptor_accessor
bool no_standard_descriptor_accessor() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.pb.h:12089
google::protobuf::compiler::java::JAVATYPE_MESSAGE
@ JAVATYPE_MESSAGE
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:214
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateStaticVariableInitializers
virtual int GenerateStaticVariableInitializers(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:146
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
google::protobuf::compiler::java::Context::GetNameResolver
ClassNameResolver * GetNameResolver() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_context.cc:52
google::protobuf::compiler::java::HasRequiredFields
bool HasRequiredFields(const Descriptor *type, std::unordered_set< const Descriptor * > *already_seen)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:840
google::protobuf::compiler::java::ClassNameResolver::GetClassName
std::string GetClassName(const Descriptor *descriptor, bool immutable)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc:227
google::protobuf::compiler::java::OneofGeneratorInfo::capitalized_name
std::string capitalized_name
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:166
google::protobuf::compiler::java::Context::GetOneofGeneratorInfo
const OneofGeneratorInfo * GetOneofGeneratorInfo(const OneofDescriptor *oneof) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_context.cc:180
google::protobuf::compiler::java::IsOwnFile
bool IsOwnFile(const Descriptor *descriptor, bool immutable)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:166
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
google::protobuf::compiler::java::HasPackedFields
bool HasPackedFields(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:341
google::protobuf::compiler::java::ClassNameResolver::GetKotlinExtensionsClassName
std::string GetKotlinExtensionsClassName(const Descriptor *descriptor)
Definition: protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc:347
google::protobuf::compiler::java::PrimitiveTypeName
const char * PrimitiveTypeName(JavaType type)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:365
google::protobuf::compiler::java::SortFieldsByNumber
const FieldDescriptor ** SortFieldsByNumber(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc:824
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateExtensionRegistrationCode
virtual void GenerateExtensionRegistrationCode(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1154
google::protobuf::io::Printer::Outdent
void Outdent()
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/printer.cc:188
google::protobuf::Descriptor::index
int index() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:2091
compiler
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/plugin.pb.cc:21
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::compiler::java::ImmutableMessageGenerator::Generate
virtual void Generate(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:290
google::protobuf::compiler::java::GeneratedCodeVersionSuffix
std::string GeneratedCodeVersionSuffix()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:396
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateInitializers
void GenerateInitializers(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1360
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
google::protobuf::compiler::java::IsAnyMessage
bool IsAnyMessage(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h:383
MessageOptions::message_set_wire_format
bool message_set_wire_format() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.pb.h:12061


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:09