• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <cstdint>
32 
33 #include "google/protobuf/extension_set.h"
34 #include "google/protobuf/generated_message_tctable_impl.h"
35 #include "google/protobuf/message.h"
36 #include "google/protobuf/message_lite.h"
37 #include "google/protobuf/parse_context.h"
38 #include "google/protobuf/unknown_field_set.h"
39 #include "google/protobuf/wire_format.h"
40 #include "google/protobuf/wire_format_lite.h"
41 
42 // must be last
43 #include "google/protobuf/port_def.inc"
44 
45 namespace google {
46 namespace protobuf {
47 namespace internal {
48 
GenericFallback(PROTOBUF_TC_PARAM_DECL)49 const char* TcParser::GenericFallback(PROTOBUF_TC_PARAM_DECL) {
50   PROTOBUF_MUSTTAIL return GenericFallbackImpl<Message, UnknownFieldSet>(
51       PROTOBUF_TC_PARAM_PASS);
52 }
53 
ReflectionFallback(PROTOBUF_TC_PARAM_DECL)54 const char* TcParser::ReflectionFallback(PROTOBUF_TC_PARAM_DECL) {
55   bool must_fallback_to_generic = (ptr == nullptr);
56   if (PROTOBUF_PREDICT_FALSE(must_fallback_to_generic)) {
57     PROTOBUF_MUSTTAIL return GenericFallback(PROTOBUF_TC_PARAM_PASS);
58   }
59 
60   SyncHasbits(msg, hasbits, table);
61   uint32_t tag = data.tag();
62   if (tag == 0 || (tag & 7) == WireFormatLite::WIRETYPE_END_GROUP) {
63     ctx->SetLastTag(tag);
64     return ptr;
65   }
66 
67   auto* full_msg = DownCastMessage<Message>(msg);
68   auto* descriptor = full_msg->GetDescriptor();
69   auto* reflection = full_msg->GetReflection();
70   int field_number = WireFormatLite::GetTagFieldNumber(tag);
71   const FieldDescriptor* field = descriptor->FindFieldByNumber(field_number);
72 
73   // If that failed, check if the field is an extension.
74   if (field == nullptr && descriptor->IsExtensionNumber(field_number)) {
75     if (ctx->data().pool == nullptr) {
76       field = reflection->FindKnownExtensionByNumber(field_number);
77     } else {
78       field = ctx->data().pool->FindExtensionByNumber(descriptor, field_number);
79     }
80   }
81 
82   return WireFormat::_InternalParseAndMergeField(full_msg, ptr, ctx, tag,
83                                                  reflection, field);
84 }
85 
ReflectionParseLoop(PROTOBUF_TC_PARAM_DECL)86 const char* TcParser::ReflectionParseLoop(PROTOBUF_TC_PARAM_DECL) {
87   (void)data;
88   (void)table;
89   (void)hasbits;
90   // Call into the wire format reflective parse loop.
91   return WireFormat::_InternalParse(DownCastMessage<Message>(msg), ptr, ctx);
92 }
93 
MessageSetWireFormatParseLoop(PROTOBUF_TC_PARAM_NO_DATA_DECL)94 const char* TcParser::MessageSetWireFormatParseLoop(
95     PROTOBUF_TC_PARAM_NO_DATA_DECL) {
96   PROTOBUF_MUSTTAIL return MessageSetWireFormatParseLoopImpl<Message>(
97       PROTOBUF_TC_PARAM_NO_DATA_PASS);
98 }
99 
100 }  // namespace internal
101 }  // namespace protobuf
102 }  // namespace google
103 
104 #include "google/protobuf/port_undef.inc"
105