~drizzle-trunk/drizzle/development

641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
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
	const byte*	b)	/* in: pointer to byte */
37
	__attribute__((nonnull, pure));
38
/***********************************************************
39
The following function is used to store data in two consecutive
40
bytes. We store the most significant byte to the lower address. */
41
UNIV_INLINE
42
void
43
mach_write_to_2(
44
/*============*/
45
	byte*	b,	/* in: pointer to two bytes where to store */
46
	ulint	n);	 /* in: ulint integer to be stored, >= 0, < 64k */
47
/************************************************************
48
The following function is used to fetch data from two consecutive
49
bytes. The most significant byte is at the lowest address. */
50
UNIV_INLINE
51
ulint
52
mach_read_from_2(
53
/*=============*/
54
				/* out: ulint integer, >= 0, < 64k */
55
	const byte*	b)	/* in: pointer to two bytes */
56
	__attribute__((nonnull, pure));
57
58
/************************************************************
59
The following function is used to convert a 16-bit data item
60
to the canonical format, for fast bytewise equality test
61
against memory. */
62
UNIV_INLINE
63
uint16
64
mach_encode_2(
65
/*==========*/
66
			/* out: 16-bit integer in canonical format */
67
	ulint	n)	/* in: integer in machine-dependent format */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
68
	__attribute__((__const__));
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
69
/************************************************************
70
The following function is used to convert a 16-bit data item
71
from the canonical format, for fast bytewise equality test
72
against memory. */
73
UNIV_INLINE
74
ulint
75
mach_decode_2(
76
/*==========*/
77
			/* out: integer in machine-dependent format */
78
	uint16	n)	/* in: 16-bit integer in canonical format */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
79
	__attribute__((__const__));
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
80
/***********************************************************
81
The following function is used to store data in 3 consecutive
82
bytes. We store the most significant byte to the lowest address. */
83
UNIV_INLINE
84
void
85
mach_write_to_3(
86
/*============*/
87
	byte*	b,	/* in: pointer to 3 bytes where to store */
88
	ulint	n);	 /* in: ulint integer to be stored */
89
/************************************************************
90
The following function is used to fetch data from 3 consecutive
91
bytes. The most significant byte is at the lowest address. */
92
UNIV_INLINE
93
ulint
94
mach_read_from_3(
95
/*=============*/
96
				/* out: ulint integer */
97
	const byte*	b)	/* in: pointer to 3 bytes */
98
	__attribute__((nonnull, pure));
99
/***********************************************************
100
The following function is used to store data in four consecutive
101
bytes. We store the most significant byte to the lowest address. */
102
UNIV_INLINE
103
void
104
mach_write_to_4(
105
/*============*/
106
	byte*	b,	/* in: pointer to four bytes where to store */
107
	ulint	n);	 /* in: ulint integer to be stored */
108
/************************************************************
109
The following function is used to fetch data from 4 consecutive
110
bytes. The most significant byte is at the lowest address. */
111
UNIV_INLINE
112
ulint
113
mach_read_from_4(
114
/*=============*/
115
				/* out: ulint integer */
116
	const byte*	b)	/* in: pointer to four bytes */
117
	__attribute__((nonnull, pure));
118
/*************************************************************
119
Writes a ulint in a compressed form (1..5 bytes). */
120
UNIV_INLINE
121
ulint
122
mach_write_compressed(
123
/*==================*/
124
			/* out: stored size in bytes */
125
	byte*	b,	/* in: pointer to memory where to store */
126
	ulint	n);	/* in: ulint integer to be stored */
127
/*************************************************************
128
Returns the size of an ulint when written in the compressed form. */
129
UNIV_INLINE
130
ulint
131
mach_get_compressed_size(
132
/*=====================*/
133
			/* out: compressed size in bytes */
134
	ulint	n)	/* in: ulint integer to be stored */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
135
	__attribute__((__const__));
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
136
/*************************************************************
137
Reads a ulint in a compressed form. */
138
UNIV_INLINE
139
ulint
140
mach_read_compressed(
141
/*=================*/
142
				/* out: read integer */
143
	const byte*	b)	/* in: pointer to memory from where to read */
144
	__attribute__((nonnull, pure));
145
/***********************************************************
146
The following function is used to store data in 6 consecutive
147
bytes. We store the most significant byte to the lowest address. */
148
UNIV_INLINE
149
void
150
mach_write_to_6(
151
/*============*/
152
	byte*	b,	/* in: pointer to 6 bytes where to store */
153
	dulint	n);	 /* in: dulint integer to be stored */
