MySQL 8.0.39
Source Code Documentation
xa_aux.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2024, Oracle and/or its affiliates.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef XA_AUX_H
25#define XA_AUX_H
26#include "m_string.h" // _dig_vec_lower
27
28/**
29 Function serializes XID which is characterized by by four last arguments
30 of the function.
31 Serialized XID is presented in valid hex format and is returned to
32 the caller in a buffer pointed by the first argument.
33 The buffer size provived by the caller must be not less than
34 8 + 2 * XIDDATASIZE + 4 * sizeof(XID::formatID) + 1, see
35 XID::serialize_xid() that is a caller and plugin.h for XID declaration.
36
37 @param buf pointer to a buffer allocated for storing serialized data
38 @param fmt formatID value
39 @param gln gtrid_length value
40 @param bln bqual_length value
41 @param dat data value
42
43 @return the value of the buffer pointer
44*/
45
46inline char *serialize_xid(char *buf, long fmt, long gln, long bln,
47 const char *dat) {
48 int i;
49 char *c = buf;
50 /*
51 Build a string like following pattern:
52 X'hex11hex12...hex1m',X'hex21hex22...hex2n',11
53 and store it into buf.
54 Here hex1i and hex2k are hexadecimals representing XID's internal
55 raw bytes (1 <= i <= m, 1 <= k <= n), and `m' and `n' even numbers
56 half of which corresponding to the lengths of XID's components.
57 */
58 *c++ = 'X';
59 *c++ = '\'';
60 for (i = 0; i < gln; i++) {
61 *c++ = _dig_vec_lower[static_cast<uchar>(dat[i]) >> 4];
62 *c++ = _dig_vec_lower[static_cast<uchar>(dat[i]) & 0x0f];
63 }
64 *c++ = '\'';
65
66 *c++ = ',';
67 *c++ = 'X';
68 *c++ = '\'';
69 for (; i < gln + bln; i++) {
70 *c++ = _dig_vec_lower[static_cast<uchar>(dat[i]) >> 4];
71 *c++ = _dig_vec_lower[static_cast<uchar>(dat[i]) & 0x0f];
72 }
73 *c++ = '\'';
74 sprintf(c, ",%lu", fmt);
75
76 return buf;
77}
78
79#endif /* XA_AUX_H */
const char _dig_vec_lower[]
Definition: int2str.cc:41
unsigned char uchar
Definition: my_inttypes.h:52
Definition: buf0block_hint.cc:30
char * serialize_xid(char *buf, long fmt, long gln, long bln, const char *dat)
Function serializes XID which is characterized by by four last arguments of the function.
Definition: xa_aux.h:46