File indexing completed on 2025-01-31 10:12:04
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef GOOGLE_PROTOBUF_STUBS_PORT_H_
0009 #define GOOGLE_PROTOBUF_STUBS_PORT_H_
0010
0011 #include <assert.h>
0012 #include <stdlib.h>
0013 #include <string.h>
0014
0015 #include <cstddef>
0016 #include <cstdint>
0017 #include <string>
0018
0019 #include "google/protobuf/stubs/platform_macros.h"
0020
0021
0022 #include "google/protobuf/port_def.inc" // NOLINT
0023
0024
0025 #ifdef _MSC_VER
0026 #include <stdlib.h> // NOLINT(build/include)
0027 #include <intrin.h>
0028 #elif defined(__APPLE__)
0029 #include <libkern/OSByteOrder.h>
0030 #elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__)
0031 #include <byteswap.h> // IWYU pragma: export
0032 #endif
0033
0034
0035
0036 #if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
0037 #ifdef LIBPROTOBUF_EXPORTS
0038 #define LIBPROTOBUF_EXPORT __declspec(dllexport)
0039 #else
0040 #define LIBPROTOBUF_EXPORT __declspec(dllimport)
0041 #endif
0042 #ifdef LIBPROTOC_EXPORTS
0043 #define LIBPROTOC_EXPORT __declspec(dllexport)
0044 #else
0045 #define LIBPROTOC_EXPORT __declspec(dllimport)
0046 #endif
0047 #else
0048 #define LIBPROTOBUF_EXPORT
0049 #define LIBPROTOC_EXPORT
0050 #endif
0051
0052 #define PROTOBUF_RUNTIME_DEPRECATED(message) [[deprecated]] (message)
0053 #define GOOGLE_PROTOBUF_RUNTIME_DEPRECATED(message) [[deprecated]] (message)
0054
0055
0056
0057
0058 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
0059 (defined(_MSC_VER) && _MSC_VER >= 1900))
0060
0061
0062
0063 #define LANG_CXX11 1
0064 #else
0065 #error "Protobuf requires at least C++11."
0066 #endif
0067
0068 namespace google {
0069 namespace protobuf {
0070
0071 typedef unsigned int uint;
0072
0073 typedef int8_t int8;
0074 typedef int16_t int16;
0075 typedef int32_t int32;
0076 typedef int64_t int64;
0077
0078 typedef uint8_t uint8;
0079 typedef uint16_t uint16;
0080 typedef uint32_t uint32;
0081 typedef uint64_t uint64;
0082
0083 static const int32 kint32max = 0x7FFFFFFF;
0084 static const int32 kint32min = -kint32max - 1;
0085 static const int64 kint64max = int64_t{0x7FFFFFFFFFFFFFFF};
0086 static const int64 kint64min = -kint64max - 1;
0087 static const uint32 kuint32max = 0xFFFFFFFFu;
0088 static const uint64 kuint64max = uint64_t{0xFFFFFFFFFFFFFFFFu};
0089
0090 inline uint16_t GOOGLE_UNALIGNED_LOAD16(const void *p) {
0091 uint16_t t;
0092 memcpy(&t, p, sizeof t);
0093 return t;
0094 }
0095
0096 inline uint32_t GOOGLE_UNALIGNED_LOAD32(const void *p) {
0097 uint32_t t;
0098 memcpy(&t, p, sizeof t);
0099 return t;
0100 }
0101
0102 inline uint64_t GOOGLE_UNALIGNED_LOAD64(const void *p) {
0103 uint64_t t;
0104 memcpy(&t, p, sizeof t);
0105 return t;
0106 }
0107
0108 inline void GOOGLE_UNALIGNED_STORE16(void *p, uint16_t v) {
0109 memcpy(p, &v, sizeof v);
0110 }
0111
0112 inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32_t v) {
0113 memcpy(p, &v, sizeof v);
0114 }
0115
0116 inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64_t v) {
0117 memcpy(p, &v, sizeof v);
0118 }
0119
0120 #if defined(GOOGLE_PROTOBUF_OS_NACL) \
0121 || (defined(__ANDROID__) && defined(__clang__) \
0122 && (__clang_major__ == 3 && __clang_minor__ == 8) \
0123 && (__clang_patchlevel__ < 275480))
0124 # define GOOGLE_PROTOBUF_USE_PORTABLE_LOG2
0125 #endif
0126
0127
0128 #ifdef _MSC_VER
0129 #define bswap_16(x) _byteswap_ushort(x)
0130 #define bswap_32(x) _byteswap_ulong(x)
0131 #define bswap_64(x) _byteswap_uint64(x)
0132
0133 #elif defined(__APPLE__)
0134
0135 #define bswap_16(x) OSSwapInt16(x)
0136 #define bswap_32(x) OSSwapInt32(x)
0137 #define bswap_64(x) OSSwapInt64(x)
0138
0139 #elif !defined(__linux__) && !defined(__ANDROID__) && !defined(__CYGWIN__)
0140
0141 #ifndef bswap_16
0142 static inline uint16_t bswap_16(uint16_t x) {
0143 return static_cast<uint16_t>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8));
0144 }
0145 #define bswap_16(x) bswap_16(x)
0146 #endif
0147
0148 #ifndef bswap_32
0149 static inline uint32_t bswap_32(uint32_t x) {
0150 return (((x & 0xFF) << 24) |
0151 ((x & 0xFF00) << 8) |
0152 ((x & 0xFF0000) >> 8) |
0153 ((x & 0xFF000000) >> 24));
0154 }
0155 #define bswap_32(x) bswap_32(x)
0156 #endif
0157
0158 #ifndef bswap_64
0159 static inline uint64_t bswap_64(uint64_t x) {
0160 return (((x & uint64_t{0xFFu}) << 56) | ((x & uint64_t{0xFF00u}) << 40) |
0161 ((x & uint64_t{0xFF0000u}) << 24) |
0162 ((x & uint64_t{0xFF000000u}) << 8) |
0163 ((x & uint64_t{0xFF00000000u}) >> 8) |
0164 ((x & uint64_t{0xFF0000000000u}) >> 24) |
0165 ((x & uint64_t{0xFF000000000000u}) >> 40) |
0166 ((x & uint64_t{0xFF00000000000000u}) >> 56));
0167 }
0168 #define bswap_64(x) bswap_64(x)
0169 #endif
0170
0171 #endif
0172
0173
0174
0175 PROTOBUF_EXPORT uint32_t ghtonl(uint32_t x);
0176
0177 class BigEndian {
0178 public:
0179 #ifdef ABSL_IS_LITTLE_ENDIAN
0180
0181 static uint16_t FromHost16(uint16_t x) { return bswap_16(x); }
0182 static uint16_t ToHost16(uint16_t x) { return bswap_16(x); }
0183
0184 static uint32_t FromHost32(uint32_t x) { return bswap_32(x); }
0185 static uint32_t ToHost32(uint32_t x) { return bswap_32(x); }
0186
0187 static uint64_t FromHost64(uint64_t x) { return bswap_64(x); }
0188 static uint64_t ToHost64(uint64_t x) { return bswap_64(x); }
0189
0190 static bool IsLittleEndian() { return true; }
0191
0192 #else
0193
0194 static uint16_t FromHost16(uint16_t x) { return x; }
0195 static uint16_t ToHost16(uint16_t x) { return x; }
0196
0197 static uint32_t FromHost32(uint32_t x) { return x; }
0198 static uint32_t ToHost32(uint32_t x) { return x; }
0199
0200 static uint64_t FromHost64(uint64_t x) { return x; }
0201 static uint64_t ToHost64(uint64_t x) { return x; }
0202
0203 static bool IsLittleEndian() { return false; }
0204
0205 #endif
0206
0207
0208 static uint16_t Load16(const void *p) {
0209 return ToHost16(GOOGLE_UNALIGNED_LOAD16(p));
0210 }
0211
0212 static void Store16(void *p, uint16_t v) {
0213 GOOGLE_UNALIGNED_STORE16(p, FromHost16(v));
0214 }
0215
0216 static uint32_t Load32(const void *p) {
0217 return ToHost32(GOOGLE_UNALIGNED_LOAD32(p));
0218 }
0219
0220 static void Store32(void *p, uint32_t v) {
0221 GOOGLE_UNALIGNED_STORE32(p, FromHost32(v));
0222 }
0223
0224 static uint64_t Load64(const void *p) {
0225 return ToHost64(GOOGLE_UNALIGNED_LOAD64(p));
0226 }
0227
0228 static void Store64(void *p, uint64_t v) {
0229 GOOGLE_UNALIGNED_STORE64(p, FromHost64(v));
0230 }
0231 };
0232
0233 }
0234 }
0235
0236 #include "google/protobuf/port_undef.inc"
0237
0238 #endif