154
/************************************************************
155
The following function is used to fetch data from 6 consecutive
156
bytes. The most significant byte is at the lowest address. */
157
UNIV_INLINE
158
dulint
159
mach_read_from_6(
160
/*=============*/
161
				/* out: dulint integer */
162
	const byte*	b)	/* in: pointer to 6 bytes */
163
	__attribute__((nonnull, pure));
164
/***********************************************************
165
The following function is used to store data in 7 consecutive
166
bytes. We store the most significant byte to the lowest address. */
167
UNIV_INLINE
168
void
169
mach_write_to_7(
170
/*============*/
171
	byte*	b,	/* in: pointer to 7 bytes where to store */
172
	dulint	n);	 /* in: dulint integer to be stored */
173
/************************************************************
174
The following function is used to fetch data from 7 consecutive
175
bytes. The most significant byte is at the lowest address. */
176
UNIV_INLINE
177
dulint
178
mach_read_from_7(
179
/*=============*/
180
				/* out: dulint integer */
181
	const byte*	b)	/* in: pointer to 7 bytes */
182
	__attribute__((nonnull, pure));
183
/***********************************************************
184
The following function is used to store data in 8 consecutive
185
bytes. We store the most significant byte to the lowest address. */
186
UNIV_INLINE
187
void
188
mach_write_to_8(
189
/*============*/
190
	byte*	b,	/* in: pointer to 8 bytes where to store */
191
	dulint	n);	/* in: dulint integer to be stored */
192
/***********************************************************
193
The following function is used to store data in 8 consecutive
194
bytes. We store the most significant byte to the lowest address. */
195
UNIV_INLINE
196
void
197
mach_write_ull(
198
/*===========*/
199
	byte*		b,	/* in: pointer to 8 bytes where to store */
200
	ib_uint64_t	n);	/* in: 64-bit integer to be stored */
201
/************************************************************
202
The following function is used to fetch data from 8 consecutive
203
bytes. The most significant byte is at the lowest address. */
204
UNIV_INLINE
205
dulint
206
mach_read_from_8(
207
/*=============*/
208
				/* out: dulint integer */
209
	const byte*	b)	/* in: pointer to 8 bytes */
210
	__attribute__((nonnull, pure));
211
/************************************************************
212
The following function is used to fetch data from 8 consecutive
213
bytes. The most significant byte is at the lowest address. */
214
UNIV_INLINE
215
ib_uint64_t
216
mach_read_ull(
217
/*==========*/
218
				/* out: 64-bit integer */
219
	const byte*	b)	/* in: pointer to 8 bytes */
220
	__attribute__((nonnull, pure));
221
/*************************************************************
222
Writes a dulint in a compressed form (5..9 bytes). */
223
UNIV_INLINE
224
ulint
225
mach_dulint_write_compressed(
226
/*=========================*/
227
			/* out: size in bytes */
228
	byte*	b,	/* in: pointer to memory where to store */
229
	dulint	n);	/* in: dulint integer to be stored */
230
/*************************************************************
231
Returns the size of a dulint when written in the compressed form. */
232
UNIV_INLINE
233
ulint
234
mach_dulint_get_compressed_size(
235
/*============================*/
236
			/* out: compressed size in bytes */
237
	dulint	 n);	/* in: dulint integer to be stored */
238
/*************************************************************
239
Reads a dulint in a compressed form. */
240
UNIV_INLINE
241
dulint
242
mach_dulint_read_compressed(
243
/*========================*/
244
				/* out: read dulint */
245
	const byte*	b)	/* in: pointer to memory from where to read */
246
	__attribute__((nonnull, pure));
247
/*************************************************************
248
Writes a dulint in a compressed form (1..11 bytes). */
249
UNIV_INLINE
250
ulint
251
mach_dulint_write_much_compressed(
252
/*==============================*/
253
			/* out: size in bytes */
254
	byte*	b,	/* in: pointer to memory where to store */
255
	dulint	n);	/* in: dulint integer to be stored */
256
/*************************************************************
257
Returns the size of a dulint when written in the compressed form. */
258
UNIV_INLINE
259
ulint
260
mach_dulint_get_much_compressed_size(
261
/*=================================*/
262
			/* out: compressed size in bytes */
263
	dulint	 n)	 /* in: dulint integer to be stored */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
