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