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