xref: /aosp_15_r20/external/cronet/third_party/protobuf/src/google/protobuf/generated_message_bases.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 <google/protobuf/generated_message_bases.h>
32 
33 #include <google/protobuf/io/coded_stream.h>
34 #include <google/protobuf/io/zero_copy_stream_impl.h>
35 #include <google/protobuf/parse_context.h>
36 #include <google/protobuf/unknown_field_set.h>
37 #include <google/protobuf/wire_format.h>
38 #include <google/protobuf/wire_format_lite.h>
39 
40 // Must be last:
41 #include <google/protobuf/port_def.inc>
42 
43 namespace google {
44 namespace protobuf {
45 namespace internal {
46 
47 // =============================================================================
48 // ZeroFieldsBase
49 
Clear()50 void ZeroFieldsBase::Clear() {
51   _internal_metadata_.Clear<UnknownFieldSet>();  //
52 }
53 
~ZeroFieldsBase()54 ZeroFieldsBase::~ZeroFieldsBase() {
55   (void)_internal_metadata_.DeleteReturnArena<UnknownFieldSet>();
56 }
57 
ByteSizeLong() const58 size_t ZeroFieldsBase::ByteSizeLong() const {
59   return MaybeComputeUnknownFieldsSize(0, &_cached_size_);
60 }
61 
_InternalParse(const char * ptr,internal::ParseContext * ctx)62 const char* ZeroFieldsBase::_InternalParse(const char* ptr,
63                                            internal::ParseContext* ctx) {
64 #define CHK_(x)                       \
65   if (PROTOBUF_PREDICT_FALSE(!(x))) { \
66     goto failure;                     \
67   }
68 
69   while (!ctx->Done(&ptr)) {
70     uint32_t tag;
71     ptr = internal::ReadTag(ptr, &tag);
72     if ((tag == 0) || ((tag & 7) == 4)) {
73       CHK_(ptr);
74       ctx->SetLastTag(tag);
75       goto message_done;
76     }
77     ptr = UnknownFieldParse(
78         tag, _internal_metadata_.mutable_unknown_fields<UnknownFieldSet>(), ptr,
79         ctx);
80     CHK_(ptr);
81   }  // while
82 message_done:
83   return ptr;
84 failure:
85   ptr = nullptr;
86   goto message_done;
87 #undef CHK_
88 }
89 
_InternalSerialize(::uint8_t * target,io::EpsCopyOutputStream * stream) const90 ::uint8_t* ZeroFieldsBase::_InternalSerialize(
91     ::uint8_t* target, io::EpsCopyOutputStream* stream) const {
92   if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
93     target = internal::WireFormat::InternalSerializeUnknownFieldsToArray(
94         _internal_metadata_.unknown_fields<UnknownFieldSet>(
95             UnknownFieldSet::default_instance),
96         target, stream);
97   }
98   return target;
99 }
100 
MergeImpl(Message & to_param,const Message & from_param)101 void ZeroFieldsBase::MergeImpl(Message& to_param, const Message& from_param) {
102   auto* to = static_cast<ZeroFieldsBase*>(&to_param);
103   const auto* from = static_cast<const ZeroFieldsBase*>(&from_param);
104   GOOGLE_DCHECK_NE(from, to);
105   to->_internal_metadata_.MergeFrom<UnknownFieldSet>(from->_internal_metadata_);
106 }
107 
CopyImpl(Message & to_param,const Message & from_param)108 void ZeroFieldsBase::CopyImpl(Message& to_param, const Message& from_param) {
109   auto* to = static_cast<ZeroFieldsBase*>(&to_param);
110   const auto* from = static_cast<const ZeroFieldsBase*>(&from_param);
111   if (from == to) return;
112   to->_internal_metadata_.Clear<UnknownFieldSet>();
113   to->_internal_metadata_.MergeFrom<UnknownFieldSet>(from->_internal_metadata_);
114 }
115 
InternalSwap(ZeroFieldsBase * other)116 void ZeroFieldsBase::InternalSwap(ZeroFieldsBase* other) {
117   _internal_metadata_.Swap<UnknownFieldSet>(&other->_internal_metadata_);
118 }
119 
120 }  // namespace internal
121 }  // namespace protobuf
122 }  // namespace google
123 
124 #include <google/protobuf/port_undef.inc>
125