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
43namespace google {
44namespace protobuf {
45namespace internal {
46
47// =============================================================================
48// ZeroFieldsBase
49
50void ZeroFieldsBase::Clear() {
51 _internal_metadata_.Clear<UnknownFieldSet>(); //
52}
53
54ZeroFieldsBase::~ZeroFieldsBase() {
55 (void)_internal_metadata_.DeleteReturnArena<UnknownFieldSet>();
56}
57
58size_t ZeroFieldsBase::ByteSizeLong() const {
59 return MaybeComputeUnknownFieldsSize(total_size: 0, cached_size: &_cached_size_);
60}
61
62const 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: &ptr)) {
70 uint32_t tag;
71 ptr = internal::ReadTag(p: ptr, out: &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, unknown: _internal_metadata_.mutable_unknown_fields<UnknownFieldSet>(), ptr,
79 ctx);
80 CHK_(ptr);
81 } // while
82message_done:
83 return ptr;
84failure:
85 ptr = nullptr;
86 goto message_done;
87#undef CHK_
88}
89
90::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 unknown_fields: _internal_metadata_.unknown_fields<UnknownFieldSet>(
95 default_instance: UnknownFieldSet::default_instance),
96 target, stream);
97 }
98 return target;
99}
100
101void 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>(other: from->_internal_metadata_);
106}
107
108void 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>(other: from->_internal_metadata_);
114}
115
116void ZeroFieldsBase::InternalSwap(ZeroFieldsBase* other) {
117 _internal_metadata_.Swap<UnknownFieldSet>(other: &other->_internal_metadata_);
118}
119
120} // namespace internal
121} // namespace protobuf
122} // namespace google
123
124#include <google/protobuf/port_undef.inc>
125