generated_message_table_driven_lite.h
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 #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__
32 #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__
33 
35 
43 #include <type_traits>
44 
45 
46 #include <google/protobuf/port_def.inc>
47 
48 namespace google {
49 namespace protobuf {
50 namespace internal {
51 
52 
53 enum StringType {
56 };
57 
58 // Logically a superset of StringType, consisting of all field types that
59 // require special initialization.
66 };
67 
72 };
73 
74 template <typename Type>
75 inline Type* Raw(MessageLite* msg, int64 offset) {
76  return reinterpret_cast<Type*>(reinterpret_cast<uint8*>(msg) + offset);
77 }
78 
79 template <typename Type>
80 inline const Type* Raw(const MessageLite* msg, int64 offset) {
81  return reinterpret_cast<const Type*>(reinterpret_cast<const uint8*>(msg) +
82  offset);
83 }
84 
85 template <typename InternalMetadata>
86 inline Arena* GetArena(MessageLite* msg, int64 arena_offset) {
87  if (PROTOBUF_PREDICT_FALSE(arena_offset == -1)) {
88  return NULL;
89  }
90 
91  return Raw<InternalMetadata>(msg, arena_offset)->arena();
92 }
93 
94 inline ExtensionSet* GetExtensionSet(MessageLite* msg, int64 extension_offset) {
95  if (extension_offset == -1) {
96  return NULL;
97  }
98 
99  return Raw<ExtensionSet>(msg, extension_offset);
100 }
101 
102 template <typename Type>
104  static_assert(std::is_pod<Type>::value ||
106  "Do not assign");
107 
108  RepeatedField<Type>* repeated = Raw<RepeatedField<Type>>(msg, offset);
109  return repeated->Add();
110 }
111 
112 template <>
113 inline std::string* AddField<std::string>(MessageLite* msg, int64 offset) {
115  Raw<RepeatedPtrField<std::string>>(msg, offset);
116  return repeated->Add();
117 }
118 
119 
120 template <typename Type>
121 inline void AddField(MessageLite* msg, int64 offset, Type value) {
122  static_assert(std::is_pod<Type>::value,
123  "Do not assign");
124  *AddField<Type>(msg, offset) = value;
125 }
126 
127 inline void SetBit(uint32* has_bits, uint32 has_bit_index) {
128  GOOGLE_DCHECK(has_bits != nullptr);
129 
130  uint32 mask = static_cast<uint32>(1u) << (has_bit_index % 32);
131  has_bits[has_bit_index / 32u] |= mask;
132 }
133 
134 template <typename Type>
135 inline Type* MutableField(MessageLite* msg, uint32* has_bits,
136  uint32 has_bit_index, int64 offset) {
137  SetBit(has_bits, has_bit_index);
138  return Raw<Type>(msg, offset);
139 }
140 
141 template <typename Type>
142 inline void SetField(MessageLite* msg, uint32* has_bits, uint32 has_bit_index,
143  int64 offset, Type value) {
144  static_assert(std::is_pod<Type>::value,
145  "Do not assign");
146  *MutableField<Type>(msg, has_bits, has_bit_index, offset) = value;
147 }
148 
149 template <typename Type>
150 inline void SetOneofField(MessageLite* msg, uint32* oneof_case,
151  uint32 oneof_case_index, int64 offset,
152  int field_number, Type value) {
153  oneof_case[oneof_case_index] = field_number;
154  *Raw<Type>(msg, offset) = value;
155 }
156 
157 // Clears a oneof field. The field argument should correspond to the particular
158 // field that is currently set in the oneof.
159 inline void ClearOneofField(const ParseTableField& field, Arena* arena,
160  MessageLite* msg) {
161  switch (field.processing_type & kTypeMask) {
163  if (arena == NULL) {
164  delete *Raw<MessageLite*>(msg, field.offset);
165  }
166  break;
167 
170  Raw<ArenaStringPtr>(msg, field.offset)
171  ->Destroy(&GetEmptyStringAlreadyInited(), arena);
172  break;
173 
174  case TYPE_STRING_INLINED:
175  case TYPE_BYTES_INLINED:
176  Raw<InlinedStringField>(msg, field.offset)->DestroyNoArena(NULL);
177  break;
178 
179  default:
180  // No cleanup needed.
181  break;
182  }
183 }
184 
185 // Clears and reinitializes a oneof field as necessary, in preparation for
186 // parsing a new value with type field_type and field number field_number.
187 //
188 // Note: the oneof_case argument should point directly to the _oneof_case_
189 // element corresponding to this particular oneof, not to the beginning of the
190 // _oneof_case_ array.
191 template <ProcessingType field_type>
192 inline void ResetOneofField(const ParseTable& table, int field_number,
193  Arena* arena, MessageLite* msg, uint32* oneof_case,
194  int64 offset, const void* default_ptr) {
195  if (*oneof_case == field_number) {
196  // The oneof is already set to the right type, so there is no need to clear
197  // it.
198  return;
199  }
200 
201  if (*oneof_case != 0) {
202  ClearOneofField(table.fields[*oneof_case], arena, msg);
203  }
204  *oneof_case = field_number;
205 
206  switch (field_type) {
208  Raw<ArenaStringPtr>(msg, offset)
209  ->UnsafeSetDefault(static_cast<const std::string*>(default_ptr));
210  break;
212  new (Raw<InlinedStringField>(msg, offset))
213  InlinedStringField(*static_cast<const std::string*>(default_ptr));
214  break;
216  MessageLite** submessage = Raw<MessageLite*>(msg, offset);
217  const MessageLite* prototype =
218  table.aux[field_number].messages.default_message();
219  *submessage = prototype->New(arena);
220  break;
221  }
222 }
223 
224 template <typename UnknownFieldHandler, Cardinality cardinality,
225  bool is_string_type, StringType ctype>
227  Arena* arena, uint32* has_bits,
228  uint32 has_bit_index, int64 offset,
229  const void* default_ptr,
230  const char* field_name) {
231  StringPiece utf8_string_data;
232 #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
233  constexpr bool kValidateUtf8 = is_string_type;
234 #else
235  constexpr bool kValidateUtf8 = false;
236 #endif // GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
237 
238  switch (ctype) {
239  case StringType_INLINED: {
240  InlinedStringField* s = nullptr;
241  switch (cardinality) {
243  // TODO(ckennelly): Is this optimal?
244  s = MutableField<InlinedStringField>(msg, has_bits, has_bit_index,
245  offset);
246  break;
248  s = AddField<InlinedStringField>(msg, offset);
249  break;
250  case Cardinality_ONEOF:
251  s = Raw<InlinedStringField>(msg, offset);
252  break;
253  }
254  GOOGLE_DCHECK(s != nullptr);
255  std::string* value = s->MutableNoArena(NULL);
256  if (PROTOBUF_PREDICT_FALSE(!WireFormatLite::ReadString(input, value))) {
257  return false;
258  }
259  utf8_string_data = *value;
260  break;
261  }
262  case StringType_STRING: {
263  switch (cardinality) {
264  case Cardinality_SINGULAR: {
265  ArenaStringPtr* field = MutableField<ArenaStringPtr>(
266  msg, has_bits, has_bit_index, offset);
267  std::string* value = field->Mutable(
268  static_cast<const std::string*>(default_ptr), arena);
269  if (PROTOBUF_PREDICT_FALSE(
271  return false;
272  }
273  utf8_string_data = field->Get();
274  } break;
275  case Cardinality_REPEATED: {
276  std::string* value = AddField<std::string>(msg, offset);
277  if (PROTOBUF_PREDICT_FALSE(
279  return false;
280  }
281  utf8_string_data = *value;
282  } break;
283  case Cardinality_ONEOF: {
284  ArenaStringPtr* field = Raw<ArenaStringPtr>(msg, offset);
285  std::string* value = field->Mutable(
286  static_cast<const std::string*>(default_ptr), arena);
287  if (PROTOBUF_PREDICT_FALSE(
289  return false;
290  }
291  utf8_string_data = field->Get();
292  } break;
293  }
294  break;
295  }
296  }
297 
298  if (kValidateUtf8) {
299  // TODO(b/118759213): fail if proto3
300  WireFormatLite::VerifyUtf8String(utf8_string_data.data(),
301  utf8_string_data.length(),
302  WireFormatLite::PARSE, field_name);
303  }
304  return true;
305 }
306 
307 template <typename UnknownFieldHandler, typename InternalMetadata,
308  Cardinality cardinality>
310  MessageLite* msg, uint32* presence,
311  uint32 presence_index, int64 offset, uint32 tag,
312  int field_number) {
313  int value;
314  if (PROTOBUF_PREDICT_FALSE(
315  (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
316  input, &value)))) {
317  return false;
318  }
319 
321  table.aux[field_number].enums.validator;
322  if (validator == nullptr || validator(value)) {
323  switch (cardinality) {
325  SetField(msg, presence, presence_index, offset, value);
326  break;
328  AddField(msg, offset, value);
329  break;
330  case Cardinality_ONEOF:
331  ClearOneofField(table.fields[presence[presence_index]],
332  GetArena<InternalMetadata>(msg, table.arena_offset),
333  msg);
334  SetOneofField(msg, presence, presence_index, offset, field_number,
335  value);
336  break;
337  }
338  } else {
339  UnknownFieldHandler::Varint(msg, table, tag, value);
340  }
341 
342  return true;
343 }
344 
345 // RepeatedMessageTypeHandler allows us to operate on RepeatedPtrField fields
346 // without instantiating the specific template.
348  public:
349  typedef MessageLite Type;
351  static Arena* GetArena(Type* t) { return t->GetArena(); }
352  static void* GetMaybeArenaPointer(Type* t) {
353  return t->GetMaybeArenaPointer();
354  }
355  static inline Type* NewFromPrototype(const Type* prototype,
356  Arena* arena = NULL) {
357  return prototype->New(arena);
358  }
359  static void Delete(Type* t, Arena* arena = NULL) {
360  if (arena == NULL) {
361  delete t;
362  }
363  }
364 };
365 
367  public:
369  const MessageLite* prototype) {
370  return field->Add<RepeatedMessageTypeHandler>(
371  const_cast<MessageLite*>(prototype));
372  }
373 };
374 
375 template <typename UnknownFieldHandler, typename InternalMetadata,
376  uint32 kMaxTag>
378  const ParseTable& table,
380  // We require that has_bits are present, as to avoid having to check for them
381  // for every field.
382  //
383  // TODO(ckennelly): Make this a compile-time parameter with templates.
384  GOOGLE_DCHECK_GE(table.has_bits_offset, 0);
385  uint32* has_bits = Raw<uint32>(msg, table.has_bits_offset);
386  GOOGLE_DCHECK(has_bits != NULL);
387 
388  while (true) {
389  uint32 tag = input->ReadTagWithCutoffNoLastTag(kMaxTag).first;
390  const WireFormatLite::WireType wire_type =
392  const int field_number = WireFormatLite::GetTagFieldNumber(tag);
393 
394  if (PROTOBUF_PREDICT_FALSE(field_number > table.max_field_number)) {
395  // check for possible extensions
396  if (UnknownFieldHandler::ParseExtension(msg, table, input, tag)) {
397  // successfully parsed
398  continue;
399  }
400 
401  if (PROTOBUF_PREDICT_FALSE(
402  !UnknownFieldHandler::Skip(msg, table, input, tag))) {
403  return false;
404  }
405 
406  continue;
407  }
408 
409  // We implicitly verify that data points to a valid field as we check the
410  // wire types. Entries in table.fields[i] that do not correspond to valid
411  // field numbers have their normal_wiretype and packed_wiretype fields set
412  // with the kInvalidMask value. As wire_type cannot take on that value, we
413  // will never match.
414  const ParseTableField* data = table.fields + field_number;
415 
416  // TODO(ckennelly): Avoid sign extension
417  const int64 presence_index = data->presence_index;
418  const int64 offset = data->offset;
419  const unsigned char processing_type = data->processing_type;
420 
421  if (data->normal_wiretype == static_cast<unsigned char>(wire_type)) {
422  // TODO(ckennelly): Use a computed goto on GCC/LLVM or otherwise eliminate
423  // the bounds check on processing_type.
424 
425  switch (processing_type) {
426 #define HANDLE_TYPE(TYPE, CPPTYPE) \
427  case (WireFormatLite::TYPE_##TYPE): { \
428  CPPTYPE value; \
429  if (PROTOBUF_PREDICT_FALSE( \
430  (!WireFormatLite::ReadPrimitive< \
431  CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \
432  return false; \
433  } \
434  SetField(msg, has_bits, presence_index, offset, value); \
435  break; \
436  } \
437  case (WireFormatLite::TYPE_##TYPE) | kRepeatedMask: { \
438  RepeatedField<CPPTYPE>* values = Raw<RepeatedField<CPPTYPE>>(msg, offset); \
439  if (PROTOBUF_PREDICT_FALSE((!WireFormatLite::ReadRepeatedPrimitive< \
440  CPPTYPE, WireFormatLite::TYPE_##TYPE>( \
441  data->tag_size, tag, input, values)))) { \
442  return false; \
443  } \
444  break; \
445  } \
446  case (WireFormatLite::TYPE_##TYPE) | kOneofMask: { \
447  uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset); \
448  CPPTYPE value; \
449  if (PROTOBUF_PREDICT_FALSE( \
450  (!WireFormatLite::ReadPrimitive< \
451  CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \
452  return false; \
453  } \
454  ClearOneofField(table.fields[oneof_case[presence_index]], \
455  GetArena<InternalMetadata>(msg, table.arena_offset), msg); \
456  SetOneofField(msg, oneof_case, presence_index, offset, field_number, \
457  value); \
458  break; \
459  }
460 
461  HANDLE_TYPE(INT32, int32)
462  HANDLE_TYPE(INT64, int64)
463  HANDLE_TYPE(SINT32, int32)
464  HANDLE_TYPE(SINT64, int64)
465  HANDLE_TYPE(UINT32, uint32)
466  HANDLE_TYPE(UINT64, uint64)
467 
468  HANDLE_TYPE(FIXED32, uint32)
469  HANDLE_TYPE(FIXED64, uint64)
470  HANDLE_TYPE(SFIXED32, int32)
471  HANDLE_TYPE(SFIXED64, int64)
472 
473  HANDLE_TYPE(FLOAT, float)
474  HANDLE_TYPE(DOUBLE, double)
475 
476  HANDLE_TYPE(BOOL, bool)
477 #undef HANDLE_TYPE
479 #ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
481 #endif // GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
482  {
483  Arena* const arena =
484  GetArena<InternalMetadata>(msg, table.arena_offset);
485  const void* default_ptr = table.aux[field_number].strings.default_ptr;
486 
487  if (PROTOBUF_PREDICT_FALSE(
488  (!HandleString<UnknownFieldHandler, Cardinality_SINGULAR,
489  false, StringType_STRING>(
490  input, msg, arena, has_bits, presence_index, offset,
491  default_ptr, nullptr)))) {
492  return false;
493  }
494  break;
495  }
496  case TYPE_BYTES_INLINED:
497 #ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
498  case TYPE_STRING_INLINED:
499 #endif // !GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
500  {
501  Arena* const arena =
502  GetArena<InternalMetadata>(msg, table.arena_offset);
503  const void* default_ptr = table.aux[field_number].strings.default_ptr;
504 
505  if (PROTOBUF_PREDICT_FALSE(
506  (!HandleString<UnknownFieldHandler, Cardinality_SINGULAR,
507  false, StringType_INLINED>(
508  input, msg, arena, has_bits, presence_index, offset,
509  default_ptr, nullptr)))) {
510  return false;
511  }
512  break;
513  }
515 #ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
517 #endif // !GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
518  {
519  Arena* const arena =
520  GetArena<InternalMetadata>(msg, table.arena_offset);
521  uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
522  const void* default_ptr = table.aux[field_number].strings.default_ptr;
523 
524  ResetOneofField<ProcessingType_STRING>(
525  table, field_number, arena, msg, oneof_case + presence_index,
526  offset, default_ptr);
527 
528  if (PROTOBUF_PREDICT_FALSE(
529  (!HandleString<UnknownFieldHandler, Cardinality_ONEOF, false,
530  StringType_STRING>(input, msg, arena, has_bits,
531  presence_index, offset,
532  default_ptr, nullptr)))) {
533  return false;
534  }
535  break;
536  }
539 #ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
542 #endif // !GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
543  {
544  Arena* const arena =
545  GetArena<InternalMetadata>(msg, table.arena_offset);
546  const void* default_ptr = table.aux[field_number].strings.default_ptr;
547 
548  if (PROTOBUF_PREDICT_FALSE(
549  (!HandleString<UnknownFieldHandler, Cardinality_REPEATED,
550  false, StringType_STRING>(
551  input, msg, arena, has_bits, presence_index, offset,
552  default_ptr, nullptr)))) {
553  return false;
554  }
555  break;
556  }
557 #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
559  Arena* const arena =
560  GetArena<InternalMetadata>(msg, table.arena_offset);
561  const void* default_ptr = table.aux[field_number].strings.default_ptr;
562  const char* field_name = table.aux[field_number].strings.field_name;
563 
564  if (PROTOBUF_PREDICT_FALSE(
565  (!HandleString<UnknownFieldHandler, Cardinality_SINGULAR,
566  true, StringType_STRING>(
567  input, msg, arena, has_bits, presence_index, offset,
568  default_ptr, field_name)))) {
569  return false;
570  }
571  break;
572  }
575  Arena* const arena =
576  GetArena<InternalMetadata>(msg, table.arena_offset);
577  const void* default_ptr = table.aux[field_number].strings.default_ptr;
578  const char* field_name = table.aux[field_number].strings.field_name;
579 
580  if (PROTOBUF_PREDICT_FALSE(
581  (!HandleString<UnknownFieldHandler, Cardinality_REPEATED,
582  true, StringType_STRING>(
583  input, msg, arena, has_bits, presence_index, offset,
584  default_ptr, field_name)))) {
585  return false;
586  }
587  break;
588  }
590  Arena* const arena =
591  GetArena<InternalMetadata>(msg, table.arena_offset);
592  uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
593  const void* default_ptr = table.aux[field_number].strings.default_ptr;
594  const char* field_name = table.aux[field_number].strings.field_name;
595 
596  ResetOneofField<ProcessingType_STRING>(
597  table, field_number, arena, msg, oneof_case + presence_index,
598  offset, default_ptr);
599 
600  if (PROTOBUF_PREDICT_FALSE(
601  (!HandleString<UnknownFieldHandler, Cardinality_ONEOF, true,
603  input, msg, arena, has_bits, presence_index, offset,
604  default_ptr, field_name)))) {
605  return false;
606  }
607  break;
608  }
609 #endif // GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
611  if (PROTOBUF_PREDICT_FALSE(
612  (!HandleEnum<UnknownFieldHandler, InternalMetadata,
614  table, input, msg, has_bits, presence_index, offset, tag,
615  field_number)))) {
616  return false;
617  }
618  break;
619  }
621  if (PROTOBUF_PREDICT_FALSE(
622  (!HandleEnum<UnknownFieldHandler, InternalMetadata,
624  table, input, msg, has_bits, presence_index, offset, tag,
625  field_number)))) {
626  return false;
627  }
628  break;
629  }
631  uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
632  if (PROTOBUF_PREDICT_FALSE(
633  (!HandleEnum<UnknownFieldHandler, InternalMetadata,
634  Cardinality_ONEOF>(table, input, msg, oneof_case,
635  presence_index, offset, tag,
636  field_number)))) {
637  return false;
638  }
639  break;
640  }
642  MessageLite** submsg_holder =
643  MutableField<MessageLite*>(msg, has_bits, presence_index, offset);
644  MessageLite* submsg = *submsg_holder;
645 
646  if (submsg == NULL) {
647  Arena* const arena =
648  GetArena<InternalMetadata>(msg, table.arena_offset);
649  const MessageLite* prototype =
650  table.aux[field_number].messages.default_message();
651  submsg = prototype->New(arena);
652  *submsg_holder = submsg;
653  }
654 
655  if (PROTOBUF_PREDICT_FALSE(
656  !WireFormatLite::ReadGroup(field_number, input, submsg))) {
657  return false;
658  }
659 
660  break;
661  }
663  RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset);
664  const MessageLite* prototype =
665  table.aux[field_number].messages.default_message();
666  GOOGLE_DCHECK(prototype != NULL);
667 
668  MessageLite* submsg =
670 
671  if (PROTOBUF_PREDICT_FALSE(
672  !WireFormatLite::ReadGroup(field_number, input, submsg))) {
673  return false;
674  }
675 
676  break;
677  }
679  MessageLite** submsg_holder =
680  MutableField<MessageLite*>(msg, has_bits, presence_index, offset);
681  MessageLite* submsg = *submsg_holder;
682 
683  if (submsg == NULL) {
684  Arena* const arena =
685  GetArena<InternalMetadata>(msg, table.arena_offset);
686  const MessageLite* prototype =
687  table.aux[field_number].messages.default_message();
688  if (prototype == NULL) {
690  }
691  submsg = prototype->New(arena);
692  *submsg_holder = submsg;
693  }
694 
695  if (PROTOBUF_PREDICT_FALSE(
696  !WireFormatLite::ReadMessage(input, submsg))) {
697  return false;
698  }
699 
700  break;
701  }
702  // TODO(ckennelly): Adapt ReadMessageNoVirtualNoRecursionDepth and
703  // manage input->IncrementRecursionDepth() here.
705  RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset);
706  const MessageLite* prototype =
707  table.aux[field_number].messages.default_message();
708  if (prototype == NULL) {
710  }
711 
712  MessageLite* submsg =
714 
715  if (PROTOBUF_PREDICT_FALSE(
716  !WireFormatLite::ReadMessage(input, submsg))) {
717  return false;
718  }
719 
720  break;
721  }
723  Arena* const arena =
724  GetArena<InternalMetadata>(msg, table.arena_offset);
725  uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
726  MessageLite** submsg_holder = Raw<MessageLite*>(msg, offset);
727  ResetOneofField<ProcessingType_MESSAGE>(
728  table, field_number, arena, msg, oneof_case + presence_index,
729  offset, NULL);
730  MessageLite* submsg = *submsg_holder;
731 
732  if (PROTOBUF_PREDICT_FALSE(
733  !WireFormatLite::ReadMessage(input, submsg))) {
734  return false;
735  }
736 
737  break;
738  }
739 #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
740  case TYPE_STRING_INLINED: {
741  Arena* const arena =
742  GetArena<InternalMetadata>(msg, table.arena_offset);
743  const void* default_ptr = table.aux[field_number].strings.default_ptr;
744  const char* field_name = table.aux[field_number].strings.field_name;
745 
746  if (PROTOBUF_PREDICT_FALSE(
747  (!HandleString<UnknownFieldHandler, Cardinality_SINGULAR,
748  true, StringType_INLINED>(
749  input, msg, arena, has_bits, presence_index, offset,
750  default_ptr, field_name)))) {
751  return false;
752  }
753  break;
754  }
755 #endif // GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
756  case TYPE_MAP: {
757  if (PROTOBUF_PREDICT_FALSE(!(*table.aux[field_number].maps.parse_map)(
758  input, Raw<void>(msg, offset)))) {
759  return false;
760  }
761  break;
762  }
763  case 0: {
764  // Done.
765  input->SetLastTag(tag);
766  return true;
767  }
768  default:
769  break;
770  }
771  } else if (data->packed_wiretype == static_cast<unsigned char>(wire_type)) {
772  // Non-packable fields have their packed_wiretype masked with
773  // kNotPackedMask, which is impossible to match here.
774  GOOGLE_DCHECK(processing_type & kRepeatedMask);
775  GOOGLE_DCHECK_NE(processing_type, kRepeatedMask);
776  GOOGLE_DCHECK_EQ(0, processing_type & kOneofMask);
777 
780 
781  // TODO(ckennelly): Use a computed goto on GCC/LLVM.
782  //
783  // Mask out kRepeatedMask bit, allowing the jump table to be smaller.
784  switch (static_cast<WireFormatLite::FieldType>(processing_type ^
785  kRepeatedMask)) {
786 #define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \
787  case WireFormatLite::TYPE_##TYPE: { \
788  RepeatedField<CPPTYPE>* values = Raw<RepeatedField<CPPTYPE>>(msg, offset); \
789  if (PROTOBUF_PREDICT_FALSE( \
790  (!WireFormatLite::ReadPackedPrimitive< \
791  CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, values)))) { \
792  return false; \
793  } \
794  break; \
795  }
796 
799  HANDLE_PACKED_TYPE(SINT32, int32, Int32)
800  HANDLE_PACKED_TYPE(SINT64, int64, Int64)
803 
804  HANDLE_PACKED_TYPE(FIXED32, uint32, UInt32)
805  HANDLE_PACKED_TYPE(FIXED64, uint64, UInt64)
806  HANDLE_PACKED_TYPE(SFIXED32, int32, Int32)
807  HANDLE_PACKED_TYPE(SFIXED64, int64, Int64)
808 
809  HANDLE_PACKED_TYPE(FLOAT, float, Float)
810  HANDLE_PACKED_TYPE(DOUBLE, double, Double)
811 
812  HANDLE_PACKED_TYPE(BOOL, bool, Bool)
813 #undef HANDLE_PACKED_TYPE
815  // To avoid unnecessarily calling MutableUnknownFields (which mutates
816  // InternalMetadataWithArena) when all inputs in the repeated series
817  // are valid, we implement our own parser rather than call
818  // WireFormat::ReadPackedEnumPreserveUnknowns.
819  uint32 length;
820  if (PROTOBUF_PREDICT_FALSE(!input->ReadVarint32(&length))) {
821  return false;
822  }
823 
825  table.aux[field_number].enums.validator;
826  RepeatedField<int>* values = Raw<RepeatedField<int>>(msg, offset);
827 
828  io::CodedInputStream::Limit limit = input->PushLimit(length);
829  while (input->BytesUntilLimit() > 0) {
830  int value;
831  if (PROTOBUF_PREDICT_FALSE(
834  return false;
835  }
836 
837  if (validator == nullptr || validator(value)) {
838  values->Add(value);
839  } else {
840  // TODO(ckennelly): Consider caching here.
841  UnknownFieldHandler::Varint(msg, table, tag, value);
842  }
843  }
844  input->PopLimit(limit);
845 
846  break;
847  }
852  GOOGLE_DCHECK(false);
853  return false;
854  default:
855  break;
856  }
857  } else {
858  if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) {
859  // Must be the end of the message.
860  input->SetLastTag(tag);
861  return true;
862  }
863 
864  // check for possible extensions
865  if (UnknownFieldHandler::ParseExtension(msg, table, input, tag)) {
866  // successfully parsed
867  continue;
868  }
869 
870  // process unknown field.
871  if (PROTOBUF_PREDICT_FALSE(
872  !UnknownFieldHandler::Skip(msg, table, input, tag))) {
873  return false;
874  }
875  }
876  }
877 }
878 
879 template <typename UnknownFieldHandler, typename InternalMetadata>
882  // The main beneficial cutoff values are 1 and 2 byte tags.
883  // Instantiate calls with the appropriate upper tag range
884  if (table.max_field_number <= (0x7F >> 3)) {
885  return MergePartialFromCodedStreamInlined<UnknownFieldHandler,
886  InternalMetadata, 0x7F>(
887  msg, table, input);
888  } else if (table.max_field_number <= (0x3FFF >> 3)) {
889  return MergePartialFromCodedStreamInlined<UnknownFieldHandler,
890  InternalMetadata, 0x3FFF>(
891  msg, table, input);
892  } else {
894  UnknownFieldHandler, InternalMetadata,
895  std::numeric_limits<uint32>::max()>(msg, table, input);
896  }
897 }
898 
899 } // namespace internal
900 } // namespace protobuf
901 } // namespace google
902 
903 #include <google/protobuf/port_undef.inc>
904 
905 #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__
google::protobuf.internal::RepeatedMessageTypeHandler
Definition: generated_message_table_driven_lite.h:347
google::protobuf.internal::WireFormatLite::ReadPrimitive
static PROTOBUF_ALWAYS_INLINE bool ReadPrimitive(io::CodedInputStream *input, CType *value)
google::protobuf.internal::StringType_INLINED
@ StringType_INLINED
Definition: generated_message_table_driven_lite.h:55
table
upb_strtable table
Definition: php/ext/google/protobuf/protobuf.h:1065
google::protobuf.internal::RepeatedMessageTypeHandler::GetArena
static Arena * GetArena(Type *t)
Definition: generated_message_table_driven_lite.h:351
Json::UInt64
unsigned long long int UInt64
Definition: json.h:241
google::protobuf.internal::ExtensionSet
Definition: extension_set.h:179
google::protobuf.internal::GetExtensionSet
ExtensionSet * GetExtensionSet(MessageLite *msg, int64 extension_offset)
Definition: generated_message_table_driven_lite.h:94
google::protobuf::RepeatedPtrField< std::string >
google::protobuf.internal::WireFormatLite::ReadGroup
static bool ReadGroup(int field_number, io::CodedInputStream *input, MessageType *value)
Definition: wire_format_lite.h:1245
google::protobuf::RepeatedPtrField::Add
Element * Add()
Definition: repeated_field.h:2035
google::protobuf.internal::Cardinality_SINGULAR
@ Cardinality_SINGULAR
Definition: generated_message_table_driven_lite.h:69
google::protobuf.internal::GetArena
Arena * GetArena(MessageLite *msg, int64 arena_offset)
Definition: generated_message_table_driven_lite.h:86
google::protobuf.internal::AddField
Type * AddField(MessageLite *msg, int64 offset)
Definition: generated_message_table_driven_lite.h:103
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
wire_format_lite.h
google::protobuf::StringPiece::length
stringpiece_ssize_type length() const
Definition: stringpiece.h:249
google::protobuf.internal::WireFormatLite::PARSE
@ PARSE
Definition: wire_format_lite.h:323
google::protobuf.internal::StringType_STRING
@ StringType_STRING
Definition: generated_message_table_driven_lite.h:54
NULL
NULL
Definition: test_security_zap.cpp:405
google::protobuf.internal::MergePartialFromCodedStreamImpl
bool MergePartialFromCodedStreamImpl(MessageLite *msg, const ParseTable &table, io::CodedInputStream *input)
Definition: generated_message_table_driven_lite.h:880
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.internal::ProcessingType_STRING_PIECE
@ ProcessingType_STRING_PIECE
Definition: generated_message_table_driven_lite.h:63
google::protobuf::StringPiece::data
const char * data() const
Definition: stringpiece.h:247
GOOGLE_DCHECK_GE
#define GOOGLE_DCHECK_GE
Definition: logging.h:201
google::protobuf::MessageLite::GetArena
virtual Arena * GetArena() const
Definition: message_lite.h:206
length
GLenum GLuint GLenum GLsizei length
Definition: glcorearb.h:2695
input
std::string input
Definition: tokenizer_unittest.cc:197
extension_set.h
inlined_string_field.h
google::protobuf::uint8
uint8_t uint8
Definition: protobuf/src/google/protobuf/stubs/port.h:153
google::protobuf.internal::MergePartialFromCodedStreamHelper
Definition: generated_message_table_driven_lite.h:366
GOOGLE_DCHECK
#define GOOGLE_DCHECK
Definition: logging.h:194
s
XmlRpcServer s
google::protobuf.internal::WireFormatLite::TYPE_GROUP
@ TYPE_GROUP
Definition: wire_format_lite.h:121
google::protobuf::uint32
uint32_t uint32
Definition: protobuf/src/google/protobuf/stubs/port.h:155
google::protobuf.internal::Raw
Type * Raw(MessageLite *msg, int64 offset)
Definition: generated_message_table_driven_lite.h:75
google::protobuf.internal::ProcessingType_CORD
@ ProcessingType_CORD
Definition: generated_message_table_driven_lite.h:62
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::RepeatedField
Definition: src/google/protobuf/message.h:184
google::protobuf.internal::WireFormatLite::WIRETYPE_END_GROUP
@ WIRETYPE_END_GROUP
Definition: wire_format_lite.h:106
google::protobuf.internal::SetField
void SetField(MessageLite *msg, uint32 *has_bits, uint32 has_bit_index, int64 offset, Type value)
Definition: generated_message_table_driven_lite.h:142
google::protobuf.internal::TYPE_STRING_INLINED
@ TYPE_STRING_INLINED
Definition: generated_message_table_driven.h:76
google::protobuf.internal::ProcessingType_STRING
@ ProcessingType_STRING
Definition: generated_message_table_driven_lite.h:61
google::protobuf::MessageLite
Definition: message_lite.h:183
google::protobuf::RepeatedField::Add
void Add(const Element &value)
Definition: repeated_field.h:1220
google::protobuf::HANDLE_TYPE
HANDLE_TYPE(int32, FieldDescriptor::CPPTYPE_INT32, -1)
google::protobuf.internal::MergePartialFromCodedStreamHelper::Add
static MessageLite * Add(RepeatedPtrFieldBase *field, const MessageLite *prototype)
Definition: generated_message_table_driven_lite.h:368
testing::internal::Int32
TypeWithSize< 4 >::Int Int32
Definition: gtest-port.h:2241
GOOGLE_DCHECK_NE
#define GOOGLE_DCHECK_NE
Definition: logging.h:197
testing::internal::Double
FloatingPoint< double > Double
Definition: gtest-internal.h:429
testing::internal::UInt32
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:2242
google::protobuf.internal::kTypeMask
static constexpr const unsigned char kTypeMask
Definition: generated_message_table_driven.h:65
google::protobuf.internal::ParseTableField
Definition: generated_message_table_driven.h:124
google::protobuf.internal::TYPE_BYTES_INLINED
@ TYPE_BYTES_INLINED
Definition: generated_message_table_driven.h:77
values
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:3591
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
google::protobuf.internal::Cardinality_ONEOF
@ Cardinality_ONEOF
Definition: generated_message_table_driven_lite.h:71
metadata_lite.h
Type
Definition: type.pb.h:182
google::protobuf.internal::field_type
WireFormatLite::FieldType field_type(FieldType type)
Definition: extension_set_heavy.cc:138
google::protobuf.internal::kOneofMask
static constexpr const unsigned char kOneofMask
Definition: generated_message_table_driven.h:61
mask
GLint GLuint mask
Definition: glcorearb.h:2789
testing::internal::Float
FloatingPoint< float > Float
Definition: gtest-internal.h:428
offset
GLintptr offset
Definition: glcorearb.h:2944
google::protobuf.internal::AuxillaryParseTableField::EnumValidator
bool(* EnumValidator)(int)
Definition: generated_message_table_driven.h:142
google::protobuf::StringPiece
Definition: stringpiece.h:180
google::protobuf.internal::ResetOneofField
void ResetOneofField(const ParseTable &table, int field_number, Arena *arena, MessageLite *msg, uint32 *oneof_case, int64 offset, const void *default_ptr)
Definition: generated_message_table_driven_lite.h:192
google::protobuf::MessageLite::GetMaybeArenaPointer
virtual void * GetMaybeArenaPointer() const
Definition: message_lite.h:217
google::protobuf.internal::HandleString
static bool HandleString(io::CodedInputStream *input, MessageLite *msg, Arena *arena, uint32 *has_bits, uint32 has_bit_index, int64 offset, const void *default_ptr, const char *field_name)
Definition: generated_message_table_driven_lite.h:226
google::protobuf.internal::WireFormatLite::ReadString
static bool ReadString(io::CodedInputStream *input, std::string *value)
Definition: wire_format_lite.h:878
google::protobuf.internal::WireFormatLite::ReadMessage
static bool ReadMessage(io::CodedInputStream *input, MessageType *value)
Definition: wire_format_lite.h:1258
google::protobuf.internal::RepeatedMessageTypeHandler::WeakType
MessageLite WeakType
Definition: generated_message_table_driven_lite.h:350
google::protobuf.internal::WireFormatLite::TYPE_MESSAGE
@ TYPE_MESSAGE
Definition: wire_format_lite.h:122
google::protobuf.internal::SetOneofField
void SetOneofField(MessageLite *msg, uint32 *oneof_case, uint32 oneof_case_index, int64 offset, int field_number, Type value)
Definition: generated_message_table_driven_lite.h:150
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
repeated_field.h
google::protobuf.internal::StringType
StringType
Definition: generated_message_table_driven_lite.h:53
google::protobuf.internal::WireFormatLite::FieldType
FieldType
Definition: wire_format_lite.h:111
generated_message_table_driven.h
google::protobuf.internal::MergePartialFromCodedStreamInlined
bool MergePartialFromCodedStreamInlined(MessageLite *msg, const ParseTable &table, io::CodedInputStream *input)
Definition: generated_message_table_driven_lite.h:377
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
google::protobuf.internal::WireFormatLite::GetTagFieldNumber
static int GetTagFieldNumber(uint32 tag)
Definition: wire_format_lite.h:777
google::protobuf.internal::WireFormatLite::TYPE_BYTES
@ TYPE_BYTES
Definition: wire_format_lite.h:123
google::protobuf.internal::InlinedStringField
Definition: inlined_string_field.h:61
google::protobuf.internal::WireFormatLite::TYPE_STRING
@ TYPE_STRING
Definition: wire_format_lite.h:120
zero_copy_stream_impl_lite.h
google::protobuf.internal::WireFormatLite::GetTagWireType
static WireType GetTagWireType(uint32 tag)
Definition: wire_format_lite.h:773
google::protobuf.internal::RepeatedMessageTypeHandler::GetMaybeArenaPointer
static void * GetMaybeArenaPointer(Type *t)
Definition: generated_message_table_driven_lite.h:352
HANDLE_PACKED_TYPE
#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD)
google::protobuf.internal::SetBit
void SetBit(uint32 *has_bits, uint32 has_bit_index)
Definition: generated_message_table_driven_lite.h:127
google::protobuf.internal::Cardinality
Cardinality
Definition: generated_message_table_driven_lite.h:68
pump.Skip
def Skip(lines, pos, regex)
Definition: pump.py:261
google::protobuf::io::CodedInputStream
Definition: coded_stream.h:173
implicit_weak_message.h
google::protobuf.internal::GetEmptyStringAlreadyInited
const PROTOBUF_EXPORT std::string & GetEmptyStringAlreadyInited()
Definition: message_lite.h:152
google::protobuf.internal::ParseTable
Definition: generated_message_table_driven.h:183
google::protobuf.internal::RepeatedMessageTypeHandler::NewFromPrototype
static Type * NewFromPrototype(const Type *prototype, Arena *arena=NULL)
Definition: generated_message_table_driven_lite.h:355
google::protobuf.internal::WireFormatLite::WireType
WireType
Definition: wire_format_lite.h:101
google::protobuf.internal::RepeatedPtrFieldBase
Definition: repeated_field.h:459
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: glcorearb.h:2879
google::protobuf.internal::RepeatedMessageTypeHandler::Type
MessageLite Type
Definition: generated_message_table_driven_lite.h:349
google::protobuf.internal::ProcessingType_MESSAGE
@ ProcessingType_MESSAGE
Definition: generated_message_table_driven_lite.h:65
google::protobuf.internal::Cardinality_REPEATED
@ Cardinality_REPEATED
Definition: generated_message_table_driven_lite.h:70
google::protobuf.internal::ImplicitWeakMessage::default_instance
static const ImplicitWeakMessage * default_instance()
Definition: implicit_weak_message.cc:66
internal
Definition: any.pb.h:40
google::protobuf.internal::HandleEnum
bool HandleEnum(const ParseTable &table, io::CodedInputStream *input, MessageLite *msg, uint32 *presence, uint32 presence_index, int64 offset, uint32 tag, int field_number)
Definition: generated_message_table_driven_lite.h:309
google::protobuf::io::CodedInputStream::Limit
int Limit
Definition: coded_stream.h:350
google::protobuf.internal::ClearOneofField
void ClearOneofField(const ParseTableField &field, Arena *arena, MessageLite *msg)
Definition: generated_message_table_driven_lite.h:159
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
google::protobuf.internal::ProcessingType_INLINED
@ ProcessingType_INLINED
Definition: generated_message_table_driven_lite.h:64
google::protobuf.internal::kRepeatedMask
static constexpr const unsigned char kRepeatedMask
Definition: generated_message_table_driven.h:62
google::protobuf.internal::RepeatedMessageTypeHandler::Delete
static void Delete(Type *t, Arena *arena=NULL)
Definition: generated_message_table_driven_lite.h:359
google::protobuf.internal::TYPE_MAP
@ TYPE_MAP
Definition: generated_message_table_driven.h:78
Json::Int64
long long int Int64
Definition: json.h:240
google
Definition: data_proto2_to_proto3_util.h:11
google::protobuf.internal::ArenaStringPtr
Definition: arenastring.h:68
google::protobuf.internal::WireFormatLite::TYPE_ENUM
@ TYPE_ENUM
Definition: wire_format_lite.h:125
google::protobuf::MessageLite::New
virtual MessageLite * New() const =0
google::protobuf.internal::MutableField
Type * MutableField(MessageLite *msg, uint32 *has_bits, uint32 has_bit_index, int64 offset)
Definition: generated_message_table_driven_lite.h:135
GOOGLE_DCHECK_EQ
#define GOOGLE_DCHECK_EQ
Definition: logging.h:196
google::protobuf.internal::ProcessingType
ProcessingType
Definition: generated_message_table_driven_lite.h:60


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:51