D.S

dev.mysql.com

MySQL: include/my_byteorder.h Source File

MySQL: include/my_byteorder.h Source File MySQL  8.0.0 Source Code Documentation Main Page Related Pages Modules Namespaces Classes Files File List File Members my_byteorder.h Go to the documentation of this file. 1 #ifndef MY_BYTEORDER_INCLUDED 2 #define MY_BYTEORDER_INCLUDED 3  4 /* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. 5  6  This program is free software; you can redistribute it and/or modify 7  it under the terms of the GNU General Public License as published by 8  the Free Software Foundation; version 2 of the License. 9  10  This program is distributed in the hope that it will be useful, 11  but WITHOUT ANY WARRANTY; without even the implied warranty of 12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  GNU General Public License for more details. 14  15  You should have received a copy of the GNU General Public License 16  along with this program; if not, write to the Free Software 17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 18  19  20 /** 21  @file include/my_byteorder.h 22  Functions for reading and storing in machine independent 23  format (low byte first). There are 'korr' (assume 'corrector') variants 24  for integer types, but 'get' (assume 'getter') for floating point types. 25 */ 26  27 #if defined(__i386__) || defined(_WIN32) || defined(__x86_64__) 28 #include " byte_order_generic_x86.h " 29 #else 30 #include " byte_order_generic.h " 31 #endif 32  33  static inline int32 sint3korr (const uchar *A) 34 { 35  return 36  ((int32) (((A[2]) & 128) ? 37  (((uint32) 255 L << 24) | 38  (((uint32) A[2]) << 16) | 39  (((uint32) A[1]) << 8) | 40  ((uint32) A[0])) : 41  (((uint32) A[2]) << 16) | 42  (((uint32) A[1]) << 8) | 43  ((uint32) A[0]))) 44  ; 45 } 46  47  static inline uint32 uint3korr (const uchar *A) 48 { 49  return 50  (uint32) (((uint32) (A[0])) + 51  (((uint32) (A[1])) << 8) + 52  (((uint32) (A[2])) << 16)) 53  ; 54 } 55  56  static inline ulonglong uint5korr (const uchar *A) 57 { 58  return 59  (( ulonglong )(((uint32) (A[0])) + 60  (((uint32) (A[1])) << 8) + 61  (((uint32) (A[2])) << 16) + 62  (((uint32) (A[3])) << 24)) + 63  ((( ulonglong ) (A[4])) << 32)) 64  ; 65 } 66  67  static inline ulonglong uint6korr (const uchar *A) 68 { 69  return 70  (( ulonglong )(((uint32) (A[0])) + 71  (((uint32) (A[1])) << 8) + 72  (((uint32) (A[2])) << 16) + 73  (((uint32) (A[3])) << 24)) + 74  ((( ulonglong ) (A[4])) << 32) + 75  ((( ulonglong ) (A[5])) << 40)) 76  ; 77 } 78  79 /** 80  int3store 81  82  Stores an unsinged integer in a platform independent way 83  84  @param T The destination buffer. Must be at least 3 bytes long 85  @param A The integer to store. 86  87  _Example:_ 88  A @ref a_protocol_type_int3 "int <3>" with the value 1 is stored as: 89  ~~~~~~~~~~~~~~~~~~~~~ 90  01 00 00 91  ~~~~~~~~~~~~~~~~~~~~~ 92 */ 93  static inline void int3store ( uchar *T, uint A) 94 { 95  *(T)= ( uchar ) (A); 96  *(T+1)= ( uchar ) (A >> 8); 97  *(T+2)= ( uchar ) (A >> 16); 98 } 99  100  static inline void int5store ( uchar *T, ulonglong A) 101 { 102  *(T)= ( uchar ) (A); 103  *(T+1)= ( uchar ) (A >> 8); 104  *(T+2)= ( uchar ) (A >> 16); 105  *(T+3)= ( uchar ) (A >> 24); 106  *(T+4)= ( uchar ) (A >> 32); 107 } 108  109  static inline void int6store ( uchar *T, ulonglong A) 110 { 111  *(T)= ( uchar ) (A); 112  *(T+1)= ( uchar ) (A >> 8); 113  *(T+2)= ( uchar ) (A >> 16); 114  *(T+3)= ( uchar ) (A >> 24); 115  *(T+4)= ( uchar ) (A >> 32); 116  *(T+5)= ( uchar ) (A >> 40); 117 } 118  119 #ifdef __cplusplus 120  121  static inline int16 sint2korr (const char *pT) 122 { 123  return sint2korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 124 } 125  126  static inline uint16 uint2korr (const char *pT) 127 { 128  return uint2korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 129 } 130  131  static inline uint32 uint3korr (const char *pT) 132 { 133  return uint3korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 134 } 135  136  static inline int32 sint3korr (const char *pT) 137 { 138  return sint3korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 139 } 140  141  static inline uint32 uint4korr (const char *pT) 142 { 143  return uint4korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 144 } 145  146  static inline int32 sint4korr (const char *pT) 147 { 148  return sint4korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 149 } 150  151  static inline ulonglong uint6korr (const char *pT) 152 { 153  return uint6korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 154 } 155  156  static inline ulonglong uint8korr (const char *pT) 157 { 158  return uint8korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 159 } 160  161  static inline longlong sint8korr (const char *pT) 162 { 163  return sint8korr (static_cast<const uchar*>(static_cast<const void*>(pT))); 164 } 165  166  167  static inline void int2store (char *pT, uint16 A) 168 { 169  in