诸暨麻将添加redis
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

255 行
9.3 KiB

  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. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // This file contains miscellaneous helper code used by generated code --
  35. // including lite types -- but which should not be used directly by users.
  36. #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
  37. #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
  38. #include <assert.h>
  39. #include <atomic>
  40. #include <climits>
  41. #include <string>
  42. #include <vector>
  43. #include <google/protobuf/stubs/common.h>
  44. #include <google/protobuf/has_bits.h>
  45. #include <google/protobuf/implicit_weak_message.h>
  46. #include <google/protobuf/message_lite.h>
  47. #include <google/protobuf/stubs/once.h> // Add direct dep on port for pb.cc
  48. #include <google/protobuf/port.h>
  49. #include <google/protobuf/wire_format_lite.h>
  50. #include <google/protobuf/stubs/strutil.h>
  51. #include <google/protobuf/stubs/casts.h>
  52. #include <google/protobuf/port_def.inc>
  53. #ifdef SWIG
  54. #error "You cannot SWIG proto headers"
  55. #endif
  56. namespace google {
  57. namespace protobuf {
  58. class Arena;
  59. namespace io {
  60. class CodedInputStream;
  61. }
  62. namespace internal {
  63. template <typename To, typename From>
  64. inline To DownCast(From* f) {
  65. return PROTOBUF_NAMESPACE_ID::internal::down_cast<To>(f);
  66. }
  67. template <typename To, typename From>
  68. inline To DownCast(From& f) {
  69. return PROTOBUF_NAMESPACE_ID::internal::down_cast<To>(f);
  70. }
  71. PROTOBUF_EXPORT void InitProtobufDefaults();
  72. // This used by proto1
  73. PROTOBUF_EXPORT inline const std::string& GetEmptyString() {
  74. InitProtobufDefaults();
  75. return GetEmptyStringAlreadyInited();
  76. }
  77. // True if IsInitialized() is true for all elements of t. Type is expected
  78. // to be a RepeatedPtrField<some message type>. It's useful to have this
  79. // helper here to keep the protobuf compiler from ever having to emit loops in
  80. // IsInitialized() methods. We want the C++ compiler to inline this or not
  81. // as it sees fit.
  82. template <class Type>
  83. bool AllAreInitialized(const Type& t) {
  84. for (int i = t.size(); --i >= 0;) {
  85. if (!t.Get(i).IsInitialized()) return false;
  86. }
  87. return true;
  88. }
  89. // "Weak" variant of AllAreInitialized, used to implement implicit weak fields.
  90. // This version operates on MessageLite to avoid introducing a dependency on the
  91. // concrete message type.
  92. template <class T>
  93. bool AllAreInitializedWeak(const RepeatedPtrField<T>& t) {
  94. for (int i = t.size(); --i >= 0;) {
  95. if (!reinterpret_cast<const RepeatedPtrFieldBase&>(t)
  96. .Get<ImplicitWeakTypeHandler<T> >(i)
  97. .IsInitialized()) {
  98. return false;
  99. }
  100. }
  101. return true;
  102. }
  103. inline bool IsPresent(const void* base, uint32 hasbit) {
  104. const uint32* has_bits_array = static_cast<const uint32*>(base);
  105. return (has_bits_array[hasbit / 32] & (1u << (hasbit & 31))) != 0;
  106. }
  107. inline bool IsOneofPresent(const void* base, uint32 offset, uint32 tag) {
  108. const uint32* oneof =
  109. reinterpret_cast<const uint32*>(static_cast<const uint8*>(base) + offset);
  110. return *oneof == tag >> 3;
  111. }
  112. typedef void (*SpecialSerializer)(const uint8* base, uint32 offset, uint32 tag,
  113. uint32 has_offset,
  114. io::CodedOutputStream* output);
  115. PROTOBUF_EXPORT void ExtensionSerializer(const uint8* base, uint32 offset,
  116. uint32 tag, uint32 has_offset,
  117. io::CodedOutputStream* output);
  118. PROTOBUF_EXPORT void UnknownFieldSerializerLite(const uint8* base,
  119. uint32 offset, uint32 tag,
  120. uint32 has_offset,
  121. io::CodedOutputStream* output);
  122. PROTOBUF_EXPORT MessageLite* DuplicateIfNonNullInternal(MessageLite* message);
  123. PROTOBUF_EXPORT MessageLite* GetOwnedMessageInternal(Arena* message_arena,
  124. MessageLite* submessage,
  125. Arena* submessage_arena);
  126. PROTOBUF_EXPORT void GenericSwap(MessageLite* m1, MessageLite* m2);
  127. template <typename T>
  128. T* DuplicateIfNonNull(T* message) {
  129. // The casts must be reinterpret_cast<> because T might be a forward-declared
  130. // type that the compiler doesn't know is related to MessageLite.
  131. return reinterpret_cast<T*>(
  132. DuplicateIfNonNullInternal(reinterpret_cast<MessageLite*>(message)));
  133. }
  134. template <typename T>
  135. T* GetOwnedMessage(Arena* message_arena, T* submessage,
  136. Arena* submessage_arena) {
  137. // The casts must be reinterpret_cast<> because T might be a forward-declared
  138. // type that the compiler doesn't know is related to MessageLite.
  139. return reinterpret_cast<T*>(GetOwnedMessageInternal(
  140. message_arena, reinterpret_cast<MessageLite*>(submessage),
  141. submessage_arena));
  142. }
  143. // Hide atomic from the public header and allow easy change to regular int
  144. // on platforms where the atomic might have a perf impact.
  145. class PROTOBUF_EXPORT CachedSize {
  146. public:
  147. int Get() const { return size_.load(std::memory_order_relaxed); }
  148. void Set(int size) { size_.store(size, std::memory_order_relaxed); }
  149. private:
  150. std::atomic<int> size_{0};
  151. };
  152. // SCCInfo represents information of a strongly connected component of
  153. // mutual dependent messages.
  154. struct PROTOBUF_EXPORT SCCInfoBase {
  155. // We use 0 for the Initialized state, because test eax,eax, jnz is smaller
  156. // and is subject to macro fusion.
  157. enum {
  158. kInitialized = 0, // final state
  159. kRunning = 1,
  160. kUninitialized = -1, // initial state
  161. };
  162. #if defined(_MSC_VER) && !defined(__clang__)
  163. // MSVC doesnt make std::atomic constant initialized. This union trick
  164. // makes it so.
  165. union {
  166. int visit_status_to_make_linker_init;
  167. std::atomic<int> visit_status;
  168. };
  169. #else
  170. std::atomic<int> visit_status;
  171. #endif
  172. int num_deps;
  173. int num_implicit_weak_deps;
  174. void (*init_func)();
  175. // This is followed by an array of num_deps
  176. // const SCCInfoBase* deps[];
  177. };
  178. // Zero-length arrays are a language extension available in GCC and Clang but
  179. // not MSVC.
  180. #ifdef __GNUC__
  181. #define PROTOBUF_ARRAY_SIZE(n) (n)
  182. #else
  183. #define PROTOBUF_ARRAY_SIZE(n) ((n) ? (n) : 1)
  184. #endif
  185. template <int N>
  186. struct SCCInfo {
  187. SCCInfoBase base;
  188. // Semantically this is const SCCInfo<T>* which is is a templated type.
  189. // The obvious inheriting from SCCInfoBase mucks with struct initialization.
  190. // Attempts showed the compiler was generating dynamic initialization code.
  191. // This deps array consists of base.num_deps pointers to SCCInfoBase followed
  192. // by base.num_implicit_weak_deps pointers to SCCInfoBase*. We need the extra
  193. // pointer indirection for implicit weak fields. We cannot use a union type
  194. // here, since that would prevent the array from being linker-initialized.
  195. void* deps[PROTOBUF_ARRAY_SIZE(N)];
  196. };
  197. #undef PROTOBUF_ARRAY_SIZE
  198. PROTOBUF_EXPORT void InitSCCImpl(SCCInfoBase* scc);
  199. inline void InitSCC(SCCInfoBase* scc) {
  200. auto status = scc->visit_status.load(std::memory_order_acquire);
  201. if (PROTOBUF_PREDICT_FALSE(status != SCCInfoBase::kInitialized))
  202. InitSCCImpl(scc);
  203. }
  204. PROTOBUF_EXPORT void DestroyMessage(const void* message);
  205. PROTOBUF_EXPORT void DestroyString(const void* s);
  206. // Destroy (not delete) the message
  207. inline void OnShutdownDestroyMessage(const void* ptr) {
  208. OnShutdownRun(DestroyMessage, ptr);
  209. }
  210. // Destroy the string (call std::string destructor)
  211. inline void OnShutdownDestroyString(const std::string* ptr) {
  212. OnShutdownRun(DestroyString, ptr);
  213. }
  214. } // namespace internal
  215. } // namespace protobuf
  216. } // namespace google
  217. #include <google/protobuf/port_undef.inc>
  218. #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__