诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

438 rivejä
14 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. #ifndef GOOGLE_PROTOBUF_STUBS_PORT_H_
  31. #define GOOGLE_PROTOBUF_STUBS_PORT_H_
  32. #include <assert.h>
  33. #include <stdlib.h>
  34. #include <cstddef>
  35. #include <string>
  36. #include <string.h>
  37. #if defined(__osf__)
  38. // Tru64 lacks stdint.h, but has inttypes.h which defines a superset of
  39. // what stdint.h would define.
  40. #include <inttypes.h>
  41. #elif !defined(_MSC_VER)
  42. #include <stdint.h>
  43. #endif
  44. #include <google/protobuf/stubs/platform_macros.h>
  45. #include <google/protobuf/port_def.inc>
  46. #undef PROTOBUF_LITTLE_ENDIAN
  47. #ifdef _WIN32
  48. // Assuming windows is always little-endian.
  49. // TODO(xiaofeng): The PROTOBUF_LITTLE_ENDIAN is not only used for
  50. // optimization but also for correctness. We should define an
  51. // different macro to test the big-endian code path in coded_stream.
  52. #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
  53. #define PROTOBUF_LITTLE_ENDIAN 1
  54. #endif
  55. #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
  56. // If MSVC has "/RTCc" set, it will complain about truncating casts at
  57. // runtime. This file contains some intentional truncating casts.
  58. #pragma runtime_checks("c", off)
  59. #endif
  60. #else
  61. #include <sys/param.h> // __BYTE_ORDER
  62. #if defined(__OpenBSD__)
  63. #include <endian.h>
  64. #endif
  65. #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
  66. (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
  67. (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN)) && \
  68. !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
  69. #define PROTOBUF_LITTLE_ENDIAN 1
  70. #endif
  71. #endif
  72. // These #includes are for the byte swap functions declared later on.
  73. #ifdef _MSC_VER
  74. #include <stdlib.h> // NOLINT(build/include)
  75. #include <intrin.h>
  76. #elif defined(__APPLE__)
  77. #include <libkern/OSByteOrder.h>
  78. #elif defined(__GLIBC__) || defined(__BIONIC__) || defined(__CYGWIN__)
  79. #include <byteswap.h> // IWYU pragma: export
  80. #endif
  81. // Legacy: some users reference these (internal-only) macros even though we
  82. // don't need them any more.
  83. #if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
  84. #ifdef LIBPROTOBUF_EXPORTS
  85. #define LIBPROTOBUF_EXPORT __declspec(dllexport)
  86. #else
  87. #define LIBPROTOBUF_EXPORT __declspec(dllimport)
  88. #endif
  89. #ifdef LIBPROTOC_EXPORTS
  90. #define LIBPROTOC_EXPORT __declspec(dllexport)
  91. #else
  92. #define LIBPROTOC_EXPORT __declspec(dllimport)
  93. #endif
  94. #else
  95. #define LIBPROTOBUF_EXPORT
  96. #define LIBPROTOC_EXPORT
  97. #endif
  98. #define PROTOBUF_RUNTIME_DEPRECATED(message) PROTOBUF_DEPRECATED_MSG(message)
  99. #define GOOGLE_PROTOBUF_RUNTIME_DEPRECATED(message) \
  100. PROTOBUF_DEPRECATED_MSG(message)
  101. // ===================================================================
  102. // from google3/base/port.h
  103. #if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
  104. (defined(_MSC_VER) && _MSC_VER >= 1900))
  105. // Define this to 1 if the code is compiled in C++11 mode; leave it
  106. // undefined otherwise. Do NOT define it to 0 -- that causes
  107. // '#ifdef LANG_CXX11' to behave differently from '#if LANG_CXX11'.
  108. #define LANG_CXX11 1
  109. #endif
  110. #if LANG_CXX11 && !defined(__NVCC__)
  111. #define PROTOBUF_CXX11 1
  112. #else
  113. #define PROTOBUF_CXX11 0
  114. #endif
  115. #if PROTOBUF_CXX11
  116. #define PROTOBUF_FINAL final
  117. #else
  118. #define PROTOBUF_FINAL
  119. #endif
  120. namespace google {
  121. namespace protobuf {
  122. typedef unsigned int uint;
  123. #ifdef _MSC_VER
  124. typedef signed __int8 int8;
  125. typedef __int16 int16;
  126. typedef __int32 int32;
  127. typedef __int64 int64;
  128. typedef unsigned __int8 uint8;
  129. typedef unsigned __int16 uint16;
  130. typedef unsigned __int32 uint32;
  131. typedef unsigned __int64 uint64;
  132. #else
  133. typedef int8_t int8;
  134. typedef int16_t int16;
  135. typedef int32_t int32;
  136. typedef int64_t int64;
  137. typedef uint8_t uint8;
  138. typedef uint16_t uint16;
  139. typedef uint32_t uint32;
  140. typedef uint64_t uint64;
  141. #endif
  142. static const int32 kint32max = 0x7FFFFFFF;
  143. static const int32 kint32min = -kint32max - 1;
  144. static const int64 kint64max = PROTOBUF_LONGLONG(0x7FFFFFFFFFFFFFFF);
  145. static const int64 kint64min = -kint64max - 1;
  146. static const uint32 kuint32max = 0xFFFFFFFFu;
  147. static const uint64 kuint64max = PROTOBUF_ULONGLONG(0xFFFFFFFFFFFFFFFF);
  148. #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) ||\
  149. defined(MEMORY_SANITIZER)
  150. #ifdef __cplusplus
  151. extern "C" {
  152. #endif // __cplusplus
  153. uint16_t __sanitizer_unaligned_load16(const void *p);
  154. uint32_t __sanitizer_unaligned_load32(const void *p);
  155. uint64_t __sanitizer_unaligned_load64(const void *p);
  156. void __sanitizer_unaligned_store16(void *p, uint16_t v);
  157. void __sanitizer_unaligned_store32(void *p, uint32_t v);
  158. void __sanitizer_unaligned_store64(void *p, uint64_t v);
  159. #ifdef __cplusplus
  160. } // extern "C"
  161. #endif // __cplusplus
  162. inline uint16 GOOGLE_UNALIGNED_LOAD16(const void *p) {
  163. return __sanitizer_unaligned_load16(p);
  164. }
  165. inline uint32 GOOGLE_UNALIGNED_LOAD32(const void *p) {
  166. return __sanitizer_unaligned_load32(p);
  167. }
  168. inline uint64 GOOGLE_UNALIGNED_LOAD64(const void *p) {
  169. return __sanitizer_unaligned_load64(p);
  170. }
  171. inline void GOOGLE_UNALIGNED_STORE16(void *p, uint16 v) {
  172. __sanitizer_unaligned_store16(p, v);
  173. }
  174. inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32 v) {
  175. __sanitizer_unaligned_store32(p, v);
  176. }
  177. inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {
  178. __sanitizer_unaligned_store64(p, v);
  179. }
  180. #elif defined(GOOGLE_PROTOBUF_USE_UNALIGNED) && GOOGLE_PROTOBUF_USE_UNALIGNED
  181. #define GOOGLE_UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p))
  182. #define GOOGLE_UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p))
  183. #define GOOGLE_UNALIGNED_LOAD64(_p) (*reinterpret_cast<const uint64 *>(_p))
  184. #define GOOGLE_UNALIGNED_STORE16(_p, _val) (*reinterpret_cast<uint16 *>(_p) = (_val))
  185. #define GOOGLE_UNALIGNED_STORE32(_p, _val) (*reinterpret_cast<uint32 *>(_p) = (_val))
  186. #define GOOGLE_UNALIGNED_STORE64(_p, _val) (*reinterpret_cast<uint64 *>(_p) = (_val))
  187. #else
  188. inline uint16 GOOGLE_UNALIGNED_LOAD16(const void *p) {
  189. uint16 t;
  190. memcpy(&t, p, sizeof t);
  191. return t;
  192. }
  193. inline uint32 GOOGLE_UNALIGNED_LOAD32(const void *p) {
  194. uint32 t;
  195. memcpy(&t, p, sizeof t);
  196. return t;
  197. }
  198. inline uint64 GOOGLE_UNALIGNED_LOAD64(const void *p) {
  199. uint64 t;
  200. memcpy(&t, p, sizeof t);
  201. return t;
  202. }
  203. inline void GOOGLE_UNALIGNED_STORE16(void *p, uint16 v) {
  204. memcpy(p, &v, sizeof v);
  205. }
  206. inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32 v) {
  207. memcpy(p, &v, sizeof v);
  208. }
  209. inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {
  210. memcpy(p, &v, sizeof v);
  211. }
  212. #endif
  213. #if defined(GOOGLE_PROTOBUF_OS_NACL) \
  214. || (defined(__ANDROID__) && defined(__clang__) \
  215. && (__clang_major__ == 3 && __clang_minor__ == 8) \
  216. && (__clang_patchlevel__ < 275480))
  217. # define GOOGLE_PROTOBUF_USE_PORTABLE_LOG2
  218. #endif
  219. #if defined(_MSC_VER)
  220. #define GOOGLE_THREAD_LOCAL __declspec(thread)
  221. #else
  222. #define GOOGLE_THREAD_LOCAL __thread
  223. #endif
  224. // The following guarantees declaration of the byte swap functions.
  225. #ifdef _MSC_VER
  226. #define bswap_16(x) _byteswap_ushort(x)
  227. #define bswap_32(x) _byteswap_ulong(x)
  228. #define bswap_64(x) _byteswap_uint64(x)
  229. #elif defined(__APPLE__)
  230. // Mac OS X / Darwin features
  231. #define bswap_16(x) OSSwapInt16(x)
  232. #define bswap_32(x) OSSwapInt32(x)
  233. #define bswap_64(x) OSSwapInt64(x)
  234. #elif !defined(__GLIBC__) && !defined(__BIONIC__) && !defined(__CYGWIN__)
  235. #ifndef bswap_16
  236. static inline uint16 bswap_16(uint16 x) {
  237. return static_cast<uint16>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8));
  238. }
  239. #define bswap_16(x) bswap_16(x)
  240. #endif
  241. #ifndef bswap_32
  242. static inline uint32 bswap_32(uint32 x) {
  243. return (((x & 0xFF) << 24) |
  244. ((x & 0xFF00) << 8) |
  245. ((x & 0xFF0000) >> 8) |
  246. ((x & 0xFF000000) >> 24));
  247. }
  248. #define bswap_32(x) bswap_32(x)
  249. #endif
  250. #ifndef bswap_64
  251. static inline uint64 bswap_64(uint64 x) {
  252. return (((x & PROTOBUF_ULONGLONG(0xFF)) << 56) |
  253. ((x & PROTOBUF_ULONGLONG(0xFF00)) << 40) |
  254. ((x & PROTOBUF_ULONGLONG(0xFF0000)) << 24) |
  255. ((x & PROTOBUF_ULONGLONG(0xFF000000)) << 8) |
  256. ((x & PROTOBUF_ULONGLONG(0xFF00000000)) >> 8) |
  257. ((x & PROTOBUF_ULONGLONG(0xFF0000000000)) >> 24) |
  258. ((x & PROTOBUF_ULONGLONG(0xFF000000000000)) >> 40) |
  259. ((x & PROTOBUF_ULONGLONG(0xFF00000000000000)) >> 56));
  260. }
  261. #define bswap_64(x) bswap_64(x)
  262. #endif
  263. #endif
  264. // ===================================================================
  265. // from google3/util/bits/bits.h
  266. class Bits {
  267. public:
  268. static uint32 Log2FloorNonZero(uint32 n) {
  269. #if defined(__GNUC__)
  270. return 31 ^ static_cast<uint32>(__builtin_clz(n));
  271. #elif defined(_MSC_VER)
  272. unsigned long where;
  273. _BitScanReverse(&where, n);
  274. return where;
  275. #else
  276. return Log2FloorNonZero_Portable(n);
  277. #endif
  278. }
  279. static uint32 Log2FloorNonZero64(uint64 n) {
  280. // Older versions of clang run into an instruction-selection failure when
  281. // it encounters __builtin_clzll:
  282. // https://bugs.chromium.org/p/nativeclient/issues/detail?id=4395
  283. // This includes arm-nacl-clang and clang in older Android NDK versions.
  284. // To work around this, when we build with those we use the portable
  285. // implementation instead.
  286. #if defined(__GNUC__) && !defined(GOOGLE_PROTOBUF_USE_PORTABLE_LOG2)
  287. return 63 ^ static_cast<uint32>(__builtin_clzll(n));
  288. #elif defined(_MSC_VER) && defined(_M_X64)
  289. unsigned long where;
  290. _BitScanReverse64(&where, n);
  291. return where;
  292. #else
  293. return Log2FloorNonZero64_Portable(n);
  294. #endif
  295. }
  296. private:
  297. static int Log2FloorNonZero_Portable(uint32 n) {
  298. if (n == 0)
  299. return -1;
  300. int log = 0;
  301. uint32 value = n;
  302. for (int i = 4; i >= 0; --i) {
  303. int shift = (1 << i);
  304. uint32 x = value >> shift;
  305. if (x != 0) {
  306. value = x;
  307. log += shift;
  308. }
  309. }
  310. assert(value == 1);
  311. return log;
  312. }
  313. static int Log2FloorNonZero64_Portable(uint64 n) {
  314. const uint32 topbits = static_cast<uint32>(n >> 32);
  315. if (topbits == 0) {
  316. // Top bits are zero, so scan in bottom bits
  317. return static_cast<int>(Log2FloorNonZero(static_cast<uint32>(n)));
  318. } else {
  319. return 32 + static_cast<int>(Log2FloorNonZero(topbits));
  320. }
  321. }
  322. };
  323. // ===================================================================
  324. // from google3/util/endian/endian.h
  325. PROTOBUF_EXPORT uint32 ghtonl(uint32 x);
  326. class BigEndian {
  327. public:
  328. #ifdef PROTOBUF_LITTLE_ENDIAN
  329. static uint16 FromHost16(uint16 x) { return bswap_16(x); }
  330. static uint16 ToHost16(uint16 x) { return bswap_16(x); }
  331. static uint32 FromHost32(uint32 x) { return bswap_32(x); }
  332. static uint32 ToHost32(uint32 x) { return bswap_32(x); }
  333. static uint64 FromHost64(uint64 x) { return bswap_64(x); }
  334. static uint64 ToHost64(uint64 x) { return bswap_64(x); }
  335. static bool IsLittleEndian() { return true; }
  336. #else
  337. static uint16 FromHost16(uint16 x) { return x; }
  338. static uint16 ToHost16(uint16 x) { return x; }
  339. static uint32 FromHost32(uint32 x) { return x; }
  340. static uint32 ToHost32(uint32 x) { return x; }
  341. static uint64 FromHost64(uint64 x) { return x; }
  342. static uint64 ToHost64(uint64 x) { return x; }
  343. static bool IsLittleEndian() { return false; }
  344. #endif /* ENDIAN */
  345. // Functions to do unaligned loads and stores in big-endian order.
  346. static uint16 Load16(const void *p) {
  347. return ToHost16(GOOGLE_UNALIGNED_LOAD16(p));
  348. }
  349. static void Store16(void *p, uint16 v) {
  350. GOOGLE_UNALIGNED_STORE16(p, FromHost16(v));
  351. }
  352. static uint32 Load32(const void *p) {
  353. return ToHost32(GOOGLE_UNALIGNED_LOAD32(p));
  354. }
  355. static void Store32(void *p, uint32 v) {
  356. GOOGLE_UNALIGNED_STORE32(p, FromHost32(v));
  357. }
  358. static uint64 Load64(const void *p) {
  359. return ToHost64(GOOGLE_UNALIGNED_LOAD64(p));
  360. }
  361. static void Store64(void *p, uint64 v) {
  362. GOOGLE_UNALIGNED_STORE64(p, FromHost64(v));
  363. }
  364. };
  365. } // namespace protobuf
  366. } // namespace google
  367. #include <google/protobuf/port_undef.inc>
  368. #endif // GOOGLE_PROTOBUF_STUBS_PORT_H_