MySQL  8.0.22
Source Code Documentation
mach0data.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2020, 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 to the
76 canonical format, for fast bytewise equality test against memory.
77 @param[in] n integer in machine-dependent format
78 @return 16-bit integer in canonical format */
79 UNIV_INLINE
80 uint16_t mach_encode_2(ulint n);
81 
82 /** The following function is used to convert a 16-bit data item from the
83 canonical format, for fast bytewise equality test against memory.
84 @param[in] n 16-bit integer in canonical format
85 @return integer in machine-dependent format */
86 UNIV_INLINE
87 ulint mach_decode_2(uint16 n);
88 
89 /** The following function is used to store data in 3 consecutive
90 bytes. We store the most significant byte to the lowest address.
91 @param[in] b pointer to 3 bytes where to store
92 @param[in] n 3 byte integer to be stored */
93 UNIV_INLINE
94 void mach_write_to_3(byte *b, ulint n);
95 
96 /** The following function is used to fetch data from 3 consecutive
97 bytes. The most significant byte is at the lowest address.
98 @param[in] b pointer to 3 bytes to read
99 @return 32 bit integer */
100 UNIV_INLINE
101 uint32_t mach_read_from_3(const byte *b) MY_ATTRIBUTE((warn_unused_result));
102 
103 /** The following function is used to store data in 4 consecutive
104 bytes. We store the most significant byte to the lowest address.
105 @param[in] b pointer to 4 bytes where to store
106 @param[in] n 4 byte integer to be stored */
107 UNIV_INLINE
108 void mach_write_to_4(byte *b, ulint n);
109 
110 /** The following function is used to fetch data from 4 consecutive
111 bytes. The most significant byte is at the lowest address.
112 @param[in] b pointer to 4 bytes to read
113 @return 32 bit integer */
114 UNIV_INLINE
115 uint32_t mach_read_from_4(const byte *b) MY_ATTRIBUTE((warn_unused_result));
116 
117 /** Write a ulint in a compressed form (1..5 bytes).
118 @param[in] b pointer to memory where to store
119 @param[in] n ulint integer to be stored
120 @return stored size in bytes */
121 UNIV_INLINE
122 ulint mach_write_compressed(byte *b, ulint n);
123 
124 /** Return the size of an ulint when written in the compressed form.
125 @param[in] n ulint integer to be stored
126 @return compressed size in bytes */
127 UNIV_INLINE
128 uint32_t mach_get_compressed_size(ulint n);
129 
130 /** Read a 32-bit integer in a compressed form.
131 @param[in,out] b pointer to memory where to read;
132 advanced by the number of bytes consumed
133 @return unsigned value */
134 UNIV_INLINE
135 ib_uint32_t mach_read_next_compressed(const byte **b);
136 
137 /** The following function is used to store data in 6 consecutive
138 bytes. We store the most significant byte to the lowest address.
139 @param[in] b pointer to 6 bytes where to store
140 @param[in] id 48-bit integer to write */
141 UNIV_INLINE
142 void mach_write_to_6(byte *b, ib_uint64_t id);
143 
144 /** The following function is used to fetch data from 6 consecutive
145 bytes. The most significant byte is at the lowest address.
146 @param[in] b pointer to 6 bytes to read
147 @return 48-bit integer */
148 UNIV_INLINE
149 ib_uint64_t mach_read_from_6(const byte *b) MY_ATTRIBUTE((warn_unused_result));
150 
151 /** The following function is used to store data in 7 consecutive
152 bytes. We store the most significant byte to the lowest address.
153 @param[in] b pointer to 7 bytes where to store
154 @param[in] n 56-bit integer */
155 UNIV_INLINE
156 void mach_write_to_7(byte *b, ib_uint64_t n);
157 
158 /** The following function is used to fetch data from 7 consecutive
159 bytes. The most significant byte is at the lowest address.
160 @param[in] b pointer to 7 bytes to read
161 @return 56-bit integer */
162 UNIV_INLINE
163 ib_uint64_t mach_read_from_7(const byte *b) MY_ATTRIBUTE((warn_unused_result));
164 
165 /** The following function is used to store data in 8 consecutive
166 bytes. We store the most significant byte to the lowest address.
167 @param[in] b pointer to 8 bytes where to store
168 @param[in] n 64-bit integer to be stored */
169 UNIV_INLINE
170 void mach_write_to_8(void *b, ib_uint64_t n);
171 
172 /** The following function is used to fetch data from 8 consecutive
173 bytes. The most significant byte is at the lowest address.
174 @param[in] b pointer to 8 bytes to read
175 @return 64-bit integer */
176 UNIV_INLINE
177 ib_uint64_t mach_read_from_8(const byte *b) MY_ATTRIBUTE((warn_unused_result));
178 
179 /** Writes a 64-bit integer in a compressed form (5..9 bytes).
180 @param[in] b pointer to memory where to store
181 @param[in] n 64-bit integer to be stored
182 @return size in bytes */
183 UNIV_INLINE
184 ulint mach_u64_write_compressed(byte *b, ib_uint64_t n);
185 
186 /** Read a 64-bit integer in a compressed form.
187 @param[in,out] b pointer to memory where to read;
188 advanced by the number of bytes consumed
189 @return unsigned value */
190 UNIV_INLINE
191 ib_uint64_t mach_u64_read_next_compressed(const byte **b);
192 
193 /** Writes a 64-bit integer in a compressed form (1..11 bytes).
194 @param[in] b pointer to memory where to store
195 @param[in] n 64-bit integer to be stored
196 @return size in bytes */
197 UNIV_INLINE
198 ulint mach_u64_write_much_compressed(byte *b, ib_uint64_t n);
199 
200 /** Reads a 64-bit integer in a compressed form.
201 @param[in] b pointer to memory from where to read
202 @return the value read */
203 UNIV_INLINE
204 ib_uint64_t mach_u64_read_much_compressed(const byte *b)
205  MY_ATTRIBUTE((warn_unused_result));
206 
207 /** Read a 64-bit integer in a much compressed form.
208 @param[in,out] ptr pointer to memory from where to read,
209 advanced by the number of bytes consumed, or set NULL if out of space
210 @param[in] end_ptr end of the buffer
211 @return unsigned 64-bit integer */
212 ib_uint64_t mach_parse_u64_much_compressed(const byte **ptr,
213  const byte *end_ptr);
214 
215 /** Read a 32-bit integer in a compressed form.
216 @param[in,out] ptr pointer to memory from where to read;
217 advanced by the number of bytes consumed, or set NULL if out of space
218 @param[in] end_ptr end of the buffer
219 @return unsigned value */
220 ib_uint32_t mach_parse_compressed(const byte **ptr, const byte *end_ptr);
221 
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
unsigned long long int ulonglong
Definition: my_inttypes.h:55
UNIV_INLINE void mach_float_write(byte *b, float d)
Writes a float.
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).
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.
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
The following function is used to store data in 4 consecutive bytes.
UNIV_INLINE ib_uint64_t mach_read_from_6(const byte *b)
The following function is used to fetch data from 6 consecutive bytes.
UNIV_INLINE uint32_t mach_get_compressed_size(ulint n)
Return the size of an ulint when written in the compressed form.
mlog_id_t
Definition: mtr0types.h:62
UNIV_INLINE ib_uint64_t mach_u64_read_next_compressed(const byte **b)
Read a 64-bit integer in a compressed form.
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:43
UNIV_INLINE uint8_t mach_read_from_1(const byte *b)
The following function is used to fetch data from one byte.
Definition: buf0block_hint.cc:29
UNIV_INLINE float mach_float_read(const byte *b)
Reads a float.
UNIV_INLINE void mach_write_to_3(byte *b, ulint n)
The following function is used to store data in 3 consecutive bytes.
constexpr DWORD buf_size
Definition: create_def.cc:223
UNIV_INLINE void mach_double_write(byte *b, double d)
Writes a double.
UNIV_INLINE ib_uint64_t mach_read_from_8(const byte *b)
The following function is used to fetch data from 8 consecutive bytes.
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.
UNIV_INLINE ib_uint32_t mach_read_next_compressed(const byte **b)
Read a 32-bit integer in a compressed form.
UNIV_INLINE ulint mach_read_from_2_little_endian(const byte *buf)
Reads a ulint stored in the little-endian format.
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.
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.
UNIV_INLINE ib_uint64_t mach_u64_read_much_compressed(const byte *b)
Reads a 64-bit integer in a compressed form.
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).
uint16_t uint16
Definition: my_inttypes.h:64
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:80
Utilities for byte operations.
UNIV_INLINE ulint mach_decode_2(uint16 n)
The following function is used to convert a 16-bit data item from the canonical format, for fast bytewise equality test against memory.
UNIV_INLINE void mach_write_to_1(byte *b, ulint n)
The following function is used to store data in one byte.
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.
UNIV_INLINE uint32_t mach_read_from_3(const byte *b)
The following function is used to fetch data from 3 consecutive bytes.
UNIV_INLINE void mach_write_to_n_little_endian(byte *dest, ulint dest_size, ulint n)
Writes a ulint in the little-endian format.
UNIV_INLINE void mach_write_to_2_little_endian(byte *dest, ulint n)
Writes a ulint in the little-endian format.
UNIV_INLINE double mach_double_read(const byte *b)
Reads a double.
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.
UNIV_INLINE ib_uint64_t mach_read_from_7(const byte *b)
The following function is used to fetch data from 7 consecutive bytes.
int n
Definition: xcom_base.cc:442
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.
UNIV_INLINE ulint mach_write_compressed(byte *b, ulint n)
Write a ulint in a compressed form (1..5 bytes).
UNIV_INLINE void mach_write_to_2(byte *b, ulint n)
The following function is used to store data in two consecutive bytes.
UNIV_INLINE uint32_t mach_read_from_4(const byte *b)
The following function is used to fetch data from 4 consecutive bytes.
unsigned char byte
Blob class.
Definition: common.h:159
UNIV_INLINE ulint mach_read_from_n_little_endian(const byte *buf, ulint buf_size)
Reads a ulint stored in the little-endian format.
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, for fast bytewise equality test against memory.
UNIV_INLINE uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
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.
Mini-transaction buffer global types.