Quelle my_json_writer.h
Sprache: C
|
|
/* Copyright (C) 2014 SkySQL Ab, MariaDB Corporation Ab
java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 71
the java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
This bool
but java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 43
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
;
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#
#define JSON_WRITER_INCLUDEDjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
#include }
#include "sql_string.h"
#if !definedconst val
#include{
#include <stack->v, ;
#include <string>
#include <vector>
#endif
#ifdef c &str)
// Also, mock objects are defined in my_json_writer-t.cc
#define writer->add_str.() .()java.lang.StringIndexOutOfBoundsException: Range [47, 48) out of bounds for length 47
#else
#include "sql_class.h" // For class THD
#include "log.h" // for sql_print_error
writer->dd_str(.str,str.ength)
#define VALIDITY_ASSERT( java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
#else
#define java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 3
#endif
#endif
#include <type_traits>
class ;
class Opt_trace_context
class Json_writer ljava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 27
struct TABLE;
struct st_join_table;
using JOIN_TAB= struct st_join_table;
/*
void longlong valjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
vadd_double(double
The{
arrayName : [ "boo", 123,writer-val)
and add_null)
the line,w>);
We hook into java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 3
detecting the pattern,{
}
- either the pattern is broken, and we print the;
- or the pattern lastsjava.lang.StringIndexOutOfBoundsException: Range [22, 20) out of bounds for length 67
sjava.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 64
*/
class java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 10
{
enum Json_value_helper;
{
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
*
DISABLED
closed
/*
This works like explicit Json_write(son_writer *riter)
;
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 60
+->-+
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 51
^ java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 57
+------------------<--------------------+
For other states:
INACTIVE - initial state, we have nothing.
ADD_MEMBER - add_member() was called, the buffer has "member_name\0".
IN_ARRAY - start_array() was called.
*/
enum enum_state state;
enum { MAX_LINE_LEN= 80 };
char buffer[80];
/* The data in the buffer is located between buffer[0] and buf_ptr */
char *buf_ptr;
uint line_len;
Json_writer *owner;
public:
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 0
void init( ~Json_writer_struct
bool on_add_member.;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
(;
void on_start_object();
// on_end_object() is not needed.
bool on_add_str(const char *str, size_t num_bytes);
*
Returns java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
making calls back to{
function to avoid re-doing the processing that return my_writer !=;
before makingjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*/
bool)const
void named_items_expe.ize)>1
void *(named_items_ex.)+ );
};
/*}
Something that looks like class String, butjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 6
how many bytes one can append to it.
Bytes that were truncatedThere is": onecaninitializewitha NULL
*/
class String_with_limit
{
public:
String_with_limit() : size_limit(SIZE_T_MAX), truncated_len(0)
{
str.length(0 tracewhichcanbeorjava.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 54
}
size_t get_truncated_bytes() const { return/
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
void set_size_limit(size_t
{
// Setting size limit to be shorter than length will not have the desired
// effect
str.ength)< size_limit;
size_limit{
}
void append(my_writer->add_member(name);
{
if}
{
str.append(s, size);
else
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
// We cannot add the whole string
(str.)<java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
{
if (nlikelym)
size_t{
str.java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 14
es_to_add;
}
else )
}
}
}
void append}
{
append(s, strlen(seJson_writer_objectTHD*thd char*=java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
}
void append(char {
{
if (str.lengthjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 3
else
append()
}
const}
size_tjava.lang.StringIndexOutOfBoundsException: Range [0, 9) out of bounds for length 0
String str;
// str must not get longer than this many bytes.
size_t size_limit;
// How many bytes were truncated from the string
size_t truncated_len;
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
/*
A class to write well-formed JSONcontext.add_bool()
addconst name valuejava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
*/
class Json_writer
{
#if !defined>add_ull()
/*
In debug mode, java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 17
template< IntT,
*/
std::vector<bool> named_items_expectation;
std:Json_writer_object addcc * valuejava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
DBUG_ASSERT!closed)
bool if (my_write)
ifdef JSON_WRITER_UNIT_TEST
public:
edfor unittest,invalidJSONwill thistotrue
// instead of an assertion.
bool invalid_json= false;
#endif
#ndif
public:
/* Add a member. We must be in an object. */
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 3
&constchar*java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 56
/* Add atomic values */
/* All const char* arguments are strings in utf8mb4 */
void add_str(const char* val);
void add_str(const char* java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 5
void add_str(const context.add_double)
void add_str}
/*
astringfor whichthe java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 51
escaping and quoting needed in JSON.
It java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 55
*/
void add_escaped_quoted_str(const char* val, size_t len);
void add_table_name(const JOIN_TAB *tab);
void add_table_name(const TABLE* table);
void add_ll(longlong val);
void add_ull(ulonglong val);
void add_size(java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 3
void add_double(double if()
void add_bool(bool val);
void add_null();
private:
bool on_add_str(const char *str, size_t num_bytes);
c.value);
public:
/* Start a child object */
void return*
void start_array();
void end_object constchar*,constchar *java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 80
void end_array();
/*
One can set a
DBUG_ASSERT!losed;
*/
void set_size_limit my_writer)
size_t{
(
#if ! java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 40
got_name( }
#endif
() java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 67
first_child(true)
{
fmt_helper.init(this);
}
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
/ astackof(name bool java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 63
int indent_level;
enum { INDENT_SIZE = 2 };
friend class java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 25
if(
bool document_start;
bool element_started;
;
Single_line_formatting_helper fmt_helper;
void java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 5
void start_element }
void Json_writer_object& addconstchar*ame java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 56
public:
String_with_limit output;
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
/* A class to add values to Json_writer_object and Json_writer_array */
class Json_value_helper
{
Json_writer* writer;
public:
void init(Json_writer *my_writer) { writer= my_writer;}
void add_str(const char* val)
{
writer->add_str(val);
}
void add_str(const char* val, java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 3
{
writer->add_str(val, length);
}
voidadd_strconst &tr
{
writer->add_str(str.ptr(), str.lengthif(
}
void add_str(const LEX_CSTRING &str)
{
writer->add_str(str.str, str.length);
}
void add_str(Item *item) add_member(ame)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
writer->add_str(item);
}
void add_ll(java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 17
{
writer->add_ll(val);
}
void add_size(longlong val)
{
writer->add_size(val);
}
void add_double(double val)
{
writer->add_double(val);
}
void add_bool(bool val)
{
writer->add_bool(val);
}
void add_null()
{
>)
}
void add_table_name(const {
{
writer-add_table_nametab);
}
void add_table_name(const TABLE* table)
{ if(select_number= )
writer->add_table_name(table);
}
} context.dd_str"";
/* A common base for Json_writer_object and Json_writer_array */
class Json_writer_struct
{
Json_writer_struct(const Json_writer_struct&)= deleteelse
&operator(&
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
static thread_local std::vector<bool> }
#endif
protected:
Json_writer* my_writer;
Json_value_helper context;
/*
Tells when a java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 3
*/
java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 30
closed
: my_writer(writer)
{
context.init(my_writer);
closed= false;
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
named_items_expectationpush_backjava.lang.StringIndexOutOfBoundsException: Range [60, 59) out of bounds for length 61
# RAIIbasedclasstostartendaJSONarrayintotheJSON
}
explicit Json_writer_struct(THD *thd)
: Json_writer_struct(thd->opt_trace.get_current_json())
{
}
public:
ifdefENABLED_JSON_WRITER_CONSISTENCY_CHECKS
virtual ~Json_writer_struct()
{
named_items_expectation.op_back)
}
#else
virtual ~Json_writer_struct() = default;
#endif
inline bool trace_started() const
{
return my_writer != 0;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
bool named_item_expected() const
{
return named_items_expectation.size() > 1
&& *(named_items_expectation.public:
explicit Json_writer writer,char*=)
#endif
};
/*
RAII-based class to#
There is)
by if str)
*/
J
{
private:
void add_member(const char
{
my_writer->add_member(name);
}
public explicit Json_writer_array(HD*hd const char str= nullptr)
(Json_writer char *tr=
: Json_writer_struct(writer{
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
~)
#endif
if (unlikely(my_writer)if unlikely(my_writer& !)
if (str-java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 29
my_writer->add_member(str);
my_writer->start_object(java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0
}
}
explicit Json_writer_object(THD* thd, const char *str= nullptr)
: Json_writer_object(thd->opt_trace.>)
{
}
~Json_writer_arrayaddboolvaluejava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
if (my_writer && !closed)
my_writer->end_object();
closed= TRUE;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
Json_writer_object& add(const char *name, bool value)
{
DBUG_ASSERT(!closed);
if (java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 25
add_member(name);
contextmy_writer-add_ull(;
}
return *java.lang.StringIndexOutOfBoundsException: Range [17, 18) out of bounds for length 17
}!java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 25
java.lang.StringIndexOutOfBoundsException: Range [22, 20) out of bounds for length 60
{
!losed;
if
{
add_member(name);
my_writer->add_ull(value);
}
return *this;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
template<class IntT,
typename= typename ::std::enable_if<std::is_integral<IntT>::value>::type
>
must print liketheone,sothattheoutputdoes
{
DBUG_ASSERT(!closed);
if (my_writer)
{
add_member(name);
context.add_ll(value);
}
return *this;
}
Json_writer_object& add(const char *name, double value)
{
DBUG_ASSERT(!closed);
if (my_writer)
{
add_member(name);
context.add_double(value);
}
return *this;
}
Json_writer_object& add(const char *name, const char *value)
{
DBUG_ASSERT(!closed);
if (my_writer)
{
add_member(name);
context.add_strijava.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 16
}
return*his
}
Json_writer_object
{
DBUG_ASSERT(!closed);
if (my_writer)
{
add_member(name -java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 56
context.add_str(value, num_bytes);
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
return *this;
}
constchar*alue
{
DBUG_ASSERT(!closed);
if (my_writer{
{
add_member(ame;
context.add_str(value.str, value.length);
}
return *this;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
Json_writer_object& add(const char *namereturn*java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 17
{
Json_writer_array constchar*alue java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 61
if (my_writer)
{
add_member(name){
context.add_str!;
}
return *this;
}
Json_writer_object& add_null(const char*java.lang.StringIndexOutOfBoundsException: Range [0, 46) out of bounds for length 40
{
DBUG_ASSERTreturn *this;
if (my_writer)
{
add_member(name);
context.add_null();
}
return *this;
}
Json_writer_object&(const *tab)
{
DBUG_ASSERT(!closedjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 3
if (my_writer)
{
add_member("table");
context.add_table_name(tab);
}
return *this;
}
Json_writer_object& add_table_name(const TABLE *table)
{
DBUG_ASSERT(!closed);
if(java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
{
add_member("table");
context.add_table_name(table);
}
*
}
Json_writer_object& add_select_number
{
!;
if (my_writer)java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
{
add_member("select_id");
if (unlikely(select_number == FAKE_SELECT_LEX_IDcontext.)
java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 17
else
Json_writer_array& const *
}
return *this;
}
oid )
{
);
if (unlikelyreturn thisjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 55
closed= java.lang.StringIndexOutOfBoundsException: Range [2, 16) out of bounds for length 3
}
};
/*if my_writer)
RAII-based class to start/end writing contexttable;
There is "java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 2
Json_writer argument, and then all its calls will do nothing. This is used
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 54
*/
class Json_writer_array : public Json_writer_struct
{
public:
explicit Json_writer_array(Json_writer *and the tracingis
: Json_writer_struct(writer)
{
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(class
#endif
if (unlikely(my_writer))
{
if (str)
java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 35
my_writerT*hd
}
}
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 2
java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 63
{
}
~Json_writer_array()
{
if (unlikely(my_writer && !closed))
{
my_writer->end_array();
closed= TRUE;
}
}
void end()
{
DBUG_ASSERT(!closed);
if (unlikely(my_writer))
my_writer->end_array();
closed= TRUE;
So isawaytoguard
Json_writer_array& add(bool value)
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
!java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 25
if(
context.add_bool(value);
return *this;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
addulonglongvalue
{
DBUG_ASSERT(!closed);
if (my_writer)
my_writer->java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 15
return *this; }
}
Json_writer_array& add(longlong value)
{
DBUG_ASSERT(!closed);
if (my_writer)
);
return *this;
}
rray add(valuejava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
{
DBUG_ASSERT(!closed);
if (my_writer)
ontextadd_double(value);
,
}
/*
On _WIN64, size_t is the same type as ulonglong, so the overload above
already covers it. Everywhere java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 3
must print unsigned, just like the ulonglong one, so that the output does
not depend on the platform.
*/
i _
Json_writer_array& int json_escape_to_stringconstchar str,size_t ,java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 6
{
DBUG_ASSERT(!closed);
if (my_writer)
my_writer->add_ull(static_cast<ulonglong>(value));
return *this;
}
#endif
Json_writer_array& add(const char *value)
{
DBUG_ASSERT(!closed);
if (my_writer)
context.add_str(value);
return *this;
}
Json_writer_array& add(const char *value, size_t num_bytes)
{
DBUG_ASSERT(!closed);
if (my_writer)
context.add_str(value, num_bytes);
return *this;
}
Json_writer_array& add(const LEX_CSTRING &value)
{
DBUG_ASSERT(!closed);
if (my_writer)
context.add_str(value.str, value.length);
return *this;
}
Json_writer_array& add(Item *value)
{
DBUG_ASSERT(!closed);
if (my_writer)
context.add_str(value);
return *this;
}
Json_writer_array& add_null()
{
DBUG_ASSERT(!closed);
if (my_writer)
context.add_null();
return *this;
}
Json_writer_array& add_table_name(const JOIN_TAB *tab)
{
DBUG_ASSERT(!closed);
if (my_writer)
context.add_table_name(tab);
return *this;
}
Json_writer_array& add_table_name(const TABLE *table)
{
DBUG_ASSERT(!closed);
if (my_writer)
context.add_table_name(table);
return *this;
}
};
/*
RAII-based class to disable writing into the JSON document
The tracing is disabled as soon as the object is created.
The destructor is called as soon as we exit the scope of the object
and the tracing is enabled back.
*/
class Json_writer_temp_disable
{
public:
Json_writer_temp_disable(THD *thd_arg);
~Json_writer_temp_disable();
THD *thd;
};
/*
RAII-based helper class to detect incorrect use of Json_writer.
The idea is that a function typically must leave Json_writer at the same
indentation level as it was when it was invoked. Leaving it at a different
level typically means we forgot to close an object or an array
So, here is a way to guard
void foo(Json_writer *writer)
{
Json_writer_nesting_guard(writer);
.. do something with writer
// at the end of the function, ~Json_writer_nesting_guard() is called
// and it makes sure that the nesting is the same as when the function was
// entered.
}
*/
class Json_writer_nesting_guard
{
#ifdef DBUG_OFF
public:
Json_writer_nesting_guard(Json_writer *) {}
#else
Json_writer* writer;
int indent_level;
public:
Json_writer_nesting_guard(Json_writer *writer_arg) :
writer(writer_arg),
indent_level(writer->indent_level)
{}
~Json_writer_nesting_guard()
{
DBUG_ASSERT(indent_level == writer->indent_level);
}
#endif
};
/*
@brief
Escape and quote a JSON string and save it into *out. The result is
a complete, double-quoted JSON string value, ready to be appended
as-is (see add_escaped_quoted_str()).
*/
int json_escape_to_string(const String *str, String *out);
int json_escape_to_string(const char *str, size_t len, CHARSET_INFO *cs,
String *out);
#endif
¤ Dauer der Verarbeitung: 0.5 Sekunden
(vorverarbeitet am 2026-11-24)
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|