Commit 691f7e16 authored by Sergei Krivonos's avatar Sergei Krivonos

MDEV-27036: allow Json_writer_[array|object] from Json_writer

parent 917b4210
...@@ -372,15 +372,21 @@ class Json_writer_struct ...@@ -372,15 +372,21 @@ class Json_writer_struct
bool closed; bool closed;
public: public:
explicit Json_writer_struct(THD *thd, bool expect_named_children) explicit Json_writer_struct(Json_writer *writer)
: my_writer(writer)
{ {
my_writer= thd->opt_trace.get_current_json();
context.init(my_writer); context.init(my_writer);
closed= false; closed= false;
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
named_items_expectation.push_back(expect_named_children); named_items_expectation.push_back(expect_named_children);
#endif #endif
} }
explicit Json_writer_struct(THD *thd)
: Json_writer_struct(thd->opt_trace.get_current_json())
{
}
public:
virtual ~Json_writer_struct() virtual ~Json_writer_struct()
{ {
...@@ -420,8 +426,8 @@ class Json_writer_object : public Json_writer_struct ...@@ -420,8 +426,8 @@ class Json_writer_object : public Json_writer_struct
my_writer->add_member(name); my_writer->add_member(name);
} }
public: public:
explicit Json_writer_object(THD* thd, const char *str= nullptr) explicit Json_writer_object(Json_writer* writer, const char *str= nullptr)
: Json_writer_struct(thd, true) : Json_writer_struct(writer)
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(named_item_expected()); DBUG_ASSERT(named_item_expected());
...@@ -434,6 +440,11 @@ class Json_writer_object : public Json_writer_struct ...@@ -434,6 +440,11 @@ class Json_writer_object : public Json_writer_struct
} }
} }
explicit Json_writer_object(THD* thd, const char *str= nullptr)
: Json_writer_object(thd->opt_trace.get_current_json(), str)
{
}
~Json_writer_object() ~Json_writer_object()
{ {
if (my_writer && !closed) if (my_writer && !closed)
...@@ -593,25 +604,25 @@ class Json_writer_object : public Json_writer_struct ...@@ -593,25 +604,25 @@ class Json_writer_object : public Json_writer_struct
class Json_writer_array : public Json_writer_struct class Json_writer_array : public Json_writer_struct
{ {
public: public:
Json_writer_array(THD *thd) explicit Json_writer_array(Json_writer *writer, const char *str= nullptr)
: Json_writer_struct(thd, false) : Json_writer_struct(writer)
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(!named_item_expected()); DBUG_ASSERT(!named_item_expected());
#endif #endif
if (unlikely(my_writer)) if (unlikely(my_writer))
{
if (str)
my_writer->add_member(str);
my_writer->start_array(); my_writer->start_array();
} }
}
Json_writer_array(THD *thd, const char *str) explicit Json_writer_array(THD *thd, const char *str= nullptr)
: Json_writer_struct(thd, false) : Json_writer_array(thd->opt_trace.get_current_json(), str)
{ {
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
DBUG_ASSERT(named_item_expected());
#endif
if (unlikely(my_writer))
my_writer->add_member(str).start_array();
} }
~Json_writer_array() ~Json_writer_array()
{ {
if (unlikely(my_writer && !closed)) if (unlikely(my_writer && !closed))
...@@ -620,6 +631,7 @@ class Json_writer_array : public Json_writer_struct ...@@ -620,6 +631,7 @@ class Json_writer_array : public Json_writer_struct
closed= TRUE; closed= TRUE;
} }
} }
void end() void end()
{ {
DBUG_ASSERT(!closed); DBUG_ASSERT(!closed);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment