Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:12:20

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef GOOGLE_PROTOBUF_FIELD_ACCESS_LISTENER_H__
0009 #define GOOGLE_PROTOBUF_FIELD_ACCESS_LISTENER_H__
0010 
0011 #include <cstddef>
0012 
0013 #include "google/protobuf/message_lite.h"
0014 #include "google/protobuf/port.h"
0015 
0016 
0017 namespace google {
0018 namespace protobuf {
0019 
0020 // A default/no-op implementation of message hooks.
0021 //
0022 // See go/statically-dispatched-message-hooks for details.
0023 template <typename Proto>
0024 struct NoOpAccessListener {
0025   // Number of fields are provided at compile time for the trackers to be able
0026   // to have stack allocated bitmaps for the fields. This is useful for
0027   // performance critical trackers. This is also to avoid cyclic dependencies
0028   // if the number of fields is needed.
0029   static constexpr int kFields = Proto::_kInternalFieldNumber;
0030   // Default constructor is called during the static global initialization of
0031   // the program.
0032   // We provide a pointer to extract the name of the proto not to get cyclic
0033   // dependencies on GetDescriptor() and OnGetMetadata() calls. If you want
0034   // to differentiate the protos during the runtime before the start of the
0035   // program, use this functor to get its name. We either way need it for
0036   // LITE_RUNTIME protos as they don't have descriptors at all.
0037   explicit NoOpAccessListener(absl::string_view (* /*name_extractor*/)()) {}
0038   // called repeatedly during serialization/deserialization/ByteSize of
0039   // Reflection as:
0040   //   AccessListener<MessageT>::OnSerialize(this);
0041   static void OnSerialize(const MessageLite* /*msg*/) {}
0042   static void OnDeserialize(const MessageLite* /*msg*/) {}
0043   static void OnByteSize(const MessageLite* /*msg*/) {}
0044   static void OnMergeFrom(const MessageLite* /*to*/,
0045                           const MessageLite* /*from*/) {}
0046 
0047   // NOTE: This function can be called pre-main. Make sure it does not make
0048   // the state of the listener invalid.
0049   static void OnGetMetadata() {}
0050 
0051   // called from accessors as:
0052   //   AccessListener<MessageT>::On$operation(this, &field_storage_);
0053   // If you need to override this with type, in your hook implementation
0054   // introduce
0055   // template <int kFieldNum, typename T>
0056   // static void On$operation(const MessageLite* msg,
0057   //                          const T* field) {}
0058   // And overloads for std::nullptr_t for incomplete types such as Messages,
0059   // Maps. Extract them using reflection if you need. Consequently, second
0060   // argument can be null pointer.
0061   // For an example, see proto_hooks/testing/memory_test_field_listener.h
0062   // And argument template deduction will deduce the type itself without
0063   // changing the generated code.
0064 
0065   // add_<field>(f)
0066   template <int kFieldNum>
0067   static void OnAdd(const MessageLite* /*msg*/, const void* /*field*/) {}
0068 
0069   // add_<field>()
0070   template <int kFieldNum>
0071   static void OnAddMutable(const MessageLite* /*msg*/, const void* /*field*/) {}
0072 
0073   // <field>() and <repeated_field>(i)
0074   template <int kFieldNum>
0075   static void OnGet(const MessageLite* /*msg*/, const void* /*field*/) {}
0076 
0077   // clear_<field>()
0078   template <int kFieldNum>
0079   static void OnClear(const MessageLite* /*msg*/, const void* /*field*/) {}
0080 
0081   // has_<field>()
0082   template <int kFieldNum>
0083   static void OnHas(const MessageLite* /*msg*/, const void* /*field*/) {}
0084 
0085   // <repeated_field>()
0086   template <int kFieldNum>
0087   static void OnList(const MessageLite* /*msg*/, const void* /*field*/) {}
0088 
0089   // mutable_<field>()
0090   template <int kFieldNum>
0091   static void OnMutable(const MessageLite* /*msg*/, const void* /*field*/) {}
0092 
0093   // mutable_<repeated_field>()
0094   template <int kFieldNum>
0095   static void OnMutableList(const MessageLite* /*msg*/, const void* /*field*/) {
0096   }
0097 
0098   // release_<field>()
0099   template <int kFieldNum>
0100   static void OnRelease(const MessageLite* /*msg*/, const void* /*field*/) {}
0101 
0102   // set_<field>() and set_<repeated_field>(i)
0103   template <int kFieldNum>
0104   static void OnSet(const MessageLite* /*msg*/, const void* /*field*/) {}
0105 
0106   // <repeated_field>_size()
0107   template <int kFieldNum>
0108   static void OnSize(const MessageLite* /*msg*/, const void* /*field*/) {}
0109 
0110   // unknown_fields()
0111   static void OnUnknownFields(const MessageLite* /*msg*/) {}
0112 
0113   // mutable_unknown_fields()
0114   static void OnMutableUnknownFields(const MessageLite* /*msg*/) {}
0115 
0116   static void OnHasExtension(const MessageLite* /*msg*/, int /*extension_tag*/,
0117                              const void* /*field*/) {}
0118   // TODO: Support clear in the proto compiler.
0119   static void OnClearExtension(const MessageLite* /*msg*/,
0120                                int /*extension_tag*/, const void* /*field*/) {}
0121   static void OnExtensionSize(const MessageLite* /*msg*/, int /*extension_tag*/,
0122                               const void* /*field*/) {}
0123   static void OnGetExtension(const MessageLite* /*msg*/, int /*extension_tag*/,
0124                              const void* /*field*/) {}
0125   static void OnMutableExtension(const MessageLite* /*msg*/,
0126                                  int /*extension_tag*/, const void* /*field*/) {
0127   }
0128   static void OnSetExtension(const MessageLite* /*msg*/, int /*extension_tag*/,
0129                              const void* /*field*/) {}
0130   static void OnReleaseExtension(const MessageLite* /*msg*/,
0131                                  int /*extension_tag*/, const void* /*field*/) {
0132   }
0133   static void OnAddExtension(const MessageLite* /*msg*/, int /*extension_tag*/,
0134                              const void* /*field*/) {}
0135   static void OnAddMutableExtension(const MessageLite* /*msg*/,
0136                                     int /*extension_tag*/,
0137                                     const void* /*field*/) {}
0138   static void OnListExtension(const MessageLite* /*msg*/, int /*extension_tag*/,
0139                               const void* /*field*/) {}
0140   static void OnMutableListExtension(const MessageLite* /*msg*/,
0141                                      int /*extension_tag*/,
0142                                      const void* /*field*/) {}
0143 };
0144 
0145 }  // namespace protobuf
0146 }  // namespace google
0147 
0148 #ifndef REPLACE_PROTO_LISTENER_IMPL
0149 namespace google {
0150 namespace protobuf {
0151 template <class T>
0152 using AccessListener = NoOpAccessListener<T>;
0153 }  // namespace protobuf
0154 }  // namespace google
0155 #else
0156 // You can put your implementations of hooks/listeners here.
0157 // All hooks are subject to approval by protobuf-team@.
0158 
0159 #endif  // !REPLACE_PROTO_LISTENER_IMPL
0160 
0161 #endif  // GOOGLE_PROTOBUF_FIELD_ACCESS_LISTENER_H__