mirror of
https://github.com/MariaDB/server.git
synced 2026-05-07 07:35:32 +02:00
Extending the API for json_writer by introdcing
classes for Json_writer_object and Json_writer_array. These classes will be used for the implementation of the optimizer trace.
This commit is contained in:
parent
4d5f85a3ec
commit
6b979416e0
2 changed files with 348 additions and 10 deletions
|
|
@ -16,7 +16,6 @@
|
|||
#include "mariadb.h"
|
||||
#include "sql_priv.h"
|
||||
#include "sql_string.h"
|
||||
|
||||
#include "my_json_writer.h"
|
||||
|
||||
void Json_writer::append_indent()
|
||||
|
|
@ -62,6 +61,7 @@ void Json_writer::end_object()
|
|||
indent_level-=INDENT_SIZE;
|
||||
if (!first_child)
|
||||
append_indent();
|
||||
first_child= false;
|
||||
output.append("}");
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,6 @@ void Json_writer::add_ll(longlong val)
|
|||
add_unquoted_str(buf);
|
||||
}
|
||||
|
||||
|
||||
/* Add a memory size, printing in Kb, Kb, Gb if necessary */
|
||||
void Json_writer::add_size(longlong val)
|
||||
{
|
||||
|
|
@ -173,7 +172,7 @@ void Json_writer::add_null()
|
|||
|
||||
void Json_writer::add_unquoted_str(const char* str)
|
||||
{
|
||||
if (fmt_helper.on_add_str(str))
|
||||
if (fmt_helper.on_add_str(str, 0))
|
||||
return;
|
||||
|
||||
if (!element_started)
|
||||
|
|
@ -183,10 +182,9 @@ void Json_writer::add_unquoted_str(const char* str)
|
|||
element_started= false;
|
||||
}
|
||||
|
||||
|
||||
void Json_writer::add_str(const char *str)
|
||||
{
|
||||
if (fmt_helper.on_add_str(str))
|
||||
if (fmt_helper.on_add_str(str, 0))
|
||||
return;
|
||||
|
||||
if (!element_started)
|
||||
|
|
@ -198,12 +196,70 @@ void Json_writer::add_str(const char *str)
|
|||
element_started= false;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used to add only num_bytes of str to the output string
|
||||
*/
|
||||
|
||||
void Json_writer::add_str(const char* str, size_t num_bytes)
|
||||
{
|
||||
if (fmt_helper.on_add_str(str, num_bytes))
|
||||
return;
|
||||
|
||||
if (!element_started)
|
||||
start_element();
|
||||
|
||||
output.append('"');
|
||||
output.append(str, num_bytes);
|
||||
output.append('"');
|
||||
element_started= false;
|
||||
}
|
||||
|
||||
void Json_writer::add_str(const String &str)
|
||||
{
|
||||
add_str(str.ptr());
|
||||
add_str(str.ptr(), str.length());
|
||||
}
|
||||
|
||||
Json_writer_object::Json_writer_object(Json_writer *writer):Json_writer_struct(writer)
|
||||
{
|
||||
if (my_writer)
|
||||
my_writer->start_object();
|
||||
}
|
||||
|
||||
Json_writer_object::Json_writer_object(Json_writer *writer, const char *str)
|
||||
:Json_writer_struct(writer)
|
||||
{
|
||||
if (my_writer)
|
||||
my_writer->add_member(str).start_object();
|
||||
|
||||
}
|
||||
Json_writer_object::~Json_writer_object()
|
||||
{
|
||||
if (!closed && my_writer)
|
||||
my_writer->end_object();
|
||||
closed= TRUE;
|
||||
}
|
||||
|
||||
Json_writer_array::Json_writer_array(Json_writer *writer):Json_writer_struct(writer)
|
||||
{
|
||||
if (my_writer)
|
||||
my_writer->start_array();
|
||||
}
|
||||
|
||||
Json_writer_array::Json_writer_array(Json_writer *writer, const char *str)
|
||||
:Json_writer_struct(writer)
|
||||
{
|
||||
if (my_writer)
|
||||
my_writer->add_member(str).start_array();
|
||||
|
||||
}
|
||||
Json_writer_array::~Json_writer_array()
|
||||
{
|
||||
if (!closed && my_writer)
|
||||
{
|
||||
my_writer->end_array();
|
||||
closed= TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
bool Single_line_formatting_helper::on_add_member(const char *name)
|
||||
{
|
||||
|
|
@ -267,11 +323,12 @@ void Single_line_formatting_helper::on_start_object()
|
|||
}
|
||||
|
||||
|
||||
bool Single_line_formatting_helper::on_add_str(const char *str)
|
||||
bool Single_line_formatting_helper::on_add_str(const char *str,
|
||||
size_t num_bytes)
|
||||
{
|
||||
if (state == IN_ARRAY)
|
||||
{
|
||||
size_t len= strlen(str);
|
||||
size_t len= num_bytes ? num_bytes : strlen(str);
|
||||
|
||||
// New length will be:
|
||||
// "$string",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue