~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/mach0data.h

  • Committer: Monty Taylor
  • Date: 2009-04-25 20:45:19 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 1003.
  • Revision ID: mordred@inaugust.com-20090425204519-lgrl7mz2r66v0jby
Blackhole.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/******************************************************************//**
20
 
@file include/mach0data.h
21
 
Utilities for converting data from the database file
22
 
to the machine format.
23
 
 
24
 
Created 11/28/1995 Heikki Tuuri
25
 
***********************************************************************/
26
 
 
27
 
#ifndef mach0data_h
28
 
#define mach0data_h
29
 
 
30
 
#include "univ.i"
31
 
#include "ut0byte.h"
32
 
 
33
 
/* The data and all fields are always stored in a database file
34
 
in the same format: ascii, big-endian, ... .
35
 
All data in the files MUST be accessed using the functions in this
36
 
module. */
37
 
 
38
 
/*******************************************************//**
39
 
The following function is used to store data in one byte. */
40
 
UNIV_INLINE
41
 
void
42
 
mach_write_to_1(
43
 
/*============*/
44
 
        byte*   b,      /*!< in: pointer to byte where to store */
45
 
        ulint   n);      /*!< in: ulint integer to be stored, >= 0, < 256 */
46
 
/********************************************************//**
47
 
The following function is used to fetch data from one byte.
48
 
@return ulint integer, >= 0, < 256 */
49
 
UNIV_INLINE
50
 
ulint
51
 
mach_read_from_1(
52
 
/*=============*/
53
 
        const byte*     b)      /*!< in: pointer to byte */
54
 
        __attribute__((nonnull, pure));
55
 
/*******************************************************//**
56
 
The following function is used to store data in two consecutive
57
 
bytes. We store the most significant byte to the lower address. */
58
 
UNIV_INLINE
59
 
void
60
 
mach_write_to_2(
61
 
/*============*/
62
 
        byte*   b,      /*!< in: pointer to two bytes where to store */
63
 
        ulint   n);      /*!< in: ulint integer to be stored, >= 0, < 64k */
64
 
/********************************************************//**
65
 
The following function is used to fetch data from two consecutive
66
 
bytes. The most significant byte is at the lowest address.
67
 
@return ulint integer, >= 0, < 64k */
68
 
UNIV_INLINE
69
 
ulint
70
 
mach_read_from_2(
71
 
/*=============*/
72
 
        const byte*     b)      /*!< in: pointer to two bytes */
73
 
        __attribute__((nonnull, pure));
74
 
 
75
 
/********************************************************//**
76
 
The following function is used to convert a 16-bit data item
77
 
to the canonical format, for fast bytewise equality test
78
 
against memory.
79
 
@return 16-bit integer in canonical format */
80
 
UNIV_INLINE
81
 
uint16
82
 
mach_encode_2(
83
 
/*==========*/
84
 
        ulint   n)      /*!< in: integer in machine-dependent format */
85
 
        __attribute__((const));
86
 
/********************************************************//**
87
 
The following function is used to convert a 16-bit data item
88
 
from the canonical format, for fast bytewise equality test
89
 
against memory.
90
 
@return integer in machine-dependent format */
91
 
UNIV_INLINE
92
 
ulint
93
 
mach_decode_2(
94
 
/*==========*/
95
 
        uint16  n)      /*!< in: 16-bit integer in canonical format */
96
 
        __attribute__((const));
97
 
/*******************************************************//**
98
 
The following function is used to store data in 3 consecutive
99
 
bytes. We store the most significant byte to the lowest address. */
100
 
UNIV_INLINE
101
 
void
102
 
mach_write_to_3(
103
 
/*============*/
104
 
        byte*   b,      /*!< in: pointer to 3 bytes where to store */
105
 
        ulint   n);      /*!< in: ulint integer to be stored */
106
 
/********************************************************//**
107
 
The following function is used to fetch data from 3 consecutive
108
 
bytes. The most significant byte is at the lowest address.
109
 
@return ulint integer */
110
 
UNIV_INLINE
111
 
ulint
112
 
mach_read_from_3(
113
 
/*=============*/
114
 
        const byte*     b)      /*!< in: pointer to 3 bytes */
115
 
        __attribute__((nonnull, pure));
116
 
/*******************************************************//**
117
 
The following function is used to store data in four consecutive
118
 
bytes. We store the most significant byte to the lowest address. */
119
 
UNIV_INLINE
120
 
void
121
 
mach_write_to_4(
122
 
/*============*/
123
 
        byte*   b,      /*!< in: pointer to four bytes where to store */
124
 
        ulint   n);      /*!< in: ulint integer to be stored */
125
 
/********************************************************//**
126
 
The following function is used to fetch data from 4 consecutive
127
 
bytes. The most significant byte is at the lowest address.
128
 
@return ulint integer */
129
 
UNIV_INLINE
130
 
ulint
131
 
mach_read_from_4(
132
 
/*=============*/
133
 
        const byte*     b)      /*!< in: pointer to four bytes */
134
 
        __attribute__((nonnull, pure));
135
 
/*********************************************************//**
136
 
Writes a ulint in a compressed form (1..5 bytes).
137
 
@return stored size in bytes */
138
 
UNIV_INLINE
139
 
ulint
140
 
mach_write_compressed(
141
 
/*==================*/
142
 
        byte*   b,      /*!< in: pointer to memory where to store */
143
 
        ulint   n);     /*!< in: ulint integer to be stored */
144
 
/*********************************************************//**
145
 
Returns the size of an ulint when written in the compressed form.
146
 
@return compressed size in bytes */
147
 
UNIV_INLINE
148
 
ulint
149
 
mach_get_compressed_size(
150
 
/*=====================*/
151
 
        ulint   n)      /*!< in: ulint integer to be stored */
152
 
        __attribute__((const));
153
 
/*********************************************************//**
154
 
Reads a ulint in a compressed form.
155
 
@return read integer */
156
 
UNIV_INLINE
157
 
ulint
158
 
mach_read_compressed(
159
 
/*=================*/
160
 
        const byte*     b)      /*!< in: pointer to memory from where to read */
161
 
        __attribute__((nonnull, pure));
162
 
/*******************************************************//**
163
 
The following function is used to store data in 6 consecutive
164
 
bytes. We store the most significant byte to the lowest address. */
165
 
UNIV_INLINE
166
 
void
167
 
mach_write_to_6(
168
 
/*============*/
169
 
        byte*   b,      /*!< in: pointer to 6 bytes where to store */
170
 
        dulint  n);      /*!< in: dulint integer to be stored */
171
 
/********************************************************//**
172
 
The following function is used to fetch data from 6 consecutive
173
 
bytes. The most significant byte is at the lowest address.
174
 
@return dulint integer */
175
 
UNIV_INLINE
176
 
dulint
177
 
mach_read_from_6(
178
 
/*=============*/
179
 
        const byte*     b)      /*!< in: pointer to 6 bytes */
180
 
        __attribute__((nonnull, pure));
181
 
/*******************************************************//**
182
 
The following function is used to store data in 7 consecutive
183
 
bytes. We store the most significant byte to the lowest address. */
184
 
UNIV_INLINE
185
 
void
186
 
mach_write_to_7(
187
 
/*============*/
188
 
        byte*   b,      /*!< in: pointer to 7 bytes where to store */
189
 
        dulint  n);      /*!< in: dulint integer to be stored */
190
 
/********************************************************//**
191
 
The following function is used to fetch data from 7 consecutive
192
 
bytes. The most significant byte is at the lowest address.
193
 
@return dulint integer */
194
 
UNIV_INLINE
195
 
dulint
196
 
mach_read_from_7(
197
 
/*=============*/
198
 
        const byte*     b)      /*!< in: pointer to 7 bytes */
199
 
        __attribute__((nonnull, pure));
200
 
/*******************************************************//**
201
 
The following function is used to store data in 8 consecutive
202
 
bytes. We store the most significant byte to the lowest address. */
203
 
UNIV_INLINE
204
 
void
205
 
mach_write_to_8(
206
 
/*============*/
207
 
        byte*   b,      /*!< in: pointer to 8 bytes where to store */
208
 
        dulint  n);     /*!< in: dulint integer to be stored */
209
 
/*******************************************************//**
210
 
The following function is used to store data in 8 consecutive
211
 
bytes. We store the most significant byte to the lowest address. */
212
 
UNIV_INLINE
213
 
void
214
 
mach_write_ull(
215
 
/*===========*/
216
 
        byte*           b,      /*!< in: pointer to 8 bytes where to store */
217
 
        ib_uint64_t     n);     /*!< in: 64-bit integer to be stored */
218
 
/********************************************************//**
219
 
The following function is used to fetch data from 8 consecutive
220
 
bytes. The most significant byte is at the lowest address.
221
 
@return dulint integer */
222
 
UNIV_INLINE
223
 
dulint
224
 
mach_read_from_8(
225
 
/*=============*/
226
 
        const byte*     b)      /*!< in: pointer to 8 bytes */
227
 
        __attribute__((nonnull, pure));
228
 
/********************************************************//**
229
 
The following function is used to fetch data from 8 consecutive
230
 
bytes. The most significant byte is at the lowest address.
231
 
@return 64-bit integer */
232
 
UNIV_INLINE
233
 
ib_uint64_t
234
 
mach_read_ull(
235
 
/*==========*/
236
 
        const byte*     b)      /*!< in: pointer to 8 bytes */
237
 
        __attribute__((nonnull, pure));
238
 
/*********************************************************//**
239
 
Writes a dulint in a compressed form (5..9 bytes).
240
 
@return size in bytes */
241
 
UNIV_INLINE
242
 
ulint
243
 
mach_dulint_write_compressed(
244
 
/*=========================*/
245
 
        byte*   b,      /*!< in: pointer to memory where to store */
246
 
        dulint  n);     /*!< in: dulint integer to be stored */
247
 
/*********************************************************//**
248
 
Returns the size of a dulint when written in the compressed form.
249
 
@return compressed size in bytes */
250
 
UNIV_INLINE
251
 
ulint
252
 
mach_dulint_get_compressed_size(
253
 
/*============================*/
254
 
        dulint   n);    /*!< in: dulint integer to be stored */
255
 
/*********************************************************//**
256
 
Reads a dulint in a compressed form.
257
 
@return read dulint */
258
 
UNIV_INLINE
259
 
dulint
260
 
mach_dulint_read_compressed(
261
 
/*========================*/
262
 
        const byte*     b)      /*!< in: pointer to memory from where to read */
263
 
        __attribute__((nonnull, pure));
264
 
/*********************************************************//**
265
 
Writes a dulint in a compressed form (1..11 bytes).
266
 
@return size in bytes */
267
 
UNIV_INLINE
268
 
ulint
269
 
mach_dulint_write_much_compressed(
270
 
/*==============================*/
271
 
        byte*   b,      /*!< in: pointer to memory where to store */
272
 
        dulint  n);     /*!< in: dulint integer to be stored */
273
 
/*********************************************************//**
274
 
Returns the size of a dulint when written in the compressed form.
275
 
@return compressed size in bytes */
276
 
UNIV_INLINE
277
 
ulint
278
 
mach_dulint_get_much_compressed_size(
279
 
/*=================================*/
280
 
        dulint   n)      /*!< in: dulint integer to be stored */
281
 
        __attribute__((const));
282
 
/*********************************************************//**
283
 
Reads a dulint in a compressed form.
284
 
@return read dulint */
285
 
UNIV_INLINE
286
 
dulint
287
 
mach_dulint_read_much_compressed(
288
 
/*=============================*/
289
 
        const byte*     b)      /*!< in: pointer to memory from where to read */
290
 
        __attribute__((nonnull, pure));
291
 
/*********************************************************//**
292
 
Reads a ulint in a compressed form if the log record fully contains it.
293
 
@return pointer to end of the stored field, NULL if not complete */
294
 
UNIV_INTERN
295
 
byte*
296
 
mach_parse_compressed(
297
 
/*==================*/
298
 
        byte*   ptr,    /*!< in: pointer to buffer from where to read */
299
 
        byte*   end_ptr,/*!< in: pointer to end of the buffer */
300
 
        ulint*  val);   /*!< out: read value */
301
 
/*********************************************************//**
302
 
Reads a dulint in a compressed form if the log record fully contains it.
303
 
@return pointer to end of the stored field, NULL if not complete */
304
 
UNIV_INTERN
305
 
byte*
306
 
mach_dulint_parse_compressed(
307
 
/*=========================*/
308
 
        byte*   ptr,    /*!< in: pointer to buffer from where to read */
309
 
        byte*   end_ptr,/*!< in: pointer to end of the buffer */
310
 
        dulint* val);   /*!< out: read value */
311
 
#ifndef UNIV_HOTBACKUP
312
 
/*********************************************************//**
313
 
Reads a double. It is stored in a little-endian format.
314
 
@return double read */
315
 
UNIV_INLINE
316
 
double
317
 
mach_double_read(
318
 
/*=============*/
319
 
        const byte*     b)      /*!< in: pointer to memory from where to read */
320
 
        __attribute__((nonnull, pure));
321
 
/*********************************************************//**
322
 
Writes a double. It is stored in a little-endian format. */
323
 
UNIV_INLINE
324
 
void
325
 
mach_double_write(
326
 
/*==============*/
327
 
        byte*   b,      /*!< in: pointer to memory where to write */
328
 
        double  d);     /*!< in: double */
329
 
/*********************************************************//**
330
 
Reads a float. It is stored in a little-endian format.
331
 
@return float read */
332
 
UNIV_INLINE
333
 
float
334
 
mach_float_read(
335
 
/*============*/
336
 
        const byte*     b)      /*!< in: pointer to memory from where to read */
337
 
        __attribute__((nonnull, pure));
338
 
/*********************************************************//**
339
 
Writes a float. It is stored in a little-endian format. */
340
 
UNIV_INLINE
341
 
void
342
 
mach_float_write(
343
 
/*=============*/
344
 
        byte*   b,      /*!< in: pointer to memory where to write */
345
 
        float   d);     /*!< in: float */
346
 
/*********************************************************//**
347
 
Reads a ulint stored in the little-endian format.
348
 
@return unsigned long int */
349
 
UNIV_INLINE
350
 
ulint
351
 
mach_read_from_n_little_endian(
352
 
/*===========================*/
353
 
        const byte*     buf,            /*!< in: from where to read */
354
 
        ulint           buf_size)       /*!< in: from how many bytes to read */
355
 
        __attribute__((nonnull, pure));
356
 
/*********************************************************//**
357
 
Writes a ulint in the little-endian format. */
358
 
UNIV_INLINE
359
 
void
360
 
mach_write_to_n_little_endian(
361
 
/*==========================*/
362
 
        byte*   dest,           /*!< in: where to write */
363
 
        ulint   dest_size,      /*!< in: into how many bytes to write */
364
 
        ulint   n);             /*!< in: unsigned long int to write */
365
 
/*********************************************************//**
366
 
Reads a ulint stored in the little-endian format.
367
 
@return unsigned long int */
368
 
UNIV_INLINE
369
 
ulint
370
 
mach_read_from_2_little_endian(
371
 
/*===========================*/
372
 
        const byte*     buf)            /*!< in: from where to read */
373
 
        __attribute__((nonnull, pure));
374
 
/*********************************************************//**
375
 
Writes a ulint in the little-endian format. */
376
 
UNIV_INLINE
377
 
void
378
 
mach_write_to_2_little_endian(
379
 
/*==========================*/
380
 
        byte*   dest,           /*!< in: where to write */
381
 
        ulint   n);             /*!< in: unsigned long int to write */
382
 
 
383
 
/*********************************************************//**
384
 
Convert integral type from storage byte order (big endian) to
385
 
host byte order.
386
 
@return integer value */
387
 
UNIV_INLINE
388
 
ullint
389
 
mach_read_int_type(
390
 
/*===============*/
391
 
        const byte*     src,            /*!< in: where to read from */
392
 
        ulint           len,            /*!< in: length of src */
393
 
        ibool           unsigned_type); /*!< in: signed or unsigned flag */
394
 
#endif /* !UNIV_HOTBACKUP */
395
 
 
396
 
#ifndef UNIV_NONINL
397
 
#include "mach0data.ic"
398
 
#endif
399
 
 
400
 
#endif