00001 /********************************************************************** 00002 Utilities for converting data from the database file 00003 to the machine format. 00004 00005 (c) 1995 Innobase Oy 00006 00007 Created 11/28/1995 Heikki Tuuri 00008 ***********************************************************************/ 00009 00010 #ifndef mach0data_h 00011 #define mach0data_h 00012 00013 #include "univ.i" 00014 #include "ut0byte.h" 00015 00016 /* The data and all fields are always stored in a database file 00017 in the same format: ascii, big-endian, ... . 00018 All data in the files MUST be accessed using the functions in this 00019 module. */ 00020 00021 /*********************************************************** 00022 The following function is used to store data in one byte. */ 00023 UNIV_INLINE 00024 void 00025 mach_write_to_1( 00026 /*============*/ 00027 byte* b, /* in: pointer to byte where to store */ 00028 ulint n); /* in: ulint integer to be stored, >= 0, < 256 */ 00029 /************************************************************ 00030 The following function is used to fetch data from one byte. */ 00031 UNIV_INLINE 00032 ulint 00033 mach_read_from_1( 00034 /*=============*/ 00035 /* out: ulint integer, >= 0, < 256 */ 00036 byte* b); /* in: pointer to byte */ 00037 /*********************************************************** 00038 The following function is used to store data in two consecutive 00039 bytes. We store the most significant byte to the lower address. */ 00040 UNIV_INLINE 00041 void 00042 mach_write_to_2( 00043 /*============*/ 00044 byte* b, /* in: pointer to two bytes where to store */ 00045 ulint n); /* in: ulint integer to be stored, >= 0, < 64k */ 00046 /************************************************************ 00047 The following function is used to fetch data from two consecutive 00048 bytes. The most significant byte is at the lowest address. */ 00049 UNIV_INLINE 00050 ulint 00051 mach_read_from_2( 00052 /*=============*/ 00053 /* out: ulint integer, >= 0, < 64k */ 00054 byte* b); /* in: pointer to two bytes */ 00055 00056 /************************************************************ 00057 The following function is used to convert a 16-bit data item 00058 to the canonical format, for fast bytewise equality test 00059 against memory. */ 00060 UNIV_INLINE 00061 uint16 00062 mach_encode_2( 00063 /*==========*/ 00064 /* out: 16-bit integer in canonical format */ 00065 ulint n); /* in: integer in machine-dependent format */ 00066 /************************************************************ 00067 The following function is used to convert a 16-bit data item 00068 from the canonical format, for fast bytewise equality test 00069 against memory. */ 00070 UNIV_INLINE 00071 ulint 00072 mach_decode_2( 00073 /*==========*/ 00074 /* out: integer in machine-dependent format */ 00075 uint16 n); /* in: 16-bit integer in canonical format */ 00076 /*********************************************************** 00077 The following function is used to store data in 3 consecutive 00078 bytes. We store the most significant byte to the lowest address. */ 00079 UNIV_INLINE 00080 void 00081 mach_write_to_3( 00082 /*============*/ 00083 byte* b, /* in: pointer to 3 bytes where to store */ 00084 ulint n); /* in: ulint integer to be stored */ 00085 /************************************************************ 00086 The following function is used to fetch data from 3 consecutive 00087 bytes. The most significant byte is at the lowest address. */ 00088 UNIV_INLINE 00089 ulint 00090 mach_read_from_3( 00091 /*=============*/ 00092 /* out: ulint integer */ 00093 byte* b); /* in: pointer to 3 bytes */ 00094 /*********************************************************** 00095 The following function is used to store data in four consecutive 00096 bytes. We store the most significant byte to the lowest address. */ 00097 UNIV_INLINE 00098 void 00099 mach_write_to_4( 00100 /*============*/ 00101 byte* b, /* in: pointer to four bytes where to store */ 00102 ulint n); /* in: ulint integer to be stored */ 00103 /************************************************************ 00104 The following function is used to fetch data from 4 consecutive 00105 bytes. The most significant byte is at the lowest address. */ 00106 UNIV_INLINE 00107 ulint 00108 mach_read_from_4( 00109 /*=============*/ 00110 /* out: ulint integer */ 00111 byte* b); /* in: pointer to four bytes */ 00112 /************************************************************* 00113 Writes a ulint in a compressed form (1..5 bytes). */ 00114 UNIV_INLINE 00115 ulint 00116 mach_write_compressed( 00117 /*==================*/ 00118 /* out: stored size in bytes */ 00119 byte* b, /* in: pointer to memory where to store */ 00120 ulint n); /* in: ulint integer to be stored */ 00121 /************************************************************* 00122 Returns the size of an ulint when written in the compressed form. */ 00123 UNIV_INLINE 00124 ulint 00125 mach_get_compressed_size( 00126 /*=====================*/ 00127 /* out: compressed size in bytes */ 00128 ulint n); /* in: ulint integer to be stored */ 00129 /************************************************************* 00130 Reads a ulint in a compressed form. */ 00131 UNIV_INLINE 00132 ulint 00133 mach_read_compressed( 00134 /*=================*/ 00135 /* out: read integer */ 00136 byte* b); /* in: pointer to memory from where to read */ 00137 /*********************************************************** 00138 The following function is used to store data in 6 consecutive 00139 bytes. We store the most significant byte to the lowest address. */ 00140 UNIV_INLINE 00141 void 00142 mach_write_to_6( 00143 /*============*/ 00144 byte* b, /* in: pointer to 6 bytes where to store */ 00145 dulint n); /* in: dulint integer to be stored */ 00146 /************************************************************ 00147 The following function is used to fetch data from 6 consecutive 00148 bytes. The most significant byte is at the lowest address. */ 00149 UNIV_INLINE 00150 dulint 00151 mach_read_from_6( 00152 /*=============*/ 00153 /* out: dulint integer */ 00154 byte* b); /* in: pointer to 6 bytes */ 00155 /*********************************************************** 00156 The following function is used to store data in 7 consecutive 00157 bytes. We store the most significant byte to the lowest address. */ 00158 UNIV_INLINE 00159 void 00160 mach_write_to_7( 00161 /*============*/ 00162 byte* b, /* in: pointer to 7 bytes where to store */ 00163 dulint n); /* in: dulint integer to be stored */ 00164 /************************************************************ 00165 The following function is used to fetch data from 7 consecutive 00166 bytes. The most significant byte is at the lowest address. */ 00167 UNIV_INLINE 00168 dulint 00169 mach_read_from_7( 00170 /*=============*/ 00171 /* out: dulint integer */ 00172 byte* b); /* in: pointer to 7 bytes */ 00173 /*********************************************************** 00174 The following function is used to store data in 8 consecutive 00175 bytes. We store the most significant byte to the lowest address. */ 00176 UNIV_INLINE 00177 void 00178 mach_write_to_8( 00179 /*============*/ 00180 byte* b, /* in: pointer to 8 bytes where to store */ 00181 dulint n); /* in: dulint integer to be stored */ 00182 /************************************************************ 00183 The following function is used to fetch data from 8 consecutive 00184 bytes. The most significant byte is at the lowest address. */ 00185 UNIV_INLINE 00186 dulint 00187 mach_read_from_8( 00188 /*=============*/ 00189 /* out: dulint integer */ 00190 byte* b); /* in: pointer to 8 bytes */ 00191 /************************************************************* 00192 Writes a dulint in a compressed form (5..9 bytes). */ 00193 UNIV_INLINE 00194 ulint 00195 mach_dulint_write_compressed( 00196 /*=========================*/ 00197 /* out: size in bytes */ 00198 byte* b, /* in: pointer to memory where to store */ 00199 dulint n); /* in: dulint integer to be stored */ 00200 /************************************************************* 00201 Returns the size of a dulint when written in the compressed form. */ 00202 UNIV_INLINE 00203 ulint 00204 mach_dulint_get_compressed_size( 00205 /*============================*/ 00206 /* out: compressed size in bytes */ 00207 dulint n); /* in: dulint integer to be stored */ 00208 /************************************************************* 00209 Reads a dulint in a compressed form. */ 00210 UNIV_INLINE 00211 dulint 00212 mach_dulint_read_compressed( 00213 /*========================*/ 00214 /* out: read dulint */ 00215 byte* b); /* in: pointer to memory from where to read */ 00216 /************************************************************* 00217 Writes a dulint in a compressed form (1..11 bytes). */ 00218 UNIV_INLINE 00219 ulint 00220 mach_dulint_write_much_compressed( 00221 /*==============================*/ 00222 /* out: size in bytes */ 00223 byte* b, /* in: pointer to memory where to store */ 00224 dulint n); /* in: dulint integer to be stored */ 00225 /************************************************************* 00226 Returns the size of a dulint when written in the compressed form. */ 00227 UNIV_INLINE 00228 ulint 00229 mach_dulint_get_much_compressed_size( 00230 /*=================================*/ 00231 /* out: compressed size in bytes */ 00232 dulint n); /* in: dulint integer to be stored */ 00233 /************************************************************* 00234 Reads a dulint in a compressed form. */ 00235 UNIV_INLINE 00236 dulint 00237 mach_dulint_read_much_compressed( 00238 /*=============================*/ 00239 /* out: read dulint */ 00240 byte* b); /* in: pointer to memory from where to read */ 00241 /************************************************************* 00242 Reads a ulint in a compressed form if the log record fully contains it. */ 00243 00244 byte* 00245 mach_parse_compressed( 00246 /*==================*/ 00247 /* out: pointer to end of the stored field, NULL if 00248 not complete */ 00249 byte* ptr, /* in: pointer to buffer from where to read */ 00250 byte* end_ptr,/* in: pointer to end of the buffer */ 00251 ulint* val); /* out: read value */ 00252 /************************************************************* 00253 Reads a dulint in a compressed form if the log record fully contains it. */ 00254 00255 byte* 00256 mach_dulint_parse_compressed( 00257 /*=========================*/ 00258 /* out: pointer to end of the stored field, NULL if 00259 not complete */ 00260 byte* ptr, /* in: pointer to buffer from where to read */ 00261 byte* end_ptr,/* in: pointer to end of the buffer */ 00262 dulint* val); /* out: read value */ 00263 /************************************************************* 00264 Reads a double. It is stored in a little-endian format. */ 00265 UNIV_INLINE 00266 double 00267 mach_double_read( 00268 /*=============*/ 00269 /* out: double read */ 00270 byte* b); /* in: pointer to memory from where to read */ 00271 /************************************************************* 00272 Writes a double. It is stored in a little-endian format. */ 00273 UNIV_INLINE 00274 void 00275 mach_double_write( 00276 /*==============*/ 00277 byte* b, /* in: pointer to memory where to write */ 00278 double d); /* in: double */ 00279 /************************************************************* 00280 Reads a float. It is stored in a little-endian format. */ 00281 UNIV_INLINE 00282 float 00283 mach_float_read( 00284 /*============*/ 00285 /* out: float read */ 00286 byte* b); /* in: pointer to memory from where to read */ 00287 /************************************************************* 00288 Writes a float. It is stored in a little-endian format. */ 00289 UNIV_INLINE 00290 void 00291 mach_float_write( 00292 /*=============*/ 00293 byte* b, /* in: pointer to memory where to write */ 00294 float d); /* in: float */ 00295 /************************************************************* 00296 Reads a ulint stored in the little-endian format. */ 00297 UNIV_INLINE 00298 ulint 00299 mach_read_from_n_little_endian( 00300 /*===========================*/ 00301 /* out: unsigned long int */ 00302 byte* buf, /* in: from where to read */ 00303 ulint buf_size); /* in: from how many bytes to read */ 00304 /************************************************************* 00305 Writes a ulint in the little-endian format. */ 00306 UNIV_INLINE 00307 void 00308 mach_write_to_n_little_endian( 00309 /*==========================*/ 00310 byte* dest, /* in: where to write */ 00311 ulint dest_size, /* in: into how many bytes to write */ 00312 ulint n); /* in: unsigned long int to write */ 00313 /************************************************************* 00314 Reads a ulint stored in the little-endian format. */ 00315 UNIV_INLINE 00316 ulint 00317 mach_read_from_2_little_endian( 00318 /*===========================*/ 00319 /* out: unsigned long int */ 00320 byte* buf); /* in: from where to read */ 00321 /************************************************************* 00322 Writes a ulint in the little-endian format. */ 00323 UNIV_INLINE 00324 void 00325 mach_write_to_2_little_endian( 00326 /*==========================*/ 00327 byte* dest, /* in: where to write */ 00328 ulint n); /* in: unsigned long int to write */ 00329 00330 #ifndef UNIV_NONINL 00331 #include "mach0data.ic" 00332 #endif 00333 00334 #endif
1.4.7

