MySQL 9.0.0
Source Code Documentation
json_writer.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef JSON_WRITER_INCLUDED
25#define JSON_WRITER_INCLUDED
26
27#include <string>
28
29#define RAPIDJSON_HAS_STDSTRING 1
30
31#include "my_rapidjson_size_t.h"
32
33#include <rapidjson/document.h>
34#include <rapidjson/stringbuffer.h>
35#include <rapidjson/writer.h>
36
39
40#include "json_ds.h"
41
43
45 public:
46 Json_writer(const std::string &data = {}, const std::string &version = "1.0",
47 const std::string &version_key = "version",
48 const std::string &array_key = "elements");
49
50 /** Destructor */
51 virtual ~Json_writer() = default;
52
53 bool set_data(const std::string &data);
54
55 std::string to_string() const;
56
57 /**
58 Add an element
59
60 @param [in] metadata Data identifier
61 @param [in] data Data
62
63 @returns status of insertion
64 @retval false Success
65 @retval true Failure
66 */
67 virtual bool add_element(const meta::Metadata &metadata,
68 const data::Data &data, Json_data_extension &);
69
70 /**
71 Remove an element
72
73 @param [in] metadata Data identifier
74
75 @returns status of removal
76 @retval false Success
77 @retval true Failure
78 */
79 virtual bool remove_element(const meta::Metadata &metadata,
80 const Json_data_extension &);
81
82 /** Number of elements stored */
83 size_t num_elements() const;
84
85 /** Validity of the document */
86 bool valid() const { return valid_; }
87
88 private:
89 /** Data in JSON DOM format */
90 rapidjson::Document document_;
91 /** Version information */
92 const std::string version_key_;
93 /** Elements array name */
94 const std::string array_key_;
95 /** Document validity */
96 bool valid_;
97};
98
99} // namespace keyring_common::json_data
100
101#endif // !JSON_WRITER_INCLUDED
Sensitive data storage.
Definition: data.h:39
Definition: json_writer.h:44
const std::string version_key_
Version information.
Definition: json_writer.h:92
bool valid() const
Validity of the document.
Definition: json_writer.h:86
bool set_data(const std::string &data)
Definition: json_writer.cc:63
virtual ~Json_writer()=default
Destructor.
const std::string array_key_
Elements array name.
Definition: json_writer.h:94
rapidjson::Document document_
Data in JSON DOM format.
Definition: json_writer.h:90
size_t num_elements() const
Number of elements stored.
Definition: json_writer.cc:148
virtual bool add_element(const meta::Metadata &metadata, const data::Data &data, Json_data_extension &)
Add an element.
Definition: json_writer.cc:78
std::string to_string() const
Get string representation of the JSON document.
Definition: json_writer.cc:69
bool valid_
Document validity.
Definition: json_writer.h:96
Json_writer(const std::string &data={}, const std::string &version="1.0", const std::string &version_key="version", const std::string &array_key="elements")
Constructor.
Definition: json_writer.cc:38
virtual bool remove_element(const meta::Metadata &metadata, const Json_data_extension &)
Remove an element.
Definition: json_writer.cc:122
Common metadata.
Definition: meta.h:38
Define rapidjson::SizeType to be std::size_t.
Definition: json_ds.h:29
required uint64 version
Definition: replication_group_member_actions.proto:41