1
/**********************************************************************
2
Utilities for converting data from the database file
7
Created 11/28/1995 Heikki Tuuri
8
***********************************************************************/
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
21
/***********************************************************
22
The following function is used to store data in one byte. */
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. */
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. */
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. */
53
/* out: ulint integer, >= 0, < 64k */
54
byte* b); /* in: pointer to two bytes */
56
/************************************************************
57
The following function is used to convert a 16-bit data item
58
to the canonical format, for fast bytewise equality test
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
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. */
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. */
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. */
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. */
110
/* out: ulint integer */
111
byte* b); /* in: pointer to four bytes */
112
/*************************************************************
113
Writes a ulint in a compressed form (1..5 bytes). */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
189
/* out: dulint integer */
190
byte* b); /* in: pointer to 8 bytes */
191
/*************************************************************
192
Writes a dulint in a compressed form (5..9 bytes). */
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. */
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. */
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). */
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. */
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. */
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. */
245
mach_parse_compressed(
246
/*==================*/
247
/* out: pointer to end of the stored field, NULL if
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. */
256
mach_dulint_parse_compressed(
257
/*=========================*/
258
/* out: pointer to end of the stored field, NULL if
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
325
mach_write_to_2_little_endian(
326
/*==========================*/
327
byte* dest, /* in: where to write */
328
ulint n); /* in: unsigned long int to write */
330
/*************************************************************
331
Convert integral type from storage byte order (big endian) to
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 */
342
#include "mach0data.ic"