24#ifndef VECTOR_CONV_INCLUDED
25#define VECTOR_CONV_INCLUDED
39 uint32_t *max_output_dims) {
40 if (input ==
nullptr || input[0] !=
'[' || input_len == 0 ||
41 input[input_len - 1] !=
']') {
47 size_t output_len =
sizeof(float) * (*max_output_dims);
48 String temp_output(output, output_len,
nullptr);
49 if (output + output_len >= input && input + input_len >= output) {
50 temp_output =
String(output_len);
53 const char *
const input_end = input + input_len - 1;
57 bool with_success =
false;
59 for (
float fnum = strtof(input, &
end); input !=
end;
60 fnum = strtof(input, &
end)) {
62 if (errno == ERANGE || dim >= *max_output_dims || std::isnan(fnum) ||
67 memcpy(temp_output.
ptr() + dim *
sizeof(
float), &fnum,
sizeof(
float));
72 }
else if (*input ==
']' && input == input_end) {
81 if (temp_output.
ptr() != output) {
82 memcpy(output, temp_output.
ptr(), dim *
sizeof(
float));
85 *max_output_dims = dim;
92 uint32_t *max_output_len) {
93 const uint32_t end_cushion = 12;
94 if (input ==
nullptr || *max_output_len < end_cushion) {
99 size_t input_len = input_dims *
sizeof(float);
100 String temp_output(output, *max_output_len,
nullptr);
101 if (output + *max_output_len >= input && input + input_len >= output) {
102 temp_output =
String(*max_output_len);
105 char *write_ptr = temp_output.ptr();
106 uint32_t total_length = 1;
109 for (uint32_t i = 0; i < input_dims; i++) {
110 int remaining_bytes = *max_output_len - total_length;
112 if (*max_output_len <= total_length + end_cushion) {
113 nchars = snprintf(write_ptr, remaining_bytes,
"...");
116 char delimiter = (i == input_dims - 1) ?
']' :
',';
117 float input_value = 0;
118 memcpy(&input_value, input + i *
sizeof(
float),
sizeof(
float));
119 nchars = snprintf(write_ptr, remaining_bytes,
"%.5e%c", input_value,
121 if (nchars < 0 || nchars >= remaining_bytes) {
126 total_length += nchars;
129 if (temp_output.ptr() != output) {
130 memcpy(output, temp_output.ptr(), total_length);
133 *max_output_len = total_length;
138 const uint32_t precision) {
142 return length / precision;
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
const char * ptr() const
Definition: sql_string.h:249
#define UINT32_MAX
Definition: lexyy.cc:86
const char * delimiter
Definition: mysqlslap.cc:160
borrowable::binary::String< true > String
Definition: classic_protocol_binary.h:323
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
Our own string classes, used pervasively throughout the executor.
static bool from_vector_to_string(const char *const input, uint32_t input_dims, char *const output, uint32_t *max_output_len)
Definition: vector_conversion.h:89
static uint32_t get_dimensions(const uint32_t length, const uint32_t precision)
Definition: vector_conversion.h:137
static bool from_string_to_vector(const char *input, uint32_t input_len, char *const output, uint32_t *max_output_dims)
Definition: vector_conversion.h:37