1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7
8 #include "google/protobuf/implicit_weak_message.h"
9
10 #include "google/protobuf/generated_message_tctable_decl.h"
11 #include "google/protobuf/message_lite.h"
12 #include "google/protobuf/parse_context.h"
13
14 // Must be included last.
15 #include "google/protobuf/port_def.inc"
16
17 // Since we could be merging Translation units, we must check if this was done
18 // before.
19 #ifndef PROTOBUF_PRAGMA_INIT_SEG_DONE
20 PROTOBUF_PRAGMA_INIT_SEG
21 #define PROTOBUF_PRAGMA_INIT_SEG_DONE
22 #endif
23
24 namespace google {
25 namespace protobuf {
26 namespace internal {
27
ParseImpl(ImplicitWeakMessage * msg,const char * ptr,ParseContext * ctx)28 const char* ImplicitWeakMessage::ParseImpl(ImplicitWeakMessage* msg,
29 const char* ptr, ParseContext* ctx) {
30 return ctx->AppendString(ptr, msg->data_);
31 }
32
MergeImpl(MessageLite & self,const MessageLite & other)33 void ImplicitWeakMessage::MergeImpl(MessageLite& self,
34 const MessageLite& other) {
35 const std::string* other_data =
36 static_cast<const ImplicitWeakMessage&>(other).data_;
37 if (other_data != nullptr) {
38 static_cast<ImplicitWeakMessage&>(self).data_->append(*other_data);
39 }
40 }
41
42 struct ImplicitWeakMessageDefaultType {
ImplicitWeakMessageDefaultTypegoogle::protobuf::internal::ImplicitWeakMessageDefaultType43 constexpr ImplicitWeakMessageDefaultType()
44 : instance(ConstantInitialized{}) {}
~ImplicitWeakMessageDefaultTypegoogle::protobuf::internal::ImplicitWeakMessageDefaultType45 ~ImplicitWeakMessageDefaultType() {}
46 union {
47 ImplicitWeakMessage instance;
48 };
49 };
50
ImplicitWeakMessage(ConstantInitialized)51 constexpr ImplicitWeakMessage::ImplicitWeakMessage(ConstantInitialized)
52 : MessageLite(class_data_.base()), data_(nullptr) {}
53
54 PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT ImplicitWeakMessageDefaultType
55 implicit_weak_message_default_instance;
56
default_instance()57 const ImplicitWeakMessage& ImplicitWeakMessage::default_instance() {
58 return implicit_weak_message_default_instance.instance;
59 }
60
61 const TcParseTable<0> ImplicitWeakMessage::table_ =
62 internal::CreateStubTcParseTable<ImplicitWeakMessage, ParseImpl>(
63 class_data_.base());
64
65 constexpr ClassDataLite<1> ImplicitWeakMessage::class_data_ = {
66 {
67 &implicit_weak_message_default_instance.instance,
68 &table_.header,
69 nullptr, // on_demand_register_arena_dtor
70 nullptr, // is_initialized (always true)
71 MergeImpl,
72 internal::MessageCreator(NewImpl<ImplicitWeakMessage>,
73 sizeof(ImplicitWeakMessage),
74 alignof(ImplicitWeakMessage)),
75 &DestroyImpl,
76 GetClearImpl<ImplicitWeakMessage>(),
77 &ByteSizeLongImpl,
78 &_InternalSerializeImpl,
79 PROTOBUF_FIELD_OFFSET(ImplicitWeakMessage, cached_size_),
80 true,
81 },
82 ""};
83
GetClassData() const84 const ClassData* ImplicitWeakMessage::GetClassData() const {
85 return class_data_.base();
86 }
87
88 } // namespace internal
89 } // namespace protobuf
90 } // namespace google
91
92 #include "google/protobuf/port_undef.inc"
93