wire_format.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 <stack>
36 #include <string>
37 #include <vector>
38 
40 
53 
54 
55 #include <google/protobuf/port_def.inc>
56 
57 const size_t kMapEntryTagByteSize = 2;
58 
59 namespace google {
60 namespace protobuf {
61 namespace internal {
62 
63 // Forward declare static functions
64 static size_t MapKeyDataOnlyByteSize(const FieldDescriptor* field,
65  const MapKey& value);
67  const MapValueRef& value);
68 
69 // ===================================================================
70 
72  uint32 tag) {
74 }
75 
78 }
79 
81  unknown_fields_->AddVarint(field_number, value);
82 }
83 
85  UnknownFieldSet* unknown_fields) {
87  // Field number 0 is illegal.
88  if (number == 0) return false;
89 
90  switch (WireFormatLite::GetTagWireType(tag)) {
92  uint64 value;
93  if (!input->ReadVarint64(&value)) return false;
94  if (unknown_fields != NULL) unknown_fields->AddVarint(number, value);
95  return true;
96  }
98  uint64 value;
99  if (!input->ReadLittleEndian64(&value)) return false;
100  if (unknown_fields != NULL) unknown_fields->AddFixed64(number, value);
101  return true;
102  }
104  uint32 length;
105  if (!input->ReadVarint32(&length)) return false;
106  if (unknown_fields == NULL) {
107  if (!input->Skip(length)) return false;
108  } else {
109  if (!input->ReadString(unknown_fields->AddLengthDelimited(number),
110  length)) {
111  return false;
112  }
113  }
114  return true;
115  }
117  if (!input->IncrementRecursionDepth()) return false;
118  if (!SkipMessage(input, (unknown_fields == NULL)
119  ? NULL
120  : unknown_fields->AddGroup(number))) {
121  return false;
122  }
123  input->DecrementRecursionDepth();
124  // Check that the ending tag matched the starting tag.
125  if (!input->LastTagWas(
128  return false;
129  }
130  return true;
131  }
133  return false;
134  }
136  uint32 value;
137  if (!input->ReadLittleEndian32(&value)) return false;
138  if (unknown_fields != NULL) unknown_fields->AddFixed32(number, value);
139  return true;
140  }
141  default: {
142  return false;
143  }
144  }
145 }
146 
148  UnknownFieldSet* unknown_fields) {
149  while (true) {
150  uint32 tag = input->ReadTag();
151  if (tag == 0) {
152  // End of input. This is a valid place to end, so return true.
153  return true;
154  }
155 
157 
158  if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) {
159  // Must be the end of the message.
160  return true;
161  }
162 
163  if (!SkipField(input, tag, unknown_fields)) return false;
164  }
165 }
166 
168  uint32 field_number,
169  bool (*is_valid)(int),
170  UnknownFieldSet* unknown_fields,
172  uint32 length;
173  if (!input->ReadVarint32(&length)) return false;
174  io::CodedInputStream::Limit limit = input->PushLimit(length);
175  while (input->BytesUntilLimit() > 0) {
176  int value;
177  if (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
178  input, &value)) {
179  return false;
180  }
181  if (is_valid == NULL || is_valid(value)) {
182  values->Add(value);
183  } else {
184  unknown_fields->AddVarint(field_number, value);
185  }
186  }
187  input->PopLimit(limit);
188  return true;
189 }
190 
193  for (int i = 0; i < unknown_fields.field_count(); i++) {
194  const UnknownField& field = unknown_fields.field(i);
195  switch (field.type()) {
197  output->WriteVarint32(WireFormatLite::MakeTag(
199  output->WriteVarint64(field.varint());
200  break;
202  output->WriteVarint32(WireFormatLite::MakeTag(
204  output->WriteLittleEndian32(field.fixed32());
205  break;
207  output->WriteVarint32(WireFormatLite::MakeTag(
209  output->WriteLittleEndian64(field.fixed64());
210  break;
212  output->WriteVarint32(WireFormatLite::MakeTag(
214  output->WriteVarint32(field.length_delimited().size());
215  output->WriteRawMaybeAliased(field.length_delimited().data(),
216  field.length_delimited().size());
217  break;
219  output->WriteVarint32(WireFormatLite::MakeTag(
222  output->WriteVarint32(WireFormatLite::MakeTag(
224  break;
225  }
226  }
227 }
228 
230  const UnknownFieldSet& unknown_fields, uint8* target) {
231  for (int i = 0; i < unknown_fields.field_count(); i++) {
232  const UnknownField& field = unknown_fields.field(i);
233 
234  switch (field.type()) {
237  field.varint(), target);
238  break;
241  field.fixed32(), target);
242  break;
245  field.fixed64(), target);
246  break;
249  field.number(), field.length_delimited(), target);
250  break;
257  break;
258  }
259  }
260  return target;
261 }
262 
264  const UnknownFieldSet& unknown_fields, io::CodedOutputStream* output) {
265  for (int i = 0; i < unknown_fields.field_count(); i++) {
266  const UnknownField& field = unknown_fields.field(i);
267  // The only unknown fields that are allowed to exist in a MessageSet are
268  // messages, which are length-delimited.
270  // Start group.
272 
273  // Write type ID.
275  output->WriteVarint32(field.number());
276 
277  // Write message.
279  field.SerializeLengthDelimitedNoTag(output);
280 
281  // End group.
283  }
284  }
285 }
286 
288  const UnknownFieldSet& unknown_fields, uint8* target) {
289  for (int i = 0; i < unknown_fields.field_count(); i++) {
290  const UnknownField& field = unknown_fields.field(i);
291 
292  // The only unknown fields that are allowed to exist in a MessageSet are
293  // messages, which are length-delimited.
295  // Start group.
298 
299  // Write type ID.
302  target =
304 
305  // Write message.
308  target = field.SerializeLengthDelimitedNoTagToArray(target);
309 
310  // End group.
313  }
314  }
315 
316  return target;
317 }
318 
320  const UnknownFieldSet& unknown_fields) {
321  size_t size = 0;
322  for (int i = 0; i < unknown_fields.field_count(); i++) {
323  const UnknownField& field = unknown_fields.field(i);
324 
325  switch (field.type()) {
330  break;
334  size += sizeof(int32);
335  break;
339  size += sizeof(int64);
340  break;
345  field.length_delimited().size());
346  size += field.length_delimited().size();
347  break;
351  size += ComputeUnknownFieldsSize(field.group());
354  break;
355  }
356  }
357 
358  return size;
359 }
360 
362  const UnknownFieldSet& unknown_fields) {
363  size_t size = 0;
364  for (int i = 0; i < unknown_fields.field_count(); i++) {
365  const UnknownField& field = unknown_fields.field(i);
366 
367  // The only unknown fields that are allowed to exist in a MessageSet are
368  // messages, which are length-delimited.
372 
373  int field_size = field.GetLengthDelimitedSize();
375  size += field_size;
376  }
377  }
378 
379  return size;
380 }
381 
382 // ===================================================================
383 
385  Message* message) {
386  const Descriptor* descriptor = message->GetDescriptor();
387  const Reflection* message_reflection = message->GetReflection();
388 
389  while (true) {
390  uint32 tag = input->ReadTag();
391  if (tag == 0) {
392  // End of input. This is a valid place to end, so return true.
393  return true;
394  }
395 
398  // Must be the end of the message.
399  return true;
400  }
401 
402  const FieldDescriptor* field = NULL;
403 
404  if (descriptor != NULL) {
405  int field_number = WireFormatLite::GetTagFieldNumber(tag);
406  field = descriptor->FindFieldByNumber(field_number);
407 
408  // If that failed, check if the field is an extension.
409  if (field == NULL && descriptor->IsExtensionNumber(field_number)) {
410  if (input->GetExtensionPool() == NULL) {
411  field = message_reflection->FindKnownExtensionByNumber(field_number);
412  } else {
413  field = input->GetExtensionPool()->FindExtensionByNumber(
414  descriptor, field_number);
415  }
416  }
417 
418  // If that failed, but we're a MessageSet, and this is the tag for a
419  // MessageSet item, then parse that.
420  if (field == NULL && descriptor->options().message_set_wire_format() &&
423  return false;
424  }
425  continue; // Skip ParseAndMergeField(); already taken care of.
426  }
427  }
428 
429  if (!ParseAndMergeField(tag, field, message, input)) {
430  return false;
431  }
432  }
433 }
434 
436  uint32 field_number,
437  UnknownFieldSet* unknown_fields) {
438  uint32 length;
439  if (!input->ReadVarint32(&length)) return false;
440  return input->ReadString(unknown_fields->AddLengthDelimited(field_number),
441  length);
442 }
443 
445  const FieldDescriptor* field,
446  Message* message,
448  const Reflection* message_reflection = message->GetReflection();
449  if (field == NULL) {
450  // We store unknown MessageSet extensions as groups.
451  return SkipMessageSetField(
452  input, field_number, message_reflection->MutableUnknownFields(message));
453  } else if (field->is_repeated() ||
455  // This shouldn't happen as we only allow optional message extensions to
456  // MessageSet.
457  GOOGLE_LOG(ERROR) << "Extensions of MessageSets must be optional messages.";
458  return false;
459  } else {
460  Message* sub_message = message_reflection->MutableMessage(
461  message, field, input->GetExtensionFactory());
462  return WireFormatLite::ReadMessage(input, sub_message);
463  }
464 }
465 
466 static bool StrictUtf8Check(const FieldDescriptor* field) {
467  return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
468 }
469 
471  uint32 tag,
472  const FieldDescriptor* field, // May be NULL for unknown
474  const Reflection* message_reflection = message->GetReflection();
475 
476  enum { UNKNOWN, NORMAL_FORMAT, PACKED_FORMAT } value_format;
477 
478  if (field == NULL) {
479  value_format = UNKNOWN;
480  } else if (WireFormatLite::GetTagWireType(tag) ==
481  WireTypeForFieldType(field->type())) {
482  value_format = NORMAL_FORMAT;
483  } else if (field->is_packable() &&
486  value_format = PACKED_FORMAT;
487  } else {
488  // We don't recognize this field. Either the field number is unknown
489  // or the wire type doesn't match. Put it in our unknown field set.
490  value_format = UNKNOWN;
491  }
492 
493  if (value_format == UNKNOWN) {
494  return SkipField(input, tag,
495  message_reflection->MutableUnknownFields(message));
496  } else if (value_format == PACKED_FORMAT) {
497  uint32 length;
498  if (!input->ReadVarint32(&length)) return false;
499  io::CodedInputStream::Limit limit = input->PushLimit(length);
500 
501  switch (field->type()) {
502 #define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \
503  case FieldDescriptor::TYPE_##TYPE: { \
504  while (input->BytesUntilLimit() > 0) { \
505  CPPTYPE value; \
506  if (!WireFormatLite::ReadPrimitive<CPPTYPE, \
507  WireFormatLite::TYPE_##TYPE>(input, \
508  &value)) \
509  return false; \
510  message_reflection->Add##CPPTYPE_METHOD(message, field, value); \
511  } \
512  break; \
513  }
514 
517  HANDLE_PACKED_TYPE(SINT32, int32, Int32)
518  HANDLE_PACKED_TYPE(SINT64, int64, Int64)
521 
522  HANDLE_PACKED_TYPE(FIXED32, uint32, UInt32)
523  HANDLE_PACKED_TYPE(FIXED64, uint64, UInt64)
524  HANDLE_PACKED_TYPE(SFIXED32, int32, Int32)
525  HANDLE_PACKED_TYPE(SFIXED64, int64, Int64)
526 
527  HANDLE_PACKED_TYPE(FLOAT, float, Float)
528  HANDLE_PACKED_TYPE(DOUBLE, double, Double)
529 
530  HANDLE_PACKED_TYPE(BOOL, bool, Bool)
531 #undef HANDLE_PACKED_TYPE
532 
534  while (input->BytesUntilLimit() > 0) {
535  int value;
536  if (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
537  input, &value))
538  return false;
539  if (message->GetDescriptor()->file()->syntax() ==
541  message_reflection->AddEnumValue(message, field, value);
542  } else {
543  const EnumValueDescriptor* enum_value =
544  field->enum_type()->FindValueByNumber(value);
545  if (enum_value != NULL) {
546  message_reflection->AddEnum(message, field, enum_value);
547  } else {
548  // The enum value is not one of the known values. Add it to the
549  // UnknownFieldSet.
550  int64 sign_extended_value = static_cast<int64>(value);
551  message_reflection->MutableUnknownFields(message)->AddVarint(
552  WireFormatLite::GetTagFieldNumber(tag), sign_extended_value);
553  }
554  }
555  }
556 
557  break;
558  }
559 
564  // Can't have packed fields of these types: these should be caught by
565  // the protocol compiler.
566  return false;
567  break;
568  }
569 
570  input->PopLimit(limit);
571  } else {
572  // Non-packed value (value_format == NORMAL_FORMAT)
573  switch (field->type()) {
574 #define HANDLE_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \
575  case FieldDescriptor::TYPE_##TYPE: { \
576  CPPTYPE value; \
577  if (!WireFormatLite::ReadPrimitive<CPPTYPE, WireFormatLite::TYPE_##TYPE>( \
578  input, &value)) \
579  return false; \
580  if (field->is_repeated()) { \
581  message_reflection->Add##CPPTYPE_METHOD(message, field, value); \
582  } else { \
583  message_reflection->Set##CPPTYPE_METHOD(message, field, value); \
584  } \
585  break; \
586  }
587 
588  HANDLE_TYPE(INT32, int32, Int32)
589  HANDLE_TYPE(INT64, int64, Int64)
590  HANDLE_TYPE(SINT32, int32, Int32)
591  HANDLE_TYPE(SINT64, int64, Int64)
592  HANDLE_TYPE(UINT32, uint32, UInt32)
593  HANDLE_TYPE(UINT64, uint64, UInt64)
594 
595  HANDLE_TYPE(FIXED32, uint32, UInt32)
596  HANDLE_TYPE(FIXED64, uint64, UInt64)
597  HANDLE_TYPE(SFIXED32, int32, Int32)
598  HANDLE_TYPE(SFIXED64, int64, Int64)
599 
600  HANDLE_TYPE(FLOAT, float, Float)
601  HANDLE_TYPE(DOUBLE, double, Double)
602 
603  HANDLE_TYPE(BOOL, bool, Bool)
604 #undef HANDLE_TYPE
605 
607  int value;
608  if (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
609  input, &value))
610  return false;
611  if (field->is_repeated()) {
612  message_reflection->AddEnumValue(message, field, value);
613  } else {
614  message_reflection->SetEnumValue(message, field, value);
615  }
616  break;
617  }
618 
619  // Handle strings separately so that we can optimize the ctype=CORD case.
621  bool strict_utf8_check = StrictUtf8Check(field);
623  if (!WireFormatLite::ReadString(input, &value)) return false;
624  if (strict_utf8_check) {
625  if (!WireFormatLite::VerifyUtf8String(value.data(), value.length(),
627  field->full_name().c_str())) {
628  return false;
629  }
630  } else {
631  VerifyUTF8StringNamedField(value.data(), value.length(), PARSE,
632  field->full_name().c_str());
633  }
634  if (field->is_repeated()) {
635  message_reflection->AddString(message, field, value);
636  } else {
637  message_reflection->SetString(message, field, value);
638  }
639  break;
640  }
641 
644  if (!WireFormatLite::ReadBytes(input, &value)) return false;
645  if (field->is_repeated()) {
646  message_reflection->AddString(message, field, value);
647  } else {
648  message_reflection->SetString(message, field, value);
649  }
650  break;
651  }
652 
654  Message* sub_message;
655  if (field->is_repeated()) {
656  sub_message = message_reflection->AddMessage(
657  message, field, input->GetExtensionFactory());
658  } else {
659  sub_message = message_reflection->MutableMessage(
660  message, field, input->GetExtensionFactory());
661  }
662 
664  input, sub_message))
665  return false;
666  break;
667  }
668 
670  Message* sub_message;
671  if (field->is_repeated()) {
672  sub_message = message_reflection->AddMessage(
673  message, field, input->GetExtensionFactory());
674  } else {
675  sub_message = message_reflection->MutableMessage(
676  message, field, input->GetExtensionFactory());
677  }
678 
679  if (!WireFormatLite::ReadMessage(input, sub_message)) return false;
680  break;
681  }
682  }
683  }
684 
685  return true;
686 }
687 
689  Message* message) {
690  struct MSReflective {
691  bool ParseField(int type_id, io::CodedInputStream* input) {
692  const FieldDescriptor* field =
693  message_reflection->FindKnownExtensionByNumber(type_id);
694  return ParseAndMergeMessageSetField(type_id, field, message, input);
695  }
696 
698  return WireFormat::SkipField(input, tag, NULL);
699  }
700 
701  const Reflection* message_reflection;
702  Message* message;
703  };
704 
706  input, MSReflective{message->GetReflection(), message});
707 }
708 
709 // ===================================================================
710 
713  const Descriptor* descriptor = message.GetDescriptor();
714  const Reflection* message_reflection = message.GetReflection();
715  int expected_endpoint = output->ByteCount() + size;
716 
717  std::vector<const FieldDescriptor*> fields;
718 
719  // Fields of map entry should always be serialized.
720  if (descriptor->options().map_entry()) {
721  for (int i = 0; i < descriptor->field_count(); i++) {
722  fields.push_back(descriptor->field(i));
723  }
724  } else {
725  message_reflection->ListFields(message, &fields);
726  }
727 
728  for (int i = 0; i < fields.size(); i++) {
730  }
731 
732  if (descriptor->options().message_set_wire_format()) {
734  message_reflection->GetUnknownFields(message), output);
735  } else {
736  SerializeUnknownFields(message_reflection->GetUnknownFields(message),
737  output);
738  }
739 
740  GOOGLE_CHECK_EQ(output->ByteCount(), expected_endpoint)
741  << ": Protocol message serialized to a size different from what was "
742  "originally expected. Perhaps it was modified by another thread "
743  "during serialization?";
744 }
745 
747  const MapKey& value,
749  switch (field->type()) {
756  GOOGLE_LOG(FATAL) << "Unsupported";
757  break;
758 #define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \
759  case FieldDescriptor::TYPE_##FieldType: \
760  WireFormatLite::Write##CamelFieldType(1, value.Get##CamelCppType##Value(), \
761  output); \
762  break;
763  CASE_TYPE(INT64, Int64, Int64)
764  CASE_TYPE(UINT64, UInt64, UInt64)
765  CASE_TYPE(INT32, Int32, Int32)
766  CASE_TYPE(FIXED64, Fixed64, UInt64)
767  CASE_TYPE(FIXED32, Fixed32, UInt32)
768  CASE_TYPE(BOOL, Bool, Bool)
769  CASE_TYPE(UINT32, UInt32, UInt32)
770  CASE_TYPE(SFIXED32, SFixed32, Int32)
771  CASE_TYPE(SFIXED64, SFixed64, Int64)
772  CASE_TYPE(SINT32, SInt32, Int32)
773  CASE_TYPE(SINT64, SInt64, Int64)
774  CASE_TYPE(STRING, String, String)
775 #undef CASE_TYPE
776  }
777 }
778 
780  const MapValueRef& value,
782  switch (field->type()) {
783 #define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \
784  case FieldDescriptor::TYPE_##FieldType: \
785  WireFormatLite::Write##CamelFieldType(2, value.Get##CamelCppType##Value(), \
786  output); \
787  break;
788  CASE_TYPE(INT64, Int64, Int64)
789  CASE_TYPE(UINT64, UInt64, UInt64)
790  CASE_TYPE(INT32, Int32, Int32)
791  CASE_TYPE(FIXED64, Fixed64, UInt64)
792  CASE_TYPE(FIXED32, Fixed32, UInt32)
793  CASE_TYPE(BOOL, Bool, Bool)
794  CASE_TYPE(UINT32, UInt32, UInt32)
795  CASE_TYPE(SFIXED32, SFixed32, Int32)
796  CASE_TYPE(SFIXED64, SFixed64, Int64)
797  CASE_TYPE(SINT32, SInt32, Int32)
798  CASE_TYPE(SINT64, SInt64, Int64)
799  CASE_TYPE(ENUM, Enum, Enum)
800  CASE_TYPE(DOUBLE, Double, Double)
801  CASE_TYPE(FLOAT, Float, Float)
802  CASE_TYPE(STRING, String, String)
803  CASE_TYPE(BYTES, Bytes, String)
804  CASE_TYPE(MESSAGE, Message, Message)
805  CASE_TYPE(GROUP, Group, Message)
806 #undef CASE_TYPE
807  }
808 }
809 
811  public:
812  static std::vector<MapKey> SortKey(const Message& message,
813  const Reflection* reflection,
814  const FieldDescriptor* field) {
815  std::vector<MapKey> sorted_key_list;
816  for (MapIterator it =
817  reflection->MapBegin(const_cast<Message*>(&message), field);
818  it != reflection->MapEnd(const_cast<Message*>(&message), field);
819  ++it) {
820  sorted_key_list.push_back(it.GetKey());
821  }
822  MapKeyComparator comparator;
823  std::sort(sorted_key_list.begin(), sorted_key_list.end(), comparator);
824  return sorted_key_list;
825  }
826 
827  private:
829  public:
830  bool operator()(const MapKey& a, const MapKey& b) const {
831  GOOGLE_DCHECK(a.type() == b.type());
832  switch (a.type()) {
833 #define CASE_TYPE(CppType, CamelCppType) \
834  case FieldDescriptor::CPPTYPE_##CppType: { \
835  return a.Get##CamelCppType##Value() < b.Get##CamelCppType##Value(); \
836  }
837  CASE_TYPE(STRING, String)
838  CASE_TYPE(INT64, Int64)
839  CASE_TYPE(INT32, Int32)
840  CASE_TYPE(UINT64, UInt64)
841  CASE_TYPE(UINT32, UInt32)
842  CASE_TYPE(BOOL, Bool)
843 #undef CASE_TYPE
844 
845  default:
846  GOOGLE_LOG(DFATAL) << "Invalid key for map field.";
847  return true;
848  }
849  }
850  };
851 };
852 
853 static void SerializeMapEntry(const FieldDescriptor* field, const MapKey& key,
854  const MapValueRef& value,
856  const FieldDescriptor* key_field = field->message_type()->field(0);
857  const FieldDescriptor* value_field = field->message_type()->field(1);
858 
861  size_t size = kMapEntryTagByteSize;
862  size += MapKeyDataOnlyByteSize(key_field, key);
863  size += MapValueRefDataOnlyByteSize(value_field, value);
864  output->WriteVarint32(size);
867 }
868 
870  const Message& message,
872  const Reflection* message_reflection = message.GetReflection();
873 
874  if (field->is_extension() &&
875  field->containing_type()->options().message_set_wire_format() &&
876  field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
877  !field->is_repeated()) {
879  return;
880  }
881 
882  // For map fields, we can use either repeated field reflection or map
883  // reflection. Our choice has some subtle effects. If we use repeated field
884  // reflection here, then the repeated field representation becomes
885  // authoritative for this field: any existing references that came from map
886  // reflection remain valid for reading, but mutations to them are lost and
887  // will be overwritten next time we call map reflection!
888  //
889  // So far this mainly affects Python, which keeps long-term references to map
890  // values around, and always uses map reflection. See: b/35918691
891  //
892  // Here we choose to use map reflection API as long as the internal
893  // map is valid. In this way, the serialization doesn't change map field's
894  // internal state and existing references that came from map reflection remain
895  // valid for both reading and writing.
896  if (field->is_map()) {
897  const MapFieldBase* map_field =
898  message_reflection->GetMapData(message, field);
899  if (map_field->IsMapValid()) {
900  if (output->IsSerializationDeterministic()) {
901  std::vector<MapKey> sorted_key_list =
902  MapKeySorter::SortKey(message, message_reflection, field);
903  for (std::vector<MapKey>::iterator it = sorted_key_list.begin();
904  it != sorted_key_list.end(); ++it) {
905  MapValueRef map_value;
906  message_reflection->InsertOrLookupMapValue(
907  const_cast<Message*>(&message), field, *it, &map_value);
908  SerializeMapEntry(field, *it, map_value, output);
909  }
910  } else {
911  for (MapIterator it = message_reflection->MapBegin(
912  const_cast<Message*>(&message), field);
913  it !=
914  message_reflection->MapEnd(const_cast<Message*>(&message), field);
915  ++it) {
916  SerializeMapEntry(field, it.GetKey(), it.GetValueRef(), output);
917  }
918  }
919 
920  return;
921  }
922  }
923 
924  int count = 0;
925 
926  if (field->is_repeated()) {
927  count = message_reflection->FieldSize(message, field);
928  } else if (field->containing_type()->options().map_entry()) {
929  // Map entry fields always need to be serialized.
930  count = 1;
931  } else if (message_reflection->HasField(message, field)) {
932  count = 1;
933  }
934 
935  // map_entries is for maps that'll be deterministically serialized.
936  std::vector<const Message*> map_entries;
937  if (count > 1 && field->is_map() && output->IsSerializationDeterministic()) {
938  map_entries =
939  DynamicMapSorter::Sort(message, count, message_reflection, field);
940  }
941 
942  const bool is_packed = field->is_packed();
943  if (is_packed && count > 0) {
946  const size_t data_size = FieldDataOnlyByteSize(field, message);
947  output->WriteVarint32(data_size);
948  }
949 
950  for (int j = 0; j < count; j++) {
951  switch (field->type()) {
952 #define HANDLE_PRIMITIVE_TYPE(TYPE, CPPTYPE, TYPE_METHOD, CPPTYPE_METHOD) \
953  case FieldDescriptor::TYPE_##TYPE: { \
954  const CPPTYPE value = \
955  field->is_repeated() \
956  ? message_reflection->GetRepeated##CPPTYPE_METHOD(message, field, \
957  j) \
958  : message_reflection->Get##CPPTYPE_METHOD(message, field); \
959  if (is_packed) { \
960  WireFormatLite::Write##TYPE_METHOD##NoTag(value, output); \
961  } else { \
962  WireFormatLite::Write##TYPE_METHOD(field->number(), value, output); \
963  } \
964  break; \
965  }
966 
969  HANDLE_PRIMITIVE_TYPE(SINT32, int32, SInt32, Int32)
970  HANDLE_PRIMITIVE_TYPE(SINT64, int64, SInt64, Int64)
973 
974  HANDLE_PRIMITIVE_TYPE(FIXED32, uint32, Fixed32, UInt32)
975  HANDLE_PRIMITIVE_TYPE(FIXED64, uint64, Fixed64, UInt64)
976  HANDLE_PRIMITIVE_TYPE(SFIXED32, int32, SFixed32, Int32)
977  HANDLE_PRIMITIVE_TYPE(SFIXED64, int64, SFixed64, Int64)
978 
979  HANDLE_PRIMITIVE_TYPE(FLOAT, float, Float, Float)
980  HANDLE_PRIMITIVE_TYPE(DOUBLE, double, Double, Double)
981 
982  HANDLE_PRIMITIVE_TYPE(BOOL, bool, Bool, Bool)
983 #undef HANDLE_PRIMITIVE_TYPE
984 
985 #define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \
986  case FieldDescriptor::TYPE_##TYPE: \
987  WireFormatLite::Write##TYPE_METHOD( \
988  field->number(), \
989  field->is_repeated() \
990  ? (map_entries.empty() \
991  ? message_reflection->GetRepeated##CPPTYPE_METHOD(message, \
992  field, j) \
993  : *map_entries[j]) \
994  : message_reflection->Get##CPPTYPE_METHOD(message, field), \
995  output); \
996  break;
997 
998  HANDLE_TYPE(GROUP, Group, Message)
999  HANDLE_TYPE(MESSAGE, Message, Message)
1000 #undef HANDLE_TYPE
1001 
1003  const EnumValueDescriptor* value =
1004  field->is_repeated()
1005  ? message_reflection->GetRepeatedEnum(message, field, j)
1006  : message_reflection->GetEnum(message, field);
1007  if (is_packed) {
1009  } else {
1010  WireFormatLite::WriteEnum(field->number(), value->number(), output);
1011  }
1012  break;
1013  }
1014 
1015  // Handle strings separately so that we can get string references
1016  // instead of copying.
1018  bool strict_utf8_check = StrictUtf8Check(field);
1019  std::string scratch;
1020  const std::string& value =
1021  field->is_repeated()
1022  ? message_reflection->GetRepeatedStringReference(message, field,
1023  j, &scratch)
1024  : message_reflection->GetStringReference(message, field,
1025  &scratch);
1026  if (strict_utf8_check) {
1027  WireFormatLite::VerifyUtf8String(value.data(), value.length(),
1029  field->full_name().c_str());
1030  } else {
1031  VerifyUTF8StringNamedField(value.data(), value.length(), SERIALIZE,
1032  field->full_name().c_str());
1033  }
1035  break;
1036  }
1037 
1039  std::string scratch;
1040  const std::string& value =
1041  field->is_repeated()
1042  ? message_reflection->GetRepeatedStringReference(message, field,
1043  j, &scratch)
1044  : message_reflection->GetStringReference(message, field,
1045  &scratch);
1047  break;
1048  }
1049  }
1050  }
1051 }
1052 
1054  const FieldDescriptor* field, const Message& message,
1056  const Reflection* message_reflection = message.GetReflection();
1057 
1058  // Start group.
1060 
1061  // Write type ID.
1063  output->WriteVarint32(field->number());
1064 
1065  // Write message.
1067 
1068  const Message& sub_message = message_reflection->GetMessage(message, field);
1069  output->WriteVarint32(sub_message.GetCachedSize());
1070  sub_message.SerializeWithCachedSizes(output);
1071 
1072  // End group.
1074 }
1075 
1076 // ===================================================================
1077 
1079  const Descriptor* descriptor = message.GetDescriptor();
1080  const Reflection* message_reflection = message.GetReflection();
1081 
1082  size_t our_size = 0;
1083 
1084  std::vector<const FieldDescriptor*> fields;
1085 
1086  // Fields of map entry should always be serialized.
1087  if (descriptor->options().map_entry()) {
1088  for (int i = 0; i < descriptor->field_count(); i++) {
1089  fields.push_back(descriptor->field(i));
1090  }
1091  } else {
1092  message_reflection->ListFields(message, &fields);
1093  }
1094 
1095  for (int i = 0; i < fields.size(); i++) {
1096  our_size += FieldByteSize(fields[i], message);
1097  }
1098 
1099  if (descriptor->options().message_set_wire_format()) {
1101  message_reflection->GetUnknownFields(message));
1102  } else {
1103  our_size +=
1104  ComputeUnknownFieldsSize(message_reflection->GetUnknownFields(message));
1105  }
1106 
1107  return our_size;
1108 }
1109 
1111  const Message& message) {
1112  const Reflection* message_reflection = message.GetReflection();
1113 
1114  if (field->is_extension() &&
1115  field->containing_type()->options().message_set_wire_format() &&
1116  field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
1117  !field->is_repeated()) {
1119  }
1120 
1121  size_t count = 0;
1122  if (field->is_repeated()) {
1123  count = FromIntSize(message_reflection->FieldSize(message, field));
1124  } else if (field->containing_type()->options().map_entry()) {
1125  // Map entry fields always need to be serialized.
1126  count = 1;
1127  } else if (message_reflection->HasField(message, field)) {
1128  count = 1;
1129  }
1130 
1131  const size_t data_size = FieldDataOnlyByteSize(field, message);
1132  size_t our_size = data_size;
1133  if (field->is_packed()) {
1134  if (data_size > 0) {
1135  // Packed fields get serialized like a string, not their native type.
1136  // Technically this doesn't really matter; the size only changes if it's
1137  // a GROUP
1138  our_size += TagSize(field->number(), FieldDescriptor::TYPE_STRING);
1139  our_size += io::CodedOutputStream::VarintSize32(data_size);
1140  }
1141  } else {
1142  our_size += count * TagSize(field->number(), field->type());
1143  }
1144  return our_size;
1145 }
1146 
1148  const MapKey& value) {
1150  switch (field->type()) {
1157  GOOGLE_LOG(FATAL) << "Unsupported";
1158  return 0;
1159 #define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \
1160  case FieldDescriptor::TYPE_##FieldType: \
1161  return WireFormatLite::CamelFieldType##Size( \
1162  value.Get##CamelCppType##Value());
1163 
1164 #define FIXED_CASE_TYPE(FieldType, CamelFieldType) \
1165  case FieldDescriptor::TYPE_##FieldType: \
1166  return WireFormatLite::k##CamelFieldType##Size;
1167 
1168  CASE_TYPE(INT32, Int32, Int32);
1169  CASE_TYPE(INT64, Int64, Int64);
1170  CASE_TYPE(UINT32, UInt32, UInt32);
1171  CASE_TYPE(UINT64, UInt64, UInt64);
1172  CASE_TYPE(SINT32, SInt32, Int32);
1173  CASE_TYPE(SINT64, SInt64, Int64);
1174  CASE_TYPE(STRING, String, String);
1175  FIXED_CASE_TYPE(FIXED32, Fixed32);
1176  FIXED_CASE_TYPE(FIXED64, Fixed64);
1177  FIXED_CASE_TYPE(SFIXED32, SFixed32);
1178  FIXED_CASE_TYPE(SFIXED64, SFixed64);
1179  FIXED_CASE_TYPE(BOOL, Bool);
1180 
1181 #undef CASE_TYPE
1182 #undef FIXED_CASE_TYPE
1183  }
1184  GOOGLE_LOG(FATAL) << "Cannot get here";
1185  return 0;
1186 }
1187 
1189  const MapValueRef& value) {
1190  switch (field->type()) {
1192  GOOGLE_LOG(FATAL) << "Unsupported";
1193  return 0;
1194 #define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \
1195  case FieldDescriptor::TYPE_##FieldType: \
1196  return WireFormatLite::CamelFieldType##Size( \
1197  value.Get##CamelCppType##Value());
1198 
1199 #define FIXED_CASE_TYPE(FieldType, CamelFieldType) \
1200  case FieldDescriptor::TYPE_##FieldType: \
1201  return WireFormatLite::k##CamelFieldType##Size;
1202 
1203  CASE_TYPE(INT32, Int32, Int32);
1204  CASE_TYPE(INT64, Int64, Int64);
1205  CASE_TYPE(UINT32, UInt32, UInt32);
1206  CASE_TYPE(UINT64, UInt64, UInt64);
1207  CASE_TYPE(SINT32, SInt32, Int32);
1208  CASE_TYPE(SINT64, SInt64, Int64);
1209  CASE_TYPE(STRING, String, String);
1210  CASE_TYPE(BYTES, Bytes, String);
1211  CASE_TYPE(ENUM, Enum, Enum);
1212  CASE_TYPE(MESSAGE, Message, Message);
1213  FIXED_CASE_TYPE(FIXED32, Fixed32);
1214  FIXED_CASE_TYPE(FIXED64, Fixed64);
1215  FIXED_CASE_TYPE(SFIXED32, SFixed32);
1216  FIXED_CASE_TYPE(SFIXED64, SFixed64);
1217  FIXED_CASE_TYPE(DOUBLE, Double);
1218  FIXED_CASE_TYPE(FLOAT, Float);
1219  FIXED_CASE_TYPE(BOOL, Bool);
1220 
1221 #undef CASE_TYPE
1222 #undef FIXED_CASE_TYPE
1223  }
1224  GOOGLE_LOG(FATAL) << "Cannot get here";
1225  return 0;
1226 }
1227 
1229  const Message& message) {
1230  const Reflection* message_reflection = message.GetReflection();
1231 
1232  size_t data_size = 0;
1233 
1234  if (field->is_map()) {
1235  const MapFieldBase* map_field =
1236  message_reflection->GetMapData(message, field);
1237  if (map_field->IsMapValid()) {
1238  MapIterator iter(const_cast<Message*>(&message), field);
1239  MapIterator end(const_cast<Message*>(&message), field);
1240  const FieldDescriptor* key_field = field->message_type()->field(0);
1241  const FieldDescriptor* value_field = field->message_type()->field(1);
1242  for (map_field->MapBegin(&iter), map_field->MapEnd(&end); iter != end;
1243  ++iter) {
1244  size_t size = kMapEntryTagByteSize;
1245  size += MapKeyDataOnlyByteSize(key_field, iter.GetKey());
1246  size += MapValueRefDataOnlyByteSize(value_field, iter.GetValueRef());
1248  }
1249  return data_size;
1250  }
1251  }
1252 
1253  size_t count = 0;
1254  if (field->is_repeated()) {
1255  count =
1256  internal::FromIntSize(message_reflection->FieldSize(message, field));
1257  } else if (field->containing_type()->options().map_entry()) {
1258  // Map entry fields always need to be serialized.
1259  count = 1;
1260  } else if (message_reflection->HasField(message, field)) {
1261  count = 1;
1262  }
1263 
1264  switch (field->type()) {
1265 #define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \
1266  case FieldDescriptor::TYPE_##TYPE: \
1267  if (field->is_repeated()) { \
1268  for (int j = 0; j < count; j++) { \
1269  data_size += WireFormatLite::TYPE_METHOD##Size( \
1270  message_reflection->GetRepeated##CPPTYPE_METHOD(message, field, \
1271  j)); \
1272  } \
1273  } else { \
1274  data_size += WireFormatLite::TYPE_METHOD##Size( \
1275  message_reflection->Get##CPPTYPE_METHOD(message, field)); \
1276  } \
1277  break;
1278 
1279 #define HANDLE_FIXED_TYPE(TYPE, TYPE_METHOD) \
1280  case FieldDescriptor::TYPE_##TYPE: \
1281  data_size += count * WireFormatLite::k##TYPE_METHOD##Size; \
1282  break;
1283 
1284  HANDLE_TYPE(INT32, Int32, Int32)
1285  HANDLE_TYPE(INT64, Int64, Int64)
1286  HANDLE_TYPE(SINT32, SInt32, Int32)
1287  HANDLE_TYPE(SINT64, SInt64, Int64)
1288  HANDLE_TYPE(UINT32, UInt32, UInt32)
1289  HANDLE_TYPE(UINT64, UInt64, UInt64)
1290 
1291  HANDLE_FIXED_TYPE(FIXED32, Fixed32)
1292  HANDLE_FIXED_TYPE(FIXED64, Fixed64)
1293  HANDLE_FIXED_TYPE(SFIXED32, SFixed32)
1294  HANDLE_FIXED_TYPE(SFIXED64, SFixed64)
1295 
1296  HANDLE_FIXED_TYPE(FLOAT, Float)
1297  HANDLE_FIXED_TYPE(DOUBLE, Double)
1298 
1299  HANDLE_FIXED_TYPE(BOOL, Bool)
1300 
1301  HANDLE_TYPE(GROUP, Group, Message)
1302  HANDLE_TYPE(MESSAGE, Message, Message)
1303 #undef HANDLE_TYPE
1304 #undef HANDLE_FIXED_TYPE
1305 
1307  if (field->is_repeated()) {
1308  for (int j = 0; j < count; j++) {
1309  data_size += WireFormatLite::EnumSize(
1310  message_reflection->GetRepeatedEnum(message, field, j)->number());
1311  }
1312  } else {
1313  data_size += WireFormatLite::EnumSize(
1314  message_reflection->GetEnum(message, field)->number());
1315  }
1316  break;
1317  }
1318 
1319  // Handle strings separately so that we can get string references
1320  // instead of copying.
1323  for (int j = 0; j < count; j++) {
1324  std::string scratch;
1325  const std::string& value =
1326  field->is_repeated()
1327  ? message_reflection->GetRepeatedStringReference(message, field,
1328  j, &scratch)
1329  : message_reflection->GetStringReference(message, field,
1330  &scratch);
1331  data_size += WireFormatLite::StringSize(value);
1332  }
1333  break;
1334  }
1335  }
1336  return data_size;
1337 }
1338 
1340  const Message& message) {
1341  const Reflection* message_reflection = message.GetReflection();
1342 
1343  size_t our_size = WireFormatLite::kMessageSetItemTagsSize;
1344 
1345  // type_id
1346  our_size += io::CodedOutputStream::VarintSize32(field->number());
1347 
1348  // message
1349  const Message& sub_message = message_reflection->GetMessage(message, field);
1350  size_t message_size = sub_message.ByteSizeLong();
1351 
1353  our_size += message_size;
1354 
1355  return our_size;
1356 }
1357 
1358 } // namespace internal
1359 } // namespace protobuf
1360 } // namespace google
google::protobuf.internal::WireFormat::ReadPackedEnumPreserveUnknowns
static bool ReadPackedEnumPreserveUnknowns(io::CodedInputStream *input, uint32 field_number, bool(*is_valid)(int), UnknownFieldSet *unknown_fields, RepeatedField< int > *values)
Definition: wire_format.cc:167
zero_copy_stream.h
GOOGLE_CHECK_EQ
#define GOOGLE_CHECK_EQ(A, B)
Definition: logging.h:156
google::protobuf.internal::WireFormatLite::EnumSize
static size_t EnumSize(int value)
Definition: wire_format_lite.h:1743
Json::UInt64
unsigned long long int UInt64
Definition: json.h:241
google::protobuf::Reflection::GetStringReference
const std::string & GetStringReference(const Message &message, const FieldDescriptor *field, std::string *scratch) const
Definition: generated_message_reflection.cc:1171
google::protobuf::UnknownField::TYPE_FIXED64
@ TYPE_FIXED64
Definition: unknown_field_set.h:228
google::protobuf.internal::WireFormatLite::ReadGroup
static bool ReadGroup(int field_number, io::CodedInputStream *input, MessageType *value)
Definition: wire_format_lite.h:1245
google::protobuf.internal::WireFormat::MessageSetItemByteSize
static size_t MessageSetItemByteSize(const FieldDescriptor *field, const Message &message)
Definition: wire_format.cc:1339
google::protobuf.internal::WireFormatLite::ReadBytes
static bool ReadBytes(io::CodedInputStream *input, std::string *value)
Definition: wire_format_lite.cc:565
google::protobuf::MapIterator::GetValueRef
const MapValueRef & GetValueRef()
Definition: map_field.h:750
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
google::protobuf.internal::WireFormat::TagSize
static size_t TagSize(int field_number, FieldDescriptor::Type type)
Definition: wire_format.h:293
zero_copy_stream_impl.h
google::protobuf.internal::MapKeyDataOnlyByteSize
static size_t MapKeyDataOnlyByteSize(const FieldDescriptor *field, const MapKey &value)
Definition: wire_format.cc:1147
google::protobuf.internal::WireFormatLite::WIRETYPE_FIXED32
@ WIRETYPE_FIXED32
Definition: wire_format_lite.h:107
google::protobuf.internal::WireFormatLite::WIRETYPE_VARINT
@ WIRETYPE_VARINT
Definition: wire_format_lite.h:102
google::protobuf.internal::WireFormatLite::PARSE
@ PARSE
Definition: wire_format_lite.h:323
end
GLuint GLuint end
Definition: glcorearb.h:2858
NULL
NULL
Definition: test_security_zap.cpp:405
Bool
Definition: gtest_pred_impl_unittest.cc:56
google::protobuf::int64
int64_t int64
Definition: protobuf/src/google/protobuf/stubs/port.h:151
google::protobuf::MessageLite::GetCachedSize
virtual int GetCachedSize() const =0
map_field_inl.h
google::protobuf::UnknownField::TYPE_FIXED32
@ TYPE_FIXED32
Definition: unknown_field_set.h:227
length
GLenum GLuint GLenum GLsizei length
Definition: glcorearb.h:2695
input
std::string input
Definition: tokenizer_unittest.cc:197
google::protobuf::io::CodedOutputStream::VarintSize64
static size_t VarintSize64(uint64 value)
Definition: coded_stream.h:1255
google::protobuf.internal::WireFormatLite::WriteInt64ToArray
static PROTOBUF_ALWAYS_INLINE uint8 * WriteInt64ToArray(int field_number, int64 value, uint8 *target)
Definition: wire_format_lite.h:1519
google::protobuf::uint8
uint8_t uint8
Definition: protobuf/src/google/protobuf/stubs/port.h:153
FATAL
const int FATAL
Definition: log_severity.h:60
google::protobuf::Reflection::GetRepeatedStringReference
const std::string & GetRepeatedStringReference(const Message &message, const FieldDescriptor *field, int index, std::string *scratch) const
Definition: generated_message_reflection.cc:1241
google::protobuf::FieldDescriptor::TYPE_BYTES
@ TYPE_BYTES
Definition: src/google/protobuf/descriptor.h:538
google::protobuf.internal::MapKeySorter::MapKeyComparator
Definition: wire_format.cc:828
GOOGLE_DCHECK
#define GOOGLE_DCHECK
Definition: logging.h:194
google::protobuf::UnknownField::TYPE_VARINT
@ TYPE_VARINT
Definition: unknown_field_set.h:226
google::protobuf.internal::WireFormat::SerializeMessageSetItemWithCachedSizes
static void SerializeMessageSetItemWithCachedSizes(const FieldDescriptor *field, const Message &message, io::CodedOutputStream *output)
Definition: wire_format.cc:1053
google::protobuf.internal::WireFormat::ByteSize
static size_t ByteSize(const Message &message)
Definition: wire_format.cc:1078
google::protobuf::DynamicMapSorter::Sort
static std::vector< const Message * > Sort(const Message &message, int map_size, const Reflection *reflection, const FieldDescriptor *field)
Definition: dynamic_message.h:158
google::protobuf::uint32
uint32_t uint32
Definition: protobuf/src/google/protobuf/stubs/port.h:155
google::protobuf::UnknownField
Definition: unknown_field_set.h:223
dynamic_message.h
google::protobuf.internal::FromIntSize
size_t FromIntSize(int size)
Definition: message_lite.h:96
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf.internal::WireFormatLite::kMessageSetItemEndTag
static const int kMessageSetItemEndTag
Definition: wire_format_lite.h:217
google::protobuf::Reflection::GetRepeatedEnum
const EnumValueDescriptor * GetRepeatedEnum(const Message &message, const FieldDescriptor *field, int index) const
Definition: generated_message_reflection.cc:1349
google::protobuf::RepeatedField< int >
google::protobuf.internal::WireFormatLite::WIRETYPE_END_GROUP
@ WIRETYPE_END_GROUP
Definition: wire_format_lite.h:106
google::protobuf::Reflection::SetString
void SetString(Message *message, const FieldDescriptor *field, const std::string &value) const
Definition: generated_message_reflection.cc:1193
google::protobuf.internal::UnknownFieldSetFieldSkipper::SkipMessage
bool SkipMessage(io::CodedInputStream *input) override
Definition: wire_format.cc:76
target
GLenum target
Definition: glcorearb.h:3739
google::protobuf::Reflection
Definition: src/google/protobuf/message.h:400
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::Reflection::HasField
bool HasField(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:728
google::protobuf::HANDLE_TYPE
HANDLE_TYPE(int32, FieldDescriptor::CPPTYPE_INT32, -1)
google::protobuf.internal::WireFormat::ParseAndMergeField
static bool ParseAndMergeField(uint32 tag, const FieldDescriptor *field, Message *message, io::CodedInputStream *input)
Definition: wire_format.cc:470
testing::internal::Int32
TypeWithSize< 4 >::Int Int32
Definition: gtest-port.h:2241
google::protobuf.internal::WireFormatLite::kMessageSetTypeIdTag
static const int kMessageSetTypeIdTag
Definition: wire_format_lite.h:219
google::protobuf::io::CodedOutputStream::WriteVarint32ToArray
static uint8 * WriteVarint32ToArray(uint32 value, uint8 *target)
Definition: coded_stream.h:1149
google::protobuf::util::error::UNKNOWN
@ UNKNOWN
Definition: status.h:49
Enum
Definition: type.pb.h:797
map_field.h
google::protobuf::UnknownFieldSet::field_count
int field_count() const
Definition: unknown_field_set.h:311
google::protobuf.internal::WireFormat::ComputeUnknownFieldsSize
static size_t ComputeUnknownFieldsSize(const UnknownFieldSet &unknown_fields)
Definition: wire_format.cc:319
google::protobuf.internal::UnknownFieldSetFieldSkipper::unknown_fields_
UnknownFieldSet * unknown_fields_
Definition: wire_format.h:267
testing::internal::Double
FloatingPoint< double > Double
Definition: gtest-internal.h:429
google::protobuf.internal::WireFormatLite::kMessageSetMessageTag
static const int kMessageSetMessageTag
Definition: wire_format_lite.h:221
b
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:3228
google::protobuf.internal::WireFormatLite::WriteEnumNoTag
static PROTOBUF_ALWAYS_INLINE void WriteEnumNoTag(int value, io::CodedOutputStream *output)
Definition: wire_format_lite.h:1329
testing::internal::UInt32
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:2242
FieldDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:129
values
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:3591
google::protobuf.internal::WireFormatLite::WriteBytes
static void WriteBytes(int field_number, const std::string &value, io::CodedOutputStream *output)
Definition: wire_format_lite.cc:493
google::protobuf.internal::MapKeySorter::MapKeyComparator::operator()
bool operator()(const MapKey &a, const MapKey &b) const
Definition: wire_format.cc:830
google::protobuf.internal::StrictUtf8Check
static bool StrictUtf8Check(const FieldDescriptor *field)
Definition: wire_format.cc:466
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
google::protobuf::UnknownFieldSet::AddGroup
UnknownFieldSet * AddGroup(int number)
Definition: unknown_field_set.cc:168
google::protobuf.internal::WireFormatLite::WriteTagToArray
static PROTOBUF_ALWAYS_INLINE uint8 * WriteTagToArray(int field_number, WireType type, uint8 *target)
Definition: wire_format_lite.h:1356
message_size
static size_t message_size
Definition: inproc_lat.cpp:18
google::protobuf::Message::SerializeWithCachedSizes
void SerializeWithCachedSizes(io::CodedOutputStream *output) const override
Definition: src/google/protobuf/message.cc:530
google::protobuf.internal::WireFormat::FieldByteSize
static size_t FieldByteSize(const FieldDescriptor *field, const Message &message)
Definition: wire_format.cc:1110
unknown_field_set.h
google::protobuf::Reflection::MutableUnknownFields
UnknownFieldSet * MutableUnknownFields(Message *message) const
Definition: generated_message_reflection.cc:237
google::protobuf::Reflection::AddEnum
void AddEnum(Message *message, const FieldDescriptor *field, const EnumValueDescriptor *value) const
Definition: generated_message_reflection.cc:1406
testing::internal::Float
FloatingPoint< float > Float
Definition: gtest-internal.h:428
coded_stream.h
google::protobuf.internal::WireFormat::SkipMessageSetField
static bool SkipMessageSetField(io::CodedInputStream *input, uint32 field_number, UnknownFieldSet *unknown_fields)
Definition: wire_format.cc:435
google::protobuf.internal::WireFormatLite::WriteFixed64ToArray
static PROTOBUF_ALWAYS_INLINE uint8 * WriteFixed64ToArray(int field_number, uint64 value, uint8 *target)
Definition: wire_format_lite.h:1549
google::protobuf.internal::WireFormatLite::ReadString
static bool ReadString(io::CodedInputStream *input, std::string *value)
Definition: wire_format_lite.h:878
google::protobuf.internal::WireFormatLite::WriteString
static void WriteString(int field_number, const std::string &value, io::CodedOutputStream *output)
Definition: wire_format_lite.cc:476
google::protobuf.internal::WireFormat::ComputeUnknownMessageSetItemsSize
static size_t ComputeUnknownMessageSetItemsSize(const UnknownFieldSet &unknown_fields)
Definition: wire_format.cc:361
google::protobuf.internal::ParseMessageSetItemImpl
bool ParseMessageSetItemImpl(io::CodedInputStream *input, MS ms)
Definition: wire_format_lite.h:1788
google::protobuf::EnumValueDescriptor::number
int number() const
google::protobuf.internal::WireFormatLite::ReadMessage
static bool ReadMessage(io::CodedInputStream *input, MessageType *value)
Definition: wire_format_lite.h:1258
google::protobuf::io::CodedOutputStream::VarintSize32
static size_t VarintSize32(uint32 value)
Definition: coded_stream.h:1245
google::protobuf::UnknownFieldSet::AddVarint
void AddVarint(int number, uint64 value)
Definition: unknown_field_set.cc:134
google::protobuf.internal::WireFormatLite::LengthDelimitedSize
static size_t LengthDelimitedSize(size_t length)
Definition: wire_format_lite.h:1778
google::protobuf.internal::UnknownFieldSetFieldSkipper::SkipField
bool SkipField(io::CodedInputStream *input, uint32 tag) override
Definition: wire_format.cc:71
google::protobuf::Reflection::GetUnknownFields
const UnknownFieldSet & GetUnknownFields(const Message &message) const
Definition: generated_message_reflection.cc:232
google::protobuf::Reflection::AddEnumValue
void AddEnumValue(Message *message, const FieldDescriptor *field, int value) const
Definition: generated_message_reflection.cc:1413
google::protobuf.internal::WireFormatLite::WriteFixed32ToArray
static PROTOBUF_ALWAYS_INLINE uint8 * WriteFixed32ToArray(int field_number, uint32 value, uint8 *target)
Definition: wire_format_lite.h:1544
GOOGLE_LOG
#define GOOGLE_LOG(LEVEL)
Definition: logging.h:146
google::protobuf.internal::WireFormatLite::WIRETYPE_FIXED64
@ WIRETYPE_FIXED64
Definition: wire_format_lite.h:103
google::protobuf.internal::UnknownFieldSetFieldSkipper::SkipUnknownEnum
void SkipUnknownEnum(int field_number, int value) override
Definition: wire_format.cc:80
google::protobuf::Reflection::GetEnum
const EnumValueDescriptor * GetEnum(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1294
google::protobuf::Reflection::MapBegin
MapIterator MapBegin(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1787
google::protobuf.internal::WireFormatLite::VerifyUtf8String
static bool VerifyUtf8String(const char *data, int size, Operation op, const char *field_name)
Definition: wire_format_lite.cc:590
google::protobuf::uint64
uint64_t uint64
Definition: protobuf/src/google/protobuf/stubs/port.h:156
size
#define size
Definition: glcorearb.h:2944
HANDLE_FIXED_TYPE
#define HANDLE_FIXED_TYPE(TYPE, TYPE_METHOD)
google::protobuf::FieldDescriptor::TYPE_STRING
@ TYPE_STRING
Definition: src/google/protobuf/descriptor.h:534
google::protobuf::Reflection::InsertOrLookupMapValue
bool InsertOrLookupMapValue(Message *message, const FieldDescriptor *field, const MapKey &key, MapValueRef *val) const
Definition: generated_message_reflection.cc:1769
google::protobuf.internal::WireFormatLite::MakeTag
constexpr static uint32 MakeTag(int field_number, WireType type)
Definition: wire_format_lite.h:768
google::protobuf.internal::WireFormat::SerializeUnknownFields
static void SerializeUnknownFields(const UnknownFieldSet &unknown_fields, io::CodedOutputStream *output)
Definition: wire_format.cc:191
google::protobuf.internal::MapFieldBase::MapBegin
virtual void MapBegin(MapIterator *map_iter) const =0
google::protobuf::FileDescriptor::SYNTAX_PROTO3
@ SYNTAX_PROTO3
Definition: src/google/protobuf/descriptor.h:1394
google::protobuf.internal::WireFormat::SERIALIZE
@ SERIALIZE
Definition: wire_format.h:227
google::protobuf.internal::MapValueRefDataOnlyByteSize
static size_t MapValueRefDataOnlyByteSize(const FieldDescriptor *field, const MapValueRef &value)
Definition: wire_format.cc:1188
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
google::protobuf::Reflection::AddString
void AddString(Message *message, const FieldDescriptor *field, const std::string &value) const
Definition: generated_message_reflection.cc:1275
google::protobuf::Reflection::FieldSize
int FieldSize(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:744
google::protobuf::ERROR
static const LogLevel ERROR
Definition: protobuf/src/google/protobuf/testing/googletest.h:70
key
const SETUP_TEARDOWN_TESTCONTEXT char * key
Definition: test_wss_transport.cpp:10
google::protobuf.internal::WireFormat::SerializeUnknownFieldsToArray
static uint8 * SerializeUnknownFieldsToArray(const UnknownFieldSet &unknown_fields, uint8 *target)
Definition: wire_format.cc:229
google::protobuf.internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED
@ WIRETYPE_LENGTH_DELIMITED
Definition: wire_format_lite.h:104
google::protobuf.internal::MapFieldBase::MapEnd
virtual void MapEnd(MapIterator *map_iter) const =0
google::protobuf.internal::SerializeMapEntry
static void SerializeMapEntry(const FieldDescriptor *field, const MapKey &key, const MapValueRef &value, io::CodedOutputStream *output)
Definition: wire_format.cc:853
google::protobuf::Reflection::MutableMessage
Message * MutableMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1462
google::protobuf.internal::WireFormatLite::GetTagFieldNumber
static int GetTagFieldNumber(uint32 tag)
Definition: wire_format_lite.h:777
kMapEntryTagByteSize
const size_t kMapEntryTagByteSize
Definition: wire_format.cc:57
google::protobuf.internal::WireFormat::SerializeWithCachedSizes
static void SerializeWithCachedSizes(const Message &message, int size, io::CodedOutputStream *output)
Definition: wire_format.cc:711
google::protobuf.internal::WireFormat::ParseAndMergeMessageSetItem
static bool ParseAndMergeMessageSetItem(io::CodedInputStream *input, Message *message)
Definition: wire_format.cc:688
google::protobuf.internal::SerializeMapValueRefWithCachedSizes
static void SerializeMapValueRefWithCachedSizes(const FieldDescriptor *field, const MapValueRef &value, io::CodedOutputStream *output)
Definition: wire_format.cc:779
google::protobuf::io::CodedOutputStream
Definition: coded_stream.h:693
google::protobuf::UnknownFieldSet::AddLengthDelimited
void AddLengthDelimited(int number, const std::string &value)
Definition: unknown_field_set.h:321
i
int i
Definition: gmock-matchers_test.cc:764
google::protobuf::FieldDescriptor::TYPE_MESSAGE
@ TYPE_MESSAGE
Definition: src/google/protobuf/descriptor.h:536
google::protobuf::FieldDescriptor::TYPE_DOUBLE
@ TYPE_DOUBLE
Definition: src/google/protobuf/descriptor.h:522
fields
static const upb_fielddef fields[107]
Definition: ruby/ext/google/protobuf_c/upb.c:7671
google::protobuf.internal::WireFormatLite::GetTagWireType
static WireType GetTagWireType(uint32 tag)
Definition: wire_format_lite.h:773
google::protobuf.internal::WireFormatLite::StringSize
static size_t StringSize(const std::string &value)
Definition: wire_format_lite.h:1747
google::protobuf::UnknownField::TYPE_GROUP
@ TYPE_GROUP
Definition: unknown_field_set.h:230
google::protobuf.internal::WireFormatLite::WriteEnum
static void WriteEnum(int field_number, int value, io::CodedOutputStream *output)
Definition: wire_format_lite.cc:470
google::protobuf.internal::WireFormat::SerializeUnknownMessageSetItems
static void SerializeUnknownMessageSetItems(const UnknownFieldSet &unknown_fields, io::CodedOutputStream *output)
Definition: wire_format.cc:263
google::protobuf::FieldDescriptor::TYPE_FLOAT
@ TYPE_FLOAT
Definition: src/google/protobuf/descriptor.h:523
google::protobuf::UnknownFieldSet::field
const UnknownField & field(int index) const
Definition: unknown_field_set.h:314
google::protobuf::Message
Definition: src/google/protobuf/message.h:205
HANDLE_PACKED_TYPE
#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD)
google::protobuf::UnknownField::TYPE_LENGTH_DELIMITED
@ TYPE_LENGTH_DELIMITED
Definition: unknown_field_set.h:229
google::protobuf.internal::WireFormat::VerifyUTF8StringNamedField
static void VerifyUTF8StringNamedField(const char *data, int size, Operation op, const char *field_name)
Definition: wire_format.h:315
common.h
google::protobuf.internal::MapFieldBase::IsMapValid
bool IsMapValid() const
Definition: map_field.cc:72
google::protobuf::MapIterator::GetKey
const MapKey & GetKey()
Definition: map_field.h:749
google::protobuf.internal::WireFormatLite::WriteTag
static PROTOBUF_ALWAYS_INLINE void WriteTag(int field_number, WireType type, io::CodedOutputStream *output)
Definition: wire_format_lite.h:1272
google::protobuf.internal::WireFormat::SerializeUnknownMessageSetItemsToArray
static uint8 * SerializeUnknownMessageSetItemsToArray(const UnknownFieldSet &unknown_fields, uint8 *target)
Definition: wire_format.cc:287
google::protobuf::Reflection::SetEnumValue
void SetEnumValue(Message *message, const FieldDescriptor *field, int value) const
Definition: generated_message_reflection.cc:1322
size
GLsizeiptr size
Definition: glcorearb.h:2943
google::protobuf::MapKey
Definition: map_field.h:371
FIXED_CASE_TYPE
#define FIXED_CASE_TYPE(FieldType, CamelFieldType)
google::protobuf.internal::WireFormatLite::SERIALIZE
@ SERIALIZE
Definition: wire_format_lite.h:324
google::protobuf.internal::WireFormat::WireTypeForFieldType
static WireFormatLite::WireType WireTypeForFieldType(FieldDescriptor::Type type)
Definition: wire_format.h:281
google::protobuf::UnknownFieldSet
Definition: unknown_field_set.h:86
google::protobuf::io::CodedInputStream
Definition: coded_stream.h:173
stringprintf.h
google::protobuf.internal::WireFormatLite::kMessageSetItemTagsSize
static const size_t kMessageSetItemTagsSize
Definition: wire_format_lite.h:225
wire_format.h
logging.h
google::protobuf::EnumValueDescriptor
Definition: src/google/protobuf/descriptor.h:1075
google::protobuf.internal::WireFormatLite::WIRETYPE_START_GROUP
@ WIRETYPE_START_GROUP
Definition: wire_format_lite.h:105
google::protobuf.internal::WireFormat::ParseAndMergePartial
static bool ParseAndMergePartial(io::CodedInputStream *input, Message *message)
Definition: wire_format.cc:384
google::protobuf::Descriptor
Definition: src/google/protobuf/descriptor.h:231
descriptor.h
google::protobuf::FieldDescriptor::TYPE_GROUP
@ TYPE_GROUP
Definition: src/google/protobuf/descriptor.h:535
google::protobuf::Message::ByteSizeLong
size_t ByteSizeLong() const override
Definition: src/google/protobuf/message.cc:540
google::protobuf.internal::WireFormat::FieldDataOnlyByteSize
static size_t FieldDataOnlyByteSize(const FieldDescriptor *field, const Message &message)
Definition: wire_format.cc:1228
google::protobuf::UnknownFieldSet::AddFixed32
void AddFixed32(int number, uint32 value)
Definition: unknown_field_set.cc:142
google::protobuf::UnknownFieldSet::AddFixed64
void AddFixed64(int number, uint64 value)
Definition: unknown_field_set.cc:150
google::protobuf.internal::WireFormatLite::WireType
WireType
Definition: wire_format_lite.h:101
google::protobuf.internal::MapKeySorter
Definition: wire_format.cc:810
google::protobuf::io::CodedOutputStream::WriteTagToArray
static PROTOBUF_ALWAYS_INLINE uint8 * WriteTagToArray(uint32 value, uint8 *target)
Definition: coded_stream.h:1241
google::protobuf.internal::WireFormat::ParseAndMergeMessageSetField
static bool ParseAndMergeMessageSetField(uint32 field_number, const FieldDescriptor *field, Message *message, io::CodedInputStream *input)
Definition: wire_format.cc:444
internal
Definition: any.pb.h:40
google::protobuf.internal::MapFieldBase
Definition: map_field.h:69
google::protobuf::io::CodedInputStream::Limit
int Limit
Definition: coded_stream.h:350
google::protobuf::Reflection::GetMapData
const internal::MapFieldBase * GetMapData(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:2218
google::protobuf.internal::WireFormatLite::WriteBytesToArray
static PROTOBUF_ALWAYS_INLINE uint8 * WriteBytesToArray(int field_number, const std::string &value, uint8 *target)
Definition: wire_format_lite.h:1675
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
descriptor.pb.h
HANDLE_PRIMITIVE_TYPE
#define HANDLE_PRIMITIVE_TYPE(TYPE, CPPTYPE, TYPE_METHOD, CPPTYPE_METHOD)
google::protobuf::Reflection::AddMessage
Message * AddMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1638
google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE
@ CPPTYPE_MESSAGE
Definition: src/google/protobuf/descriptor.h:563
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
google::protobuf.internal::WireFormat::SerializeFieldWithCachedSizes
static void SerializeFieldWithCachedSizes(const FieldDescriptor *field, const Message &message, io::CodedOutputStream *output)
Definition: wire_format.cc:869
google::protobuf::FieldDescriptor::TypeToCppType
static CppType TypeToCppType(Type type)
Definition: src/google/protobuf/descriptor.h:2147
google::protobuf::MapIterator
Definition: map_field.h:712
google::protobuf::FieldDescriptor::TYPE_ENUM
@ TYPE_ENUM
Definition: src/google/protobuf/descriptor.h:540
count
GLint GLsizei count
Definition: glcorearb.h:2830
google::protobuf.internal::WireFormat::SkipMessage
static bool SkipMessage(io::CodedInputStream *input, UnknownFieldSet *unknown_fields)
Definition: wire_format.cc:147
google::protobuf.internal::WireFormat::PARSE
@ PARSE
Definition: wire_format.h:226
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:3228
google::protobuf::Reflection::ListFields
void ListFields(const Message &message, std::vector< const FieldDescriptor * > *output) const
Definition: generated_message_reflection.cc:1029
google::protobuf.internal::WireFormatLite::kMessageSetItemStartTag
static const int kMessageSetItemStartTag
Definition: wire_format_lite.h:215
Json::Int64
long long int Int64
Definition: json.h:240
number
double number
Definition: cJSON.h:326
it
MapIter it
Definition: php/ext/google/protobuf/map.c:205
google
Definition: data_proto2_to_proto3_util.h:11
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695
google::protobuf.internal::SerializeMapKeyWithCachedSizes
static void SerializeMapKeyWithCachedSizes(const FieldDescriptor *field, const MapKey &value, io::CodedOutputStream *output)
Definition: wire_format.cc:746
CASE_TYPE
#define CASE_TYPE(FieldType, CamelFieldType, CamelCppType)
google::protobuf::Reflection::GetMessage
const Message & GetMessage(const Message &message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1443
google::protobuf::MapValueRef
Definition: map_field.h:565
google::protobuf.internal::MapKeySorter::SortKey
static std::vector< MapKey > SortKey(const Message &message, const Reflection *reflection, const FieldDescriptor *field)
Definition: wire_format.cc:812
google::protobuf.internal::WireFormat::SkipField
static bool SkipField(io::CodedInputStream *input, uint32 tag, UnknownFieldSet *unknown_fields)
Definition: wire_format.cc:84
GOOGLE_DCHECK_EQ
#define GOOGLE_DCHECK_EQ
Definition: logging.h:196
google::protobuf::Reflection::MapEnd
MapIterator MapEnd(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1795


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:01