641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
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 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
19 |
/******************************************************************//**
|
20 |
@file mach/mach0data.c
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
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 |
#include "mach0data.h" |
|
28 |
||
29 |
#ifdef UNIV_NONINL
|
|
30 |
#include "mach0data.ic" |
|
31 |
#endif
|
|
32 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
33 |
/*********************************************************//**
|
34 |
Reads a ulint in a compressed form if the log record fully contains it.
|
|
35 |
@return pointer to end of the stored field, NULL if not complete */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
36 |
UNIV_INTERN
|
37 |
byte* |
|
38 |
mach_parse_compressed( |
|
39 |
/*==================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
40 |
byte* ptr, /*!< in: pointer to buffer from where to read */ |
41 |
byte* end_ptr,/*!< in: pointer to end of the buffer */ |
|
42 |
ulint* val) /*!< out: read value (< 2^32) */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
43 |
{
|
44 |
ulint flag; |
|
45 |
||
46 |
ut_ad(ptr && end_ptr && val); |
|
47 |
||
48 |
if (ptr >= end_ptr) { |
|
49 |
||
50 |
return(NULL); |
|
51 |
}
|
|
52 |
||
53 |
flag = mach_read_from_1(ptr); |
|
54 |
||
55 |
if (flag < 0x80UL) { |
|
56 |
*val = flag; |
|
57 |
return(ptr + 1); |
|
58 |
||
59 |
} else if (flag < 0xC0UL) { |
|
60 |
if (end_ptr < ptr + 2) { |
|
61 |
return(NULL); |
|
62 |
}
|
|
63 |
||
64 |
*val = mach_read_from_2(ptr) & 0x7FFFUL; |
|
65 |
||
66 |
return(ptr + 2); |
|
67 |
||
68 |
} else if (flag < 0xE0UL) { |
|
69 |
if (end_ptr < ptr + 3) { |
|
70 |
return(NULL); |
|
71 |
}
|
|
72 |
||
73 |
*val = mach_read_from_3(ptr) & 0x3FFFFFUL; |
|
74 |
||
75 |
return(ptr + 3); |
|
76 |
} else if (flag < 0xF0UL) { |
|
77 |
if (end_ptr < ptr + 4) { |
|
78 |
return(NULL); |
|
79 |
}
|
|
80 |
||
81 |
*val = mach_read_from_4(ptr) & 0x1FFFFFFFUL; |
|
82 |
||
83 |
return(ptr + 4); |
|
84 |
} else { |
|
85 |
ut_ad(flag == 0xF0UL); |
|
86 |
||
87 |
if (end_ptr < ptr + 5) { |
|
88 |
return(NULL); |
|
89 |
}
|
|
90 |
||
91 |
*val = mach_read_from_4(ptr + 1); |
|
92 |
return(ptr + 5); |
|
93 |
}
|
|
94 |
}
|
|
95 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
96 |
/*********************************************************//**
|
97 |
Reads a dulint in a compressed form if the log record fully contains it.
|
|
98 |
@return pointer to end of the stored field, NULL if not complete */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
99 |
UNIV_INTERN
|
100 |
byte* |
|
101 |
mach_dulint_parse_compressed( |
|
102 |
/*=========================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
103 |
byte* ptr, /*!< in: pointer to buffer from where to read */ |
104 |
byte* end_ptr,/*!< in: pointer to end of the buffer */ |
|
105 |
dulint* val) /*!< out: read value */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
106 |
{
|
107 |
ulint high; |
|
108 |
ulint low; |
|
109 |
ulint size; |
|
110 |
||
111 |
ut_ad(ptr && end_ptr && val); |
|
112 |
||
113 |
if (end_ptr < ptr + 5) { |
|
114 |
||
115 |
return(NULL); |
|
116 |
}
|
|
117 |
||
118 |
high = mach_read_compressed(ptr); |
|
119 |
||
120 |
size = mach_get_compressed_size(high); |
|
121 |
||
122 |
ptr += size; |
|
123 |
||
124 |
if (end_ptr < ptr + 4) { |
|
125 |
||
126 |
return(NULL); |
|
127 |
}
|
|
128 |
||
129 |
low = mach_read_from_4(ptr); |
|
130 |
||
131 |
*val = ut_dulint_create(high, low); |
|
132 |
||
133 |
return(ptr + 4); |
|
134 |
}
|