264
	__attribute__((__const__));
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
265
/*************************************************************
266
Reads a dulint in a compressed form. */
267
UNIV_INLINE
268
dulint
269
mach_dulint_read_much_compressed(
270
/*=============================*/
271
				/* out: read dulint */
272
	const byte*	b)	/* in: pointer to memory from where to read */
273
	__attribute__((nonnull, pure));
274
/*************************************************************
275
Reads a ulint in a compressed form if the log record fully contains it. */
276
UNIV_INTERN
277
byte*
278
mach_parse_compressed(
279
/*==================*/
280
			/* out: pointer to end of the stored field, NULL if
281
			not complete */
282
	byte*	ptr,	/* in: pointer to buffer from where to read */
283
	byte*	end_ptr,/* in: pointer to end of the buffer */
284
	ulint*	val);	/* out: read value */
285
/*************************************************************
286
Reads a dulint in a compressed form if the log record fully contains it. */
287
UNIV_INTERN
288
byte*
289
mach_dulint_parse_compressed(
290
/*=========================*/
291
			/* out: pointer to end of the stored field, NULL if
292
			not complete */
293
	byte*	ptr,	/* in: pointer to buffer from where to read */
294
	byte*	end_ptr,/* in: pointer to end of the buffer */
295
	dulint*	val);	/* out: read value */
296
/*************************************************************
297
Reads a double. It is stored in a little-endian format. */
298
UNIV_INLINE
299
double
300
mach_double_read(
301
/*=============*/
302
				/* out: double read */
303
	const byte*	b)	/* in: pointer to memory from where to read */
304
	__attribute__((nonnull, pure));
305
/*************************************************************
306
Writes a double. It is stored in a little-endian format. */
307
UNIV_INLINE
308
void
309
mach_double_write(
310
/*==============*/
311
	byte*	b,	/* in: pointer to memory where to write */
312
	double	d);	/* in: double */
313
/*************************************************************
314
Reads a float. It is stored in a little-endian format. */
315
UNIV_INLINE
316
float
317
mach_float_read(
318
/*============*/
319
				/* out: float read */
320
	const byte*	b)	/* in: pointer to memory from where to read */
321
	__attribute__((nonnull, pure));
322
/*************************************************************
323
Writes a float. It is stored in a little-endian format. */
324
UNIV_INLINE
325
void
326
mach_float_write(
327
/*=============*/
328
	byte*	b,	/* in: pointer to memory where to write */
329
	float	d);	/* in: float */
330
/*************************************************************
331
Reads a ulint stored in the little-endian format. */
332
UNIV_INLINE
333
ulint
334
mach_read_from_n_little_endian(
335
/*===========================*/
336
					/* out: unsigned long int */
337
	const byte*	buf,		/* in: from where to read */
338
	ulint		buf_size)	/* in: from how many bytes to read */
339
	__attribute__((nonnull, pure));
340
/*************************************************************
341
Writes a ulint in the little-endian format. */
342
UNIV_INLINE
343
void
344
mach_write_to_n_little_endian(
345
/*==========================*/
346
	byte*	dest,		/* in: where to write */
347
	ulint	dest_size,	/* in: into how many bytes to write */
348
	ulint	n);		/* in: unsigned long int to write */
349
/*************************************************************
350
Reads a ulint stored in the little-endian format. */
351
UNIV_INLINE
352
ulint
353
mach_read_from_2_little_endian(
354
/*===========================*/
355
					/* out: unsigned long int */
356
	const byte*	buf)		/* in: from where to read */
357
	__attribute__((nonnull, pure));
358
/*************************************************************
359
Writes a ulint in the little-endian format. */
360
UNIV_INLINE
361
void
362
mach_write_to_2_little_endian(
363
/*==========================*/
364
	byte*	dest,		/* in: where to write */
365
	ulint	n);		/* in: unsigned long int to write */
366
367
/*************************************************************
368
Convert integral type from storage byte order (big endian) to
369
host byte order. */
370
UNIV_INLINE
371
ullint
372
mach_read_int_type(
373
/*===============*/
374
					/* out: integer value */
375
	const byte*	src,		/* in: where to read from */
376
	ulint		len,		/* in: length of src */
377
	ibool		unsigned_type);	/* in: signed or unsigned flag */
378
#ifndef UNIV_NONINL
379
#include "mach0data.ic"
380
#endif
381
382
#endif