MySQL  8.0.19
Source Code Documentation
mach0data.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2018, Oracle and/or its affiliates. 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, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/mach0data.h
28  Utilities for converting data from the database file
29  to the machine format.
30 
31  Created 11/28/1995 Heikki Tuuri
32  ***********************************************************************/
33 
34 #ifndef mach0data_h
35 #define mach0data_h
36 
37 #include "mtr0types.h"
38 #include "univ.i"
39 
40 #ifdef UNIV_HOTBACKUP
41 #include "ut0byte.h"
42 #endif /* UNIV_HOTBACKUP */
43 
44 /* The data and all fields are always stored in a database file
45 in the same format: ascii, big-endian, ... .
46 All data in the files MUST be accessed using the functions in this
47 module. */
48 
49 /** The following function is used to store data in one byte.
50 @param[in] b pointer to byte where to store
51 @param[in] n One byte integer to be stored, >= 0, < 256 */
52 UNIV_INLINE
53 void mach_write_to_1(byte *b, ulint n);
54 
55 /** The following function is used to fetch data from one byte.
56 @param[in] b pointer to a byte to read
57 @return ulint integer, >= 0, < 256 */
58 UNIV_INLINE
59 uint8_t mach_read_from_1(const byte *b) MY_ATTRIBUTE((warn_unused_result));
60 
61 /** The following function is used to store data in two consecutive bytes. We
62 store the most significant byte to the lower address.
63 @param[in] b pointer to 2 bytes where to store
64 @param[in] n 2-byte integer to be stored, >= 0, < 64k */
65 UNIV_INLINE
66 void mach_write_to_2(byte *b, ulint n);
67 
68 /** The following function is used to fetch data from 2 consecutive
69 bytes. The most significant byte is at the lowest address.
70 @param[in] b pointer to 2 bytes where to store
71 @return 2-byte integer, >= 0, < 64k */
72 UNIV_INLINE
73 uint16_t mach_read_from_2(const byte *b) MY_ATTRIBUTE((warn_unused_result));
74 
75 /** The following function is used to convert a 16-bit data item
76  to the canonical format, for fast bytewise equality test
77  against memory.
78  @return 16-bit integer in canonical format */
79 UNIV_INLINE
80 uint16_t mach_encode_2(ulint n) /*!< in: integer in machine-dependent format */
81  MY_ATTRIBUTE((const));
82 /** The following function is used to convert a 16-bit data item
83  from the canonical format, for fast bytewise equality test
84  against memory.
85  @return integer in machine-dependent format */
86 UNIV_INLINE
87 ulint mach_decode_2(uint16 n) /*!< in: 16-bit integer in canonical format */
88  MY_ATTRIBUTE((const));
89 
90 /** The following function is used to store data in 3 consecutive
91 bytes. We store the most significant byte to the lowest address.
92 @param[in] b pointer to 3 bytes where to store
93 @param[in] n 3 byte integer to be stored */
94 UNIV_INLINE
95 void mach_write_to_3(byte *b, ulint n);
96 
97 /** The following function is used to fetch data from 3 consecutive
98 bytes. The most significant byte is at the lowest address.
99 @param[in] b pointer to 3 bytes to read
100 @return 32 bit integer */
101 UNIV_INLINE
102 uint32_t mach_read_from_3(const byte *b) MY_ATTRIBUTE((warn_unused_result));
103 
104 /** The following function is used to store data in 4 consecutive
105 bytes. We store the most significant byte to the lowest address.
106 @param[in] b pointer to 4 bytes where to store
107 @param[in] n 4 byte integer to be stored */
108 UNIV_INLINE
109 void mach_write_to_4(byte *b, ulint n);
110 
111 /** The following function is used to fetch data from 4 consecutive
112 bytes. The most significant byte is at the lowest address.
113 @param[in] b pointer to 4 bytes to read
114 @return 32 bit integer */
115 UNIV_INLINE
116 uint32_t mach_read_from_4(const byte *b) MY_ATTRIBUTE((warn_unused_result));
117 
118 /** Write a ulint in a compressed form (1..5 bytes).
119 @param[in] b pointer to memory where to store
120 @param[in] n ulint integer to be stored
121 @return stored size in bytes */
122 UNIV_INLINE
123 ulint mach_write_compressed(byte *b, ulint n);
124 
125 /** Return the size of an ulint when written in the compressed form.
126 @param[in] n ulint integer to be stored
127 @return compressed size in bytes */
128 UNIV_INLINE
129 ulint mach_get_compressed_size(ulint n) MY_ATTRIBUTE((const));
130 
131 /** Read a 32-bit integer in a compressed form.
132 @param[in,out] b pointer to memory where to read;
133 advanced by the number of bytes consumed
134 @return unsigned value */
135 UNIV_INLINE
136 ib_uint32_t mach_read_next_compressed(const byte **b);
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 @param[in] b pointer to 6 bytes where to store
141 @param[in] id 48-bit integer to write */
142 UNIV_INLINE
143 void mach_write_to_6(byte *b, ib_uint64_t id);
144 
145 /** The following function is used to fetch data from 6 consecutive
146 bytes. The most significant byte is at the lowest address.
147 @param[in] b pointer to 6 bytes to read
148 @return 48-bit integer */
149 UNIV_INLINE
150 ib_uint64_t mach_read_from_6(const byte *b) MY_ATTRIBUTE((warn_unused_result));
151 
152 /** The following function is used to store data in 7 consecutive
153 bytes. We store the most significant byte to the lowest address.
154 @param[in] b pointer to 7 bytes where to store
155 @param[in] n 56-bit integer */
156 UNIV_INLINE
157 void mach_write_to_7(byte *b, ib_uint64_t n);
158 
159 /** The following function is used to fetch data from 7 consecutive
160 bytes. The most significant byte is at the lowest address.
161 @param[in] b pointer to 7 bytes to read
162 @return 56-bit integer */
163 UNIV_INLINE
164 ib_uint64_t mach_read_from_7(const byte *b) MY_ATTRIBUTE((warn_unused_result));
165 
166 /** The following function is used to store data in 8 consecutive
167 bytes. We store the most significant byte to the lowest address.
168 @param[in] b pointer to 8 bytes where to store
169 @param[in] n 64-bit integer to be stored */
170 UNIV_INLINE
171 void mach_write_to_8(void *b, ib_uint64_t n);
172 
173 /** The following function is used to fetch data from 8 consecutive
174 bytes. The most significant byte is at the lowest address.
175 @param[in] b pointer to 8 bytes to read
176 @return 64-bit integer */
177 UNIV_INLINE
178 ib_uint64_t mach_read_from_8(const byte *b) MY_ATTRIBUTE((warn_unused_result));
179 
180 /** Writes a 64-bit integer in a compressed form (5..9 bytes).
181 @param[in] b pointer to memory where to store
182 @param[in] n 64-bit integer to be stored
183 @return size in bytes */
184 UNIV_INLINE
185 ulint mach_u64_write_compressed(byte *b, ib_uint64_t n);
186 
187 /** Read a 64-bit integer in a compressed form.
188 @param[in,out] b pointer to memory where to read;
189 advanced by the number of bytes consumed
190 @return unsigned value */
191 UNIV_INLINE
192 ib_uint64_t mach_u64_read_next_compressed(const byte **b);
193 
194 /** Writes a 64-bit integer in a compressed form (1..11 bytes).
195 @param[in] b pointer to memory where to store
196 @param[in] n 64-bit integer to be stored
197 @return size in bytes */
198 UNIV_INLINE
199 ulint mach_u64_write_much_compressed(byte *b, ib_uint64_t n);
200 
201 /** Reads a 64-bit integer in a compressed form.
202 @param[in] b pointer to memory from where to read
203 @return the value read */
204 UNIV_INLINE
205 ib_uint64_t mach_u64_read_much_compressed(const byte *b)
206  MY_ATTRIBUTE((warn_unused_result));
207 
208 /** Read a 64-bit integer in a much compressed form.
209 @param[in,out] ptr pointer to memory from where to read,
210 advanced by the number of bytes consumed, or set NULL if out of space
211 @param[in] end_ptr end of the buffer
212 @return unsigned 64-bit integer */
213 ib_uint64_t mach_parse_u64_much_compressed(const byte **ptr,
214  const byte *end_ptr);
215 
216 /** Read a 32-bit integer in a compressed form.
217 @param[in,out] ptr pointer to memory from where to read;
218 advanced by the number of bytes consumed, or set NULL if out of space
219 @param[in] end_ptr end of the buffer
220 @return unsigned value */
221 ib_uint32_t mach_parse_compressed(const byte **ptr, const byte *end_ptr);
222 /** Read a 64-bit integer in a compressed form.
223 @param[in,out] ptr pointer to memory from where to read;
224 advanced by the number of bytes consumed, or set NULL if out of space
225 @param[in] end_ptr end of the buffer
226 @return unsigned value */
227 UNIV_INLINE
228 ib_uint64_t mach_u64_parse_compressed(const byte **ptr, const byte *end_ptr);
229 
230 /** Reads a double. It is stored in a little-endian format.
231  @return double read */
232 UNIV_INLINE
233 double mach_double_read(
234  const byte *b) /*!< in: pointer to memory from where to read */
235  MY_ATTRIBUTE((warn_unused_result));
236 
237 /** Writes a double. It is stored in a little-endian format.
238 @param[in] b pointer to memory where to write
239 @param[in] d double */
240 UNIV_INLINE
241 void mach_double_write(byte *b, double d);
242 
243 /** Reads a float. It is stored in a little-endian format.
244  @return float read */
245 UNIV_INLINE
246 float mach_float_read(
247  const byte *b) /*!< in: pointer to memory from where to read */
248  MY_ATTRIBUTE((warn_unused_result));
249 
250 /** Writes a float. It is stored in a little-endian format.
251 @param[in] b pointer to memory where to write
252 @param[in] d float */
253 UNIV_INLINE
254 void mach_float_write(byte *b, float d);
255 
256 /** Reads a ulint stored in the little-endian format.
257  @return unsigned long int */
258 UNIV_INLINE
260  const byte *buf, /*!< in: from where to read */
261  ulint buf_size) /*!< in: from how many bytes to read */
262  MY_ATTRIBUTE((warn_unused_result));
263 
264 /** Writes a ulint in the little-endian format.
265 @param[in] dest where to write
266 @param[in] dest_size into how many bytes to write
267 @param[in] n unsigned long int to write */
268 UNIV_INLINE
269 void mach_write_to_n_little_endian(byte *dest, ulint dest_size, ulint n);
270 
271 /** Reads a ulint stored in the little-endian format.
272  @return unsigned long int */
273 UNIV_INLINE
275  const byte *buf) /*!< in: from where to read */
276  MY_ATTRIBUTE((warn_unused_result));
277 
278 /** Writes a ulint in the little-endian format.
279 @param[in] dest where to write
280 @param[in] n unsigned long int to write */
281 UNIV_INLINE
282 void mach_write_to_2_little_endian(byte *dest, ulint n);
283 
284 /** Convert integral type from storage byte order (big endian) to host byte
285 order.
286 @param[in] src where to read from
287 @param[in] len length of src
288 @param[in] unsigned_type signed or unsigned flag
289 @return integer value */
290 UNIV_INLINE
291 ib_uint64_t mach_read_int_type(const byte *src, ulint len, ibool unsigned_type);
292 
293 /** Convert integral type from host byte order to (big-endian) storage
294 byte order.
295 @param[in] dest where to write
296 @param[in] src where to read
297 @param[in] len length of src
298 @param[in] usign signed or unsigned flag */
299 UNIV_INLINE
300 void mach_write_int_type(byte *dest, const byte *src, ulint len, bool usign);
301 
302 /** Convert a ulonglong integer from host byte order to (big-endian) storage
303 byte order.
304 @param[in] dest where to write
305 @param[in] src where to read from
306 @param[in] len length of dest
307 @param[in] usign signed or unsigned flag */
308 UNIV_INLINE
309 void mach_write_ulonglong(byte *dest, ulonglong src, ulint len, bool usign);
310 
311 /** Read 1 to 4 bytes from a file page buffered in the buffer pool.
312 @param[in] ptr pointer where to read
313 @param[in] type MLOG_1BYTE, MLOG_2BYTES, or MLOG_4BYTES
314 @return value read */
315 UNIV_INLINE
316 uint32_t mach_read_ulint(const byte *ptr, mlog_id_t type)
317  MY_ATTRIBUTE((warn_unused_result));
318 
319 #include "mach0data.ic"
320 
321 #endif
mach_write_to_2_little_endian
UNIV_INLINE void mach_write_to_2_little_endian(byte *dest, ulint n)
Writes a ulint in the little-endian format.
mach_write_to_4
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
The following function is used to store data in 4 consecutive bytes.
mach_encode_2
UNIV_INLINE uint16_t mach_encode_2(ulint n)
The following function is used to convert a 16-bit data item to the canonical format,...
mach_write_to_3
UNIV_INLINE void mach_write_to_3(byte *b, ulint n)
The following function is used to store data in 3 consecutive bytes.
mach_get_compressed_size
UNIV_INLINE ulint mach_get_compressed_size(ulint n)
Return the size of an ulint when written in the compressed form.
mach_write_to_7
UNIV_INLINE void mach_write_to_7(byte *b, ib_uint64_t n)
The following function is used to store data in 7 consecutive bytes.
mach_read_from_1
UNIV_INLINE uint8_t mach_read_from_1(const byte *b)
The following function is used to fetch data from one byte.
mach_parse_compressed
ib_uint32_t mach_parse_compressed(const byte **ptr, const byte *end_ptr)
Read a 32-bit integer in a compressed form.
Definition: mach0data.cc:81
mach_double_write
UNIV_INLINE void mach_double_write(byte *b, double d)
Writes a double.
mach_float_read
UNIV_INLINE float mach_float_read(const byte *b)
Reads a float.
mach_u64_write_much_compressed
UNIV_INLINE ulint mach_u64_write_much_compressed(byte *b, ib_uint64_t n)
Writes a 64-bit integer in a compressed form (1..11 bytes).
mach_u64_write_compressed
UNIV_INLINE ulint mach_u64_write_compressed(byte *b, ib_uint64_t n)
Writes a 64-bit integer in a compressed form (5..9 bytes).
mach_read_next_compressed
UNIV_INLINE ib_uint32_t mach_read_next_compressed(const byte **b)
Read a 32-bit integer in a compressed form.
mach_read_from_2
UNIV_INLINE uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
mach_read_from_2_little_endian
UNIV_INLINE ulint mach_read_from_2_little_endian(const byte *buf)
Reads a ulint stored in the little-endian format.
mach_parse_u64_much_compressed
ib_uint64_t mach_parse_u64_much_compressed(const byte **ptr, const byte *end_ptr)
Read a 64-bit integer in a much compressed form.
Definition: mach0data.cc:44
mach_write_int_type
UNIV_INLINE void mach_write_int_type(byte *dest, const byte *src, ulint len, bool usign)
Convert integral type from host byte order to (big-endian) storage byte order.
mach_read_from_3
UNIV_INLINE uint32_t mach_read_from_3(const byte *b)
The following function is used to fetch data from 3 consecutive bytes.
mach_write_to_6
UNIV_INLINE void mach_write_to_6(byte *b, ib_uint64_t id)
The following function is used to store data in 6 consecutive bytes.
mach_write_to_1
UNIV_INLINE void mach_write_to_1(byte *b, ulint n)
The following function is used to store data in one byte.
mach_write_compressed
UNIV_INLINE ulint mach_write_compressed(byte *b, ulint n)
Write a ulint in a compressed form (1..5 bytes).
mach_write_to_2
UNIV_INLINE void mach_write_to_2(byte *b, ulint n)
The following function is used to store data in two consecutive bytes.
mach_read_from_4
UNIV_INLINE uint32_t mach_read_from_4(const byte *b)
The following function is used to fetch data from 4 consecutive bytes.
mach_write_ulonglong
UNIV_INLINE void mach_write_ulonglong(byte *dest, ulonglong src, ulint len, bool usign)
Convert a ulonglong integer from host byte order to (big-endian) storage byte order.
mach_read_from_6
UNIV_INLINE ib_uint64_t mach_read_from_6(const byte *b)
The following function is used to fetch data from 6 consecutive bytes.
mach_double_read
UNIV_INLINE double mach_double_read(const byte *b)
Reads a double.
mach_u64_read_next_compressed
UNIV_INLINE ib_uint64_t mach_u64_read_next_compressed(const byte **b)
Read a 64-bit integer in a compressed form.
mach_write_to_8
UNIV_INLINE void mach_write_to_8(void *b, ib_uint64_t n)
The following function is used to store data in 8 consecutive bytes.
mach_u64_read_much_compressed
UNIV_INLINE ib_uint64_t mach_u64_read_much_compressed(const byte *b)
Reads a 64-bit integer in a compressed form.
mach_read_from_8
UNIV_INLINE ib_uint64_t mach_read_from_8(const byte *b)
The following function is used to fetch data from 8 consecutive bytes.
mach_float_write
UNIV_INLINE void mach_float_write(byte *b, float d)
Writes a float.
HttpMethod::type
int type
Definition: http_common.h:411
mlog_id_t
mlog_id_t
Definition: mtr0types.h:59
mach_write_to_n_little_endian
UNIV_INLINE void mach_write_to_n_little_endian(byte *dest, ulint dest_size, ulint n)
Writes a ulint in the little-endian format.
uint16
uint16_t uint16
Definition: my_inttypes.h:64
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
mach_u64_parse_compressed
UNIV_INLINE ib_uint64_t mach_u64_parse_compressed(const byte **ptr, const byte *end_ptr)
Read a 64-bit integer in a compressed form.
n
int n
Definition: xcom_base.c:425
mach_decode_2
UNIV_INLINE ulint mach_decode_2(uint16 n)
The following function is used to convert a 16-bit data item from the canonical format,...
mach_read_ulint
UNIV_INLINE uint32_t mach_read_ulint(const byte *ptr, mlog_id_t type)
Read 1 to 4 bytes from a file page buffered in the buffer pool.
mach_read_from_n_little_endian
UNIV_INLINE ulint mach_read_from_n_little_endian(const byte *buf, ulint buf_size)
Reads a ulint stored in the little-endian format.
mtr0types.h
mach_read_int_type
UNIV_INLINE ib_uint64_t mach_read_int_type(const byte *src, ulint len, ibool unsigned_type)
Convert integral type from storage byte order (big endian) to host byte order.
mach_read_from_7
UNIV_INLINE ib_uint64_t mach_read_from_7(const byte *b)
The following function is used to fetch data from 7 consecutive bytes.
ut0byte.h