forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_utility.cpp
More file actions
66 lines (61 loc) · 1.93 KB
/
Copy pathparser_utility.cpp
File metadata and controls
66 lines (61 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include "sql/parser/parser_utility.h"
#include "lib/utility/ob_macro_utils.h"
#include <cstddef>
int parser_to_hex_cstr(
const void *in_data,
const int64_t data_length,
char *buff,
const int64_t buff_size)
{
int ret = 0;
int64_t pos = 0;
int64_t cstr_pos = 0;
if (0 != (ret = parser_to_hex_cstr_(in_data, data_length, buff, buff_size, &pos, &cstr_pos))) {
}
return ret;
}
static const char *HEXCHARS = "0123456789ABCDEF";
int parser_to_hex_cstr_(
const void *in_data,
const int64_t data_length,
char *buf,
const int64_t buf_len,
int64_t *pos,
int64_t *cstr_pos)
{
int ret = 0;
*cstr_pos = *pos;
if ((OB_UNLIKELY(data_length > 0) && OB_ISNULL(in_data))
|| OB_ISNULL(buf)
|| OB_UNLIKELY(*pos < 0)
|| OB_UNLIKELY(buf_len - *pos) < 1) {
ret = -1;
// LOG_WARN("Invalid argument", KP(in_data), KP(buf), K(data_length), K(buf_len), K(ret));
} else if ((buf_len - *pos) < (data_length * 2 + 1)) {
buf[*pos++] = '\0';
ret = -2;
// LOG_WARN("size is overflow", K(buf_len), K(data_length), K(buf_len), K(pos), K(ret));
} else {
unsigned const char *p = (unsigned const char *)in_data;
char *dst = static_cast<char *>(buf + *pos);
for (int64_t i = 0; i < data_length; ++i) {
*dst++ = HEXCHARS[*p >> 4 & 0xF];
*dst++ = HEXCHARS[*p & 0xF];
p++;
}
*dst = '\0';
*pos += (data_length * 2 + 1);
}
return ret;
}