Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: hello_message_pack
sysdep.h
00001 /* 00002 * MessagePack system dependencies 00003 * 00004 * Copyright (C) 2008-2010 FURUHASHI Sadayuki 00005 * 00006 * Distributed under the Boost Software License, Version 1.0. 00007 * (See accompanying file LICENSE_1_0.txt or copy at 00008 * http://www.boost.org/LICENSE_1_0.txt) 00009 */ 00010 #ifndef MSGPACK_SYSDEP_H 00011 #define MSGPACK_SYSDEP_H 00012 00013 //#include <msgpack/predef.h> 00014 #define MSGPACK_ENDIAN_LITTLE_BYTE 1 00015 00016 #include <stdlib.h> 00017 #include <stddef.h> 00018 #if defined(_MSC_VER) && _MSC_VER < 1600 00019 typedef __int8 int8_t; 00020 typedef unsigned __int8 uint8_t; 00021 typedef __int16 int16_t; 00022 typedef unsigned __int16 uint16_t; 00023 typedef __int32 int32_t; 00024 typedef unsigned __int32 uint32_t; 00025 typedef __int64 int64_t; 00026 typedef unsigned __int64 uint64_t; 00027 #elif defined(_MSC_VER) // && _MSC_VER >= 1600 00028 # include <stdint.h> 00029 #else 00030 # include <stdint.h> 00031 # include <stdbool.h> 00032 #endif 00033 00034 #if !defined(MSGPACK_DLLEXPORT) 00035 #if defined(_MSC_VER) 00036 # define MSGPACK_DLLEXPORT __declspec(dllexport) 00037 #else /* _MSC_VER */ 00038 # define MSGPACK_DLLEXPORT 00039 #endif /* _MSC_VER */ 00040 #endif 00041 00042 #if defined(_WIN32) 00043 # define _msgpack_atomic_counter_header <windows.h> 00044 typedef long _msgpack_atomic_counter_t; 00045 # define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr) 00046 # define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr) 00047 #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) 00048 00049 # if defined(__cplusplus) 00050 # define _msgpack_atomic_counter_header "gcc_atomic.hpp" 00051 # else 00052 # define _msgpack_atomic_counter_header "gcc_atomic.h" 00053 # endif 00054 00055 #elif defined(__MBED__) 00056 00057 # define _msgpack_atomic_counter_header "cmsis.h" 00058 typedef unsigned int _msgpack_atomic_counter_t; 00059 # define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) 00060 # define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) 00061 00062 #elif defined(__AVR__) 00063 00064 # define _msgpack_atomic_counter_header <util/atomic.h> 00065 typedef unsigned int _msgpack_atomic_counter_t; 00066 # define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) 00067 # define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) 00068 00069 #endif 00070 00071 #ifdef _WIN32 00072 00073 # ifdef __cplusplus 00074 /* numeric_limits<T>::min,max */ 00075 # ifdef max 00076 # undef max 00077 # endif 00078 # ifdef min 00079 # undef min 00080 # endif 00081 # endif 00082 00083 //#else /* _*/ 00084 #elif !defined(__MBED__) && !defined(__AVR__) 00085 00086 #include <arpa/inet.h> /* __BYTE_ORDER */ 00087 # if defined(linux) 00088 # include <byteswap.h> 00089 # endif 00090 00091 #endif 00092 00093 #if MSGPACK_ENDIAN_LITTLE_BYTE 00094 00095 # if defined(_WIN32) || defined(__MBED__) || defined(__AVR__) 00096 # if defined(ntohs) 00097 # define _msgpack_be16(x) ntohs(x) 00098 # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400) 00099 # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x)) 00100 # else 00101 # define _msgpack_be16(x) ( \ 00102 ((((uint16_t)x) << 8) ) | \ 00103 ((((uint16_t)x) >> 8) ) ) 00104 # endif 00105 # else 00106 # define _msgpack_be16(x) ntohs(x) 00107 # endif 00108 00109 # if defined(_WIN32) || defined(__MBED__) || defined(__AVR__) 00110 # if defined(ntohl) 00111 # define _msgpack_be32(x) ntohl(x) 00112 # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400) 00113 # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x)) 00114 # else 00115 # define _msgpack_be32(x) \ 00116 ( ((((uint32_t)x) << 24) ) | \ 00117 ((((uint32_t)x) << 8) & 0x00ff0000U ) | \ 00118 ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \ 00119 ((((uint32_t)x) >> 24) ) ) 00120 # endif 00121 # else 00122 # define _msgpack_be32(x) ntohl(x) 00123 # endif 00124 00125 # if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400) 00126 # define _msgpack_be64(x) (_byteswap_uint64(x)) 00127 # elif defined(bswap_64) 00128 # define _msgpack_be64(x) bswap_64(x) 00129 # elif defined(__DARWIN_OSSwapInt64) 00130 # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) 00131 # else 00132 # define _msgpack_be64(x) \ 00133 ( ((((uint64_t)x) << 56) ) | \ 00134 ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ 00135 ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ 00136 ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ 00137 ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ 00138 ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ 00139 ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ 00140 ((((uint64_t)x) >> 56) ) ) 00141 # endif 00142 00143 #elif MSGPACK_ENDIAN_BIG_BYTE 00144 00145 # define _msgpack_be16(x) (x) 00146 # define _msgpack_be32(x) (x) 00147 # define _msgpack_be64(x) (x) 00148 00149 #else 00150 # error msgpack-c supports only big endian and little endian 00151 #endif /* MSGPACK_ENDIAN_LITTLE_BYTE */ 00152 00153 #define _msgpack_load16(cast, from, to) do { \ 00154 memcpy((cast*)(to), (from), sizeof(cast)); \ 00155 *(to) = _msgpack_be16(*(to)); \ 00156 } while (0); 00157 00158 #define _msgpack_load32(cast, from, to) do { \ 00159 memcpy((cast*)(to), (from), sizeof(cast)); \ 00160 *(to) = _msgpack_be32(*(to)); \ 00161 } while (0); 00162 #define _msgpack_load64(cast, from, to) do { \ 00163 memcpy((cast*)(to), (from), sizeof(cast)); \ 00164 *(to) = _msgpack_be64(*(to)); \ 00165 } while (0); 00166 00167 #define _msgpack_store16(to, num) \ 00168 do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0) 00169 #define _msgpack_store32(to, num) \ 00170 do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0) 00171 #define _msgpack_store64(to, num) \ 00172 do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0) 00173 00174 /* 00175 #define _msgpack_load16(cast, from) \ 00176 ({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); }) 00177 #define _msgpack_load32(cast, from) \ 00178 ({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); }) 00179 #define _msgpack_load64(cast, from) \ 00180 ({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); }) 00181 */ 00182 00183 00184 #if !defined(__cplusplus) && defined(_MSC_VER) 00185 # if !defined(FALSE) 00186 # define FALSE (0) 00187 # endif 00188 # if !defined(TRUE) 00189 # define TRUE (!FALSE) 00190 # endif 00191 # if _MSC_VER >= 1800 00192 # include <stdbool.h> 00193 # else 00194 # define bool int 00195 # define true TRUE 00196 # define false FALSE 00197 # endif 00198 # define inline __inline 00199 #endif 00200 00201 #endif /* msgpack/sysdep.h */
Generated on Tue Jul 12 2022 22:51:46 by
1.7.2