MySQL 8.4.0
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
27#include <stdio.h>
28
29#include "dig_vec.h" // dig_vec_lower
30#include "my_inttypes.h"
31
32/**
33 Function serializes XID which is characterized by by four last arguments
34 of the function.
35 Serialized XID is presented in valid hex format and is returned to
36 the caller in a buffer pointed by the first argument.
37 The buffer size provived by the caller must be not less than
38 8 + 2 * XIDDATASIZE + 4 * sizeof(XID::formatID) + 1, see
39 XID::serialize_xid() that is a caller and plugin.h for XID declaration.
40
41 @param buf pointer to a buffer allocated for storing serialized data
42 @param fmt formatID value
43 @param gln gtrid_length value
44 @param bln bqual_length value
45 @param dat data value
46
47 @return the value of the buffer pointer
48*/
49
50inline char *serialize_xid(char *buf, long fmt, long gln, long bln,
51 const char *dat) {
52 int i;
53 char *c = buf;
54 /*
55 Build a string like following pattern:
56 X'hex11hex12...hex1m',X'hex21hex22...hex2n',11
57 and store it into buf.
58 Here hex1i and hex2k are hexadecimals representing XID's internal
59 raw bytes (1 <= i <= m, 1 <= k <= n), and `m' and `n' even numbers
60 half of which corresponding to the lengths of XID's components.
61 */
62 *c++ = 'X';
63 *c++ = '\'';
64 for (i = 0; i < gln; i++) {
65 *c++ = dig_vec_lower[static_cast<uchar>(dat[i]) >> 4];
66 *c++ = dig_vec_lower[static_cast<uchar>(dat[i]) & 0x0f];
67 }
68 *c++ = '\'';
69
70 *c++ = ',';
71 *c++ = 'X';
72 *c++ = '\'';
73 for (; i < gln + bln; i++) {
74 *c++ = dig_vec_lower[static_cast<uchar>(dat[i]) >> 4];
75 *c++ = dig_vec_lower[static_cast<uchar>(dat[i]) & 0x0f];
76 }
77 *c++ = '\'';
78 sprintf(c, ",%ld", fmt);
79
80 return buf;
81}
82
83#endif /* XA_AUX_H */
static char buf[MAX_BUF]
Definition: conf_to_src.cc:73
constexpr std::array< const char, 37 > dig_vec_lower
Definition: dig_vec.h:36
Some integer typedefs for easier portability.
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:50