280
string MessageTypeProtoName(const FieldDescriptor* field) {
281
return field->message_type()->full_name();
289
286
// ===================================================================
291
288
MessageGenerator::MessageGenerator(const Descriptor* descriptor,
292
289
const Options& options)
293
: descriptor_(descriptor),
294
classname_(ClassName(descriptor, false)),
296
field_generators_(descriptor, options),
297
nested_generators_(new scoped_ptr<MessageGenerator>[
298
descriptor->nested_type_count()]),
299
enum_generators_(new scoped_ptr<EnumGenerator>[
300
descriptor->enum_type_count()]),
301
extension_generators_(new scoped_ptr<ExtensionGenerator>[
302
descriptor->extension_count()]) {
290
: descriptor_(descriptor),
291
classname_(ClassName(descriptor, false)),
293
field_generators_(descriptor, options),
294
nested_generators_(new scoped_ptr<
295
MessageGenerator>[descriptor->nested_type_count()]),
297
new scoped_ptr<EnumGenerator>[descriptor->enum_type_count()]),
298
extension_generators_(new scoped_ptr<
299
ExtensionGenerator>[descriptor->extension_count()]) {
304
301
for (int i = 0; i < descriptor->nested_type_count(); i++) {
305
302
nested_generators_[i].reset(
442
472
printer->Print("\n");
475
// Generate has_$name$() and clear_has_$name$() functions for oneofs
476
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
477
map<string, string> vars;
478
vars["oneof_name"] = descriptor_->oneof_decl(i)->name();
479
vars["oneof_index"] = SimpleItoa(descriptor_->oneof_decl(i)->index());
480
vars["cap_oneof_name"] =
481
ToUpper(descriptor_->oneof_decl(i)->name());
482
vars["classname"] = classname_;
485
"inline bool $classname$::has_$oneof_name$() {\n"
486
" return $oneof_name$_case() != $cap_oneof_name$_NOT_SET;\n"
488
"inline void $classname$::clear_has_$oneof_name$() {\n"
489
" _oneof_case_[$oneof_index$] = $cap_oneof_name$_NOT_SET;\n"
494
// Helper for the code that emits the Clear() method.
495
static bool CanClearByZeroing(const FieldDescriptor* field) {
496
if (field->is_repeated() || field->is_extension()) return false;
497
switch (field->cpp_type()) {
498
case internal::WireFormatLite::CPPTYPE_ENUM:
499
return field->default_value_enum()->number() == 0;
500
case internal::WireFormatLite::CPPTYPE_INT32:
501
return field->default_value_int32() == 0;
502
case internal::WireFormatLite::CPPTYPE_INT64:
503
return field->default_value_int64() == 0;
504
case internal::WireFormatLite::CPPTYPE_UINT32:
505
return field->default_value_uint32() == 0;
506
case internal::WireFormatLite::CPPTYPE_UINT64:
507
return field->default_value_uint64() == 0;
508
case internal::WireFormatLite::CPPTYPE_FLOAT:
509
return field->default_value_float() == 0;
510
case internal::WireFormatLite::CPPTYPE_DOUBLE:
511
return field->default_value_double() == 0;
512
case internal::WireFormatLite::CPPTYPE_BOOL:
513
return field->default_value_bool() == false;
446
519
void MessageGenerator::
545
656
" ::google::protobuf::io::CodedInputStream* input);\n"
546
657
"void SerializeWithCachedSizes(\n"
547
658
" ::google::protobuf::io::CodedOutputStream* output) const;\n");
659
// DiscardUnknownFields() is implemented in message.cc using reflections. We
660
// need to implement this function in generated code for messages.
661
if (!UseUnknownFieldSet(descriptor_->file())) {
663
"void DiscardUnknownFields();\n");
548
665
if (HasFastArraySerialization(descriptor_->file())) {
550
667
"::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;\n");
671
// Check all FieldDescriptors including those in oneofs to estimate
672
// whether ::std::string is likely to be used, and depending on that
673
// estimate, set uses_string_ to true or false. That contols
674
// whether to force initialization of empty_string_ in SharedCtor().
675
// It's often advantageous to do so to keep "is empty_string_
676
// inited?" code from appearing all over the place.
677
vector<const FieldDescriptor*> descriptors;
678
for (int i = 0; i < descriptor_->field_count(); i++) {
679
descriptors.push_back(descriptor_->field(i));
681
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
682
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
683
descriptors.push_back(descriptor_->oneof_decl(i)->field(j));
686
uses_string_ = false;
687
for (int i = 0; i < descriptors.size(); i++) {
688
const FieldDescriptor* field = descriptors[i];
689
if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) {
690
switch (field->options().ctype()) {
691
default: uses_string_ = true; break;
555
697
"int GetCachedSize() const { return _cached_size_; }\n"
557
699
"void SharedCtor();\n"
558
700
"void SharedDtor();\n"
559
701
"void SetCachedSize(int size) const;\n"
563
704
if (HasDescriptorMethods(descriptor_->file())) {
622
763
"inline void set_has_$name$();\n",
623
764
"name", FieldName(descriptor_->field(i)));
625
"inline void clear_has_$name$();\n",
626
"name", FieldName(descriptor_->field(i)));
765
if (!descriptor_->field(i)->containing_oneof()) {
767
"inline void clear_has_$name$();\n",
768
"name", FieldName(descriptor_->field(i)));
629
772
printer->Print("\n");
774
// Generate oneof function declarations
775
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
777
"inline bool has_$oneof_name$();\n"
778
"void clear_$oneof_name$();\n"
779
"inline void clear_has_$oneof_name$();\n\n",
780
"oneof_name", descriptor_->oneof_decl(i)->name());
783
// Prepare decls for _cached_size_ and _has_bits_. Their position in the
784
// output will be determined later.
786
bool need_to_emit_cached_size = true;
787
// TODO(kenton): Make _cached_size_ an atomic<int> when C++ supports it.
788
const string cached_size_decl = "mutable int _cached_size_;\n";
790
// TODO(jieluo) - Optimize _has_bits_ for repeated and oneof fields.
791
size_t sizeof_has_bits = (descriptor_->field_count() + 31) / 32 * 4;
792
if (descriptor_->field_count() == 0) {
793
// Zero-size arrays aren't technically allowed, and MSVC in particular
794
// doesn't like them. We still need to declare these arrays to make
795
// other code compile. Since this is an uncommon case, we'll just declare
796
// them with size 1 and waste some space. Oh well.
799
const string has_bits_decl = sizeof_has_bits == 0 ? "" :
800
"::google::protobuf::uint32 _has_bits_[" + SimpleItoa(sizeof_has_bits / 4) + "];\n";
631
803
// To minimize padding, data members are divided into three sections:
632
804
// (1) members assumed to align to 8 bytes
633
805
// (2) members corresponding to message fields, re-ordered to optimize
645
if (HasUnknownFields(descriptor_->file())) {
817
if (UseUnknownFieldSet(descriptor_->file())) {
647
819
"::google::protobuf::UnknownFieldSet _unknown_fields_;\n"
823
"::std::string _unknown_fields_;\n"
827
// _has_bits_ is frequently accessed, so to reduce code size and improve
828
// speed, it should be close to the start of the object. But, try not to
829
// waste space:_has_bits_ by itself always makes sense if its size is a
830
// multiple of 8, but, otherwise, maybe _has_bits_ and cached_size_ together
832
printer->Print(has_bits_decl.c_str());
833
if ((sizeof_has_bits % 8) != 0) {
834
printer->Print(cached_size_decl.c_str());
835
need_to_emit_cached_size = false;
651
838
// Field members:
840
// List fields which doesn't belong to any oneof
653
841
vector<const FieldDescriptor*> fields;
842
hash_map<string, int> fieldname_to_chunk;
654
843
for (int i = 0; i < descriptor_->field_count(); i++) {
655
fields.push_back(descriptor_->field(i));
844
if (!descriptor_->field(i)->containing_oneof()) {
845
const FieldDescriptor* field = descriptor_->field(i);
846
fields.push_back(field);
847
fieldname_to_chunk[FieldName(field)] = i / 8;
657
850
OptimizePadding(&fields);
851
// Emit some private and static members
852
runs_of_fields_ = vector< vector<string> >(1);
658
853
for (int i = 0; i < fields.size(); ++i) {
659
field_generators_.get(fields[i]).GeneratePrivateMembers(printer);
854
const FieldDescriptor* field = fields[i];
855
const FieldGenerator& generator = field_generators_.get(field);
856
generator.GenerateStaticMembers(printer);
857
generator.GeneratePrivateMembers(printer);
858
if (CanClearByZeroing(field)) {
859
const string& fieldname = FieldName(field);
860
if (!runs_of_fields_.back().empty() &&
861
(fieldname_to_chunk[runs_of_fields_.back().back()] !=
862
fieldname_to_chunk[fieldname])) {
863
runs_of_fields_.push_back(vector<string>());
865
runs_of_fields_.back().push_back(fieldname);
866
} else if (!runs_of_fields_.back().empty()) {
867
runs_of_fields_.push_back(vector<string>());
871
// For each oneof generate a union
872
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
874
"union $camel_oneof_name$Union {\n",
876
UnderscoresToCamelCase(descriptor_->oneof_decl(i)->name(), true));
878
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
879
field_generators_.get(descriptor_->oneof_decl(i)->
880
field(j)).GeneratePrivateMembers(printer);
884
"} $oneof_name$_;\n",
885
"oneof_name", descriptor_->oneof_decl(i)->name());
886
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
887
field_generators_.get(descriptor_->oneof_decl(i)->
888
field(j)).GenerateStaticMembers(printer);
662
892
// Members assumed to align to 4 bytes:
664
// TODO(kenton): Make _cached_size_ an atomic<int> when C++ supports it.
667
"mutable int _cached_size_;\n");
894
if (need_to_emit_cached_size) {
895
printer->Print(cached_size_decl.c_str());
896
need_to_emit_cached_size = false;
669
// Generate _has_bits_.
670
if (descriptor_->field_count() > 0) {
899
// Generate _oneof_case_.
900
if (descriptor_->oneof_decl_count() > 0) {
671
901
printer->Print(vars,
672
"::google::protobuf::uint32 _has_bits_[($field_count$ + 31) / 32];\n"
675
// Zero-size arrays aren't technically allowed, and MSVC in particular
676
// doesn't like them. We still need to declare these arrays to make
677
// other code compile. Since this is an uncommon case, we'll just declare
678
// them with size 1 and waste some space. Oh well.
680
"::google::protobuf::uint32 _has_bits_[1];\n"
902
"::google::protobuf::uint32 _oneof_case_[$oneof_decl_count$];\n"
978
1262
"static const int $classname$_offsets_[$field_count$] = {\n",
979
1263
"classname", classname_,
980
"field_count", SimpleItoa(max(1, descriptor_->field_count())));
1264
"field_count", SimpleItoa(max(
1265
1, descriptor_->field_count() + descriptor_->oneof_decl_count())));
981
1266
printer->Indent();
983
1268
for (int i = 0; i < descriptor_->field_count(); i++) {
984
1269
const FieldDescriptor* field = descriptor_->field(i);
1270
if (field->containing_oneof()) {
1272
"PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET("
1273
"$classname$_default_oneof_instance_, $name$_),\n",
1274
"classname", classname_,
1275
"name", FieldName(field));
1278
"GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
1280
"classname", classname_,
1281
"name", FieldName(field));
1285
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
1286
const OneofDescriptor* oneof = descriptor_->oneof_decl(i);
986
1288
"GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, $name$_),\n",
987
1289
"classname", classname_,
988
"name", FieldName(field));
1290
"name", oneof->name());
991
1293
printer->Outdent();
1181
1536
"classname", classname_);
1182
1537
printer->Indent();
1184
int last_index = -1;
1539
// Step 1: Extensions
1186
1540
if (descriptor_->extension_range_count() > 0) {
1187
1541
printer->Print("_extensions_.Clear();\n");
1190
for (int i = 0; i < descriptor_->field_count(); i++) {
1191
const FieldDescriptor* field = descriptor_->field(i);
1193
if (!field->is_repeated()) {
1194
// We can use the fact that _has_bits_ is a giant bitfield to our
1195
// advantage: We can check up to 32 bits at a time for equality to
1196
// zero, and skip the whole range if so. This can improve the speed
1197
// of Clear() for messages which contain a very large number of
1198
// optional fields of which only a few are used at a time. Here,
1199
// we've chosen to check 8 bits at a time rather than 32.
1200
if (i / 8 != last_index / 8 || last_index < 0) {
1201
if (last_index >= 0) {
1203
printer->Print("}\n");
1206
"if (_has_bits_[$index$ / 32] & (0xffu << ($index$ % 32))) {\n",
1207
"index", SimpleItoa(field->index()));
1212
// It's faster to just overwrite primitive types, but we should
1213
// only clear strings and messages if they were set.
1214
// TODO(kenton): Let the CppFieldGenerator decide this somehow.
1215
bool should_check_bit =
1216
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ||
1217
field->cpp_type() == FieldDescriptor::CPPTYPE_STRING;
1219
if (should_check_bit) {
1221
"if (has_$name$()) {\n",
1222
"name", FieldName(field));
1226
field_generators_.get(field).GenerateClearingCode(printer);
1228
if (should_check_bit) {
1544
// Step 2: Everything but extensions, repeateds, unions.
1545
// These are handled in chunks of 8. The first chunk is
1546
// the non-extensions-non-repeateds-non-unions in
1547
// descriptor_->field(0), descriptor_->field(1), ... descriptor_->field(7),
1548
// and the second chunk is the same for
1549
// descriptor_->field(8), descriptor_->field(9), ... descriptor_->field(15),
1551
set<int> step2_indices;
1552
hash_map<string, int> fieldname_to_chunk;
1553
hash_map<int, string> memsets_for_chunk;
1554
hash_map<int, int> memset_field_count_for_chunk;
1555
hash_set<string> handled; // fields that appear anywhere in memsets_for_chunk
1556
hash_map<int, uint32> fields_mask_for_chunk;
1557
for (int i = 0; i < descriptor_->field_count(); i++) {
1558
const FieldDescriptor* field = descriptor_->field(i);
1559
if (!field->is_repeated() && !field->containing_oneof()) {
1560
step2_indices.insert(i);
1562
fieldname_to_chunk[FieldName(field)] = chunk;
1563
fields_mask_for_chunk[chunk] |= static_cast<uint32>(1) << (i % 32);
1567
// Step 2a: Greedily seek runs of fields that can be cleared by memset-to-0.
1568
// The generated code uses two macros to help it clear runs of fields:
1569
// OFFSET_OF_FIELD_ computes the offset (in bytes) of a field in the Message.
1570
// ZR_ zeroes a non-empty range of fields via memset.
1571
const char* macros =
1572
"#define OFFSET_OF_FIELD_(f) (reinterpret_cast<char*>( \\\n"
1573
" &reinterpret_cast<$classname$*>(16)->f) - \\\n"
1574
" reinterpret_cast<char*>(16))\n\n"
1575
"#define ZR_(first, last) do { \\\n"
1576
" size_t f = OFFSET_OF_FIELD_(first); \\\n"
1577
" size_t n = OFFSET_OF_FIELD_(last) - f + sizeof(last); \\\n"
1578
" ::memset(&first, 0, n); \\\n"
1580
for (int i = 0; i < runs_of_fields_.size(); i++) {
1581
const vector<string>& run = runs_of_fields_[i];
1582
if (run.size() < 2) continue;
1583
const string& first_field_name = run[0];
1584
const string& last_field_name = run.back();
1585
int chunk = fieldname_to_chunk[run[0]];
1586
memsets_for_chunk[chunk].append(
1587
"ZR_(" + first_field_name + "_, " + last_field_name + "_);\n");
1588
for (int j = 0; j < run.size(); j++) {
1589
GOOGLE_DCHECK_EQ(chunk, fieldname_to_chunk[run[j]]);
1590
handled.insert(run[j]);
1592
memset_field_count_for_chunk[chunk] += run.size();
1594
const bool macros_are_needed = handled.size() > 0;
1595
if (macros_are_needed) {
1597
printer->Print(macros,
1598
"classname", classname_);
1601
// Step 2b: Finish step 2, ignoring fields handled in step 2a.
1602
int last_index = -1;
1603
bool chunk_block_in_progress = false;
1604
for (int i = 0; i < descriptor_->field_count(); i++) {
1605
if (step2_indices.count(i) == 0) continue;
1606
const FieldDescriptor* field = descriptor_->field(i);
1607
const string fieldname = FieldName(field);
1608
if (i / 8 != last_index / 8 || last_index < 0) {
1609
// End previous chunk, if there was one.
1610
if (chunk_block_in_progress) {
1229
1611
printer->Outdent();
1230
1612
printer->Print("}\n");
1613
chunk_block_in_progress = false;
1616
const string& memsets = memsets_for_chunk[i / 8];
1617
uint32 mask = fields_mask_for_chunk[i / 8];
1618
int count = popcnt(mask);
1620
(count <= 4 && count == memset_field_count_for_chunk[i / 8])) {
1621
// No "if" here because the chunk is trivial.
1624
"if (_has_bits_[$index$ / 32] & $mask$) {\n",
1625
"index", SimpleItoa(i / 8 * 8),
1626
"mask", SimpleItoa(mask));
1628
chunk_block_in_progress = true;
1630
printer->Print(memsets.c_str());
1633
if (handled.count(fieldname) > 0) continue;
1635
// It's faster to just overwrite primitive types, but we should
1636
// only clear strings and messages if they were set.
1637
// TODO(kenton): Let the CppFieldGenerator decide this somehow.
1638
bool should_check_bit =
1639
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ||
1640
field->cpp_type() == FieldDescriptor::CPPTYPE_STRING;
1642
if (should_check_bit) {
1643
printer->Print("if (has_$name$()) {\n", "name", fieldname);
1647
field_generators_.get(field).GenerateClearingCode(printer);
1649
if (should_check_bit) {
1651
printer->Print("}\n");
1235
if (last_index >= 0) {
1655
if (chunk_block_in_progress) {
1236
1656
printer->Outdent();
1237
1657
printer->Print("}\n");
1659
if (macros_are_needed) {
1661
printer->Print("\n#undef OFFSET_OF_FIELD_\n#undef ZR_\n\n");
1240
// Repeated fields don't use _has_bits_ so we clear them in a separate
1665
// Step 3: Repeated fields don't use _has_bits_; emit code to clear them here.
1242
1666
for (int i = 0; i < descriptor_->field_count(); i++) {
1243
1667
const FieldDescriptor* field = descriptor_->field(i);
1262
1697
void MessageGenerator::
1698
GenerateOneofClear(io::Printer* printer) {
1699
// Generated function clears the active field and union case (e.g. foo_case_).
1700
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
1702
"void $classname$::clear_$oneofname$() {\n",
1703
"classname", classname_,
1704
"oneofname", descriptor_->oneof_decl(i)->name());
1707
"switch($oneofname$_case()) {\n",
1708
"oneofname", descriptor_->oneof_decl(i)->name());
1710
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
1711
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
1713
"case k$field_name$: {\n",
1714
"field_name", UnderscoresToCamelCase(field->name(), true));
1716
// We clear only allocated objects in oneofs
1717
if (!IsStringOrMessage(field)) {
1719
"// No need to clear\n");
1721
field_generators_.get(field).GenerateClearingCode(printer);
1730
"case $cap_oneof_name$_NOT_SET: {\n"
1734
ToUpper(descriptor_->oneof_decl(i)->name()));
1738
"_oneof_case_[$oneof_index$] = $cap_oneof_name$_NOT_SET;\n",
1739
"oneof_index", SimpleItoa(i),
1741
ToUpper(descriptor_->oneof_decl(i)->name()));
1749
void MessageGenerator::
1263
1750
GenerateSwap(io::Printer* printer) {
1264
1751
// Generate the Swap member function.
1265
1752
printer->Print("void $classname$::Swap($classname$* other) {\n",
1852
// Merge oneof fields. Oneof field requires oneof case check.
1853
for (int i = 0; i < descriptor_->oneof_decl_count(); ++i) {
1855
"switch (from.$oneofname$_case()) {\n",
1856
"oneofname", descriptor_->oneof_decl(i)->name());
1858
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
1859
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
1861
"case k$field_name$: {\n",
1862
"field_name", UnderscoresToCamelCase(field->name(), true));
1864
field_generators_.get(field).GenerateMergingCode(printer);
1872
"case $cap_oneof_name$_NOT_SET: {\n"
1876
ToUpper(descriptor_->oneof_decl(i)->name()));
1355
1882
// Merge Optional and Required fields (after a _has_bit check).
1356
1883
int last_index = -1;
1358
1885
for (int i = 0; i < descriptor_->field_count(); ++i) {
1359
1886
const FieldDescriptor* field = descriptor_->field(i);
1361
if (!field->is_repeated()) {
1888
if (!field->is_repeated() && !field->containing_oneof()) {
1362
1889
// See above in GenerateClear for an explanation of this.
1363
1890
if (i / 8 != last_index / 8 || last_index < 0) {
1364
1891
if (last_index >= 0) {
1465
1995
printer->Print(
1466
1996
"bool $classname$::MergePartialFromCodedStream(\n"
1467
1997
" ::google::protobuf::io::CodedInputStream* input) {\n"
1468
"#define DO_(EXPRESSION) if (!(EXPRESSION)) return false\n"
1469
" ::google::protobuf::uint32 tag;\n"
1470
" while ((tag = input->ReadTag()) != 0) {\n",
1998
"#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure\n"
1999
" ::google::protobuf::uint32 tag;\n",
1471
2000
"classname", classname_);
2002
if (!UseUnknownFieldSet(descriptor_->file())) {
2004
" ::google::protobuf::io::StringOutputStream unknown_fields_string(\n"
2005
" mutable_unknown_fields());\n"
2006
" ::google::protobuf::io::CodedOutputStream unknown_fields_stream(\n"
2007
" &unknown_fields_string);\n");
2011
" // @@protoc_insertion_point(parse_start:$full_name$)\n",
2012
"full_name", descriptor_->full_name());
2015
printer->Print("for (;;) {\n");
2018
scoped_array<const FieldDescriptor*> ordered_fields(
2019
SortFieldsByNumber(descriptor_));
2020
uint32 maxtag = descriptor_->field_count() == 0 ? 0 :
2021
WireFormat::MakeTag(ordered_fields[descriptor_->field_count() - 1]);
2022
const int kCutoff0 = 127; // fits in 1-byte varint
2023
const int kCutoff1 = (127 << 7) + 127; // fits in 2-byte varint
2024
printer->Print("::std::pair< ::google::protobuf::uint32, bool> p = "
2025
"input->ReadTagWithCutoff($max$);\n"
2027
"if (!p.second) goto handle_unusual;\n",
2028
"max", SimpleItoa(maxtag <= kCutoff0 ? kCutoff0 :
2029
(maxtag <= kCutoff1 ? kCutoff1 :
1476
2031
if (descriptor_->field_count() > 0) {
1477
2032
// We don't even want to print the switch() if we have no fields because
1478
2033
// MSVC dislikes switch() statements that contain only a default value.
1524
2074
// Emit code to parse unexpectedly packed or unpacked values.
1525
2075
if (field->is_packable() && field->options().packed()) {
1527
"} else if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag)\n"
1528
" == ::google::protobuf::internal::WireFormatLite::\n"
1529
" WIRETYPE_$wiretype$) {\n",
1531
kWireTypeNames[WireFormat::WireTypeForFieldType(field->type())]);
2076
internal::WireFormatLite::WireType wiretype =
2077
WireFormat::WireTypeForFieldType(field->type());
2078
printer->Print("} else if (tag == $uncommontag$) {\n",
2079
"uncommontag", SimpleItoa(
2080
internal::WireFormatLite::MakeTag(
2081
field->number(), wiretype)));
1532
2082
printer->Indent();
1533
2083
field_generator.GenerateMergeFromCodedStream(printer);
1534
2084
printer->Outdent();
1535
2085
} else if (field->is_packable() && !field->options().packed()) {
1537
"} else if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag)\n"
1538
" == ::google::protobuf::internal::WireFormatLite::\n"
1539
" WIRETYPE_LENGTH_DELIMITED) {\n");
2086
internal::WireFormatLite::WireType wiretype =
2087
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
2088
printer->Print("} else if (tag == $uncommontag$) {\n",
2089
"uncommontag", SimpleItoa(
2090
internal::WireFormatLite::MakeTag(
2091
field->number(), wiretype)));
1540
2092
printer->Indent();
1541
2093
field_generator.GenerateMergeFromCodedStreamWithPacking(printer);
1542
2094
printer->Outdent();
2497
// Fields inside a oneof don't use _has_bits_ so we count them in a separate
2499
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
2501
"switch ($oneofname$_case()) {\n",
2502
"oneofname", descriptor_->oneof_decl(i)->name());
2504
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
2505
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
2506
PrintFieldComment(printer, field);
2508
"case k$field_name$: {\n",
2509
"field_name", UnderscoresToCamelCase(field->name(), true));
2511
field_generators_.get(field).GenerateByteSize(printer);
2519
"case $cap_oneof_name$_NOT_SET: {\n"
2523
ToUpper(descriptor_->oneof_decl(i)->name()));
1918
2529
if (descriptor_->extension_range_count() > 0) {
1919
2530
printer->Print(
1920
2531
"total_size += _extensions_.ByteSize();\n"
1924
if (HasUnknownFields(descriptor_->file())) {
2535
if (UseUnknownFieldSet(descriptor_->file())) {
1925
2536
printer->Print("if (!unknown_fields().empty()) {\n");
1926
2537
printer->Indent();
1927
2538
printer->Print(