1
/*****************************************************************************
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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
17
*****************************************************************************/
19
/******************************************************************//**
20
@file include/mach0data.h
21
Utilities for converting data from the database file
22
to the machine format.
24
Created 11/28/1995 Heikki Tuuri
25
***********************************************************************/
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
38
/*******************************************************//**
39
The following function is used to store data in one byte. */
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 */
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. */
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 */
72
const byte* b) /*!< in: pointer to two bytes */
73
__attribute__((nonnull, pure));
75
/********************************************************//**
76
The following function is used to convert a 16-bit data item
77
to the canonical format, for fast bytewise equality test
79
@return 16-bit integer in canonical format */
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
90
@return integer in machine-dependent format */
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. */
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 */
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. */
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 */
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 */
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 */
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 */
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. */
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 */
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. */
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 */
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. */
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. */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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. */
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 */
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. */
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 */
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. */
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 */
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. */
378
mach_write_to_2_little_endian(
379
/*==========================*/
380
byte* dest, /*!< in: where to write */
381
ulint n); /*!< in: unsigned long int to write */
383
/*********************************************************//**
384
Convert integral type from storage byte order (big endian) to
386
@return integer value */
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 */
397
#include "mach0data.ic"