~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

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