MySQL 8.4.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
42namespace keyring_common {
43namespace json_data {
44
46 public:
47 Json_writer(const std::string data = {}, const std::string version = "1.0",
48 const std::string version_key = "version",
49 const std::string array_key = "elements");
50
51 /** Destructor */
52 virtual ~Json_writer() = default;
53
54 bool set_data(const std::string data);
55
56 const std::string to_string() const;
57
58 /**
59 Add an element
60
61 @param [in] metadata Data identifier
62 @param [in] data Data
63
64 @returns status of insertion
65 @retval false Success
66 @retval true Failure
67 */
68 virtual bool add_element(const meta::Metadata &metadata,
69 const data::Data &data, Json_data_extension &);
70
71 /**
72 Remove an element
73
74 @param [in] metadata Data identifier
75
76 @returns status of removal
77 @retval false Success
78 @retval true Failure
79 */
80 virtual bool remove_element(const meta::Metadata &metadata,
81 const Json_data_extension &);
82
83 /** Number of elements stored */
84 size_t num_elements() const;
85
86 /** Validity of the document */
87 bool valid() const { return valid_; }
88
89 private:
90 /** Data in JSON DOM format */
91 rapidjson::Document document_;
92 /** Version information */
93 const std::string version_key_;
94 /** Elements array name */
95 const std::string array_key_;
96 /** Document validity */
97 bool valid_;
98};
99
100} // namespace json_data
101} // namespace keyring_common
102
103#endif // !JSON_WRITER_INCLUDED
Sensitive data storage.
Definition: data.h:40
Definition: json_writer.h:45
const std::string version_key_
Version information.
Definition: json_writer.h:93
bool set_data(const std::string data)
Definition: json_writer.cc:66
bool valid() const
Validity of the document.
Definition: json_writer.h:87
virtual ~Json_writer()=default
Destructor.
const std::string array_key_
Elements array name.
Definition: json_writer.h:95
rapidjson::Document document_
Data in JSON DOM format.
Definition: json_writer.h:91
size_t num_elements() const
Number of elements stored.
Definition: json_writer.cc:151
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:40
const std::string to_string() const
Get string representation of the JSON document.
Definition: json_writer.cc:72
virtual bool add_element(const meta::Metadata &metadata, const data::Data &data, Json_data_extension &)
Add an element.
Definition: json_writer.cc:81
bool valid_
Document validity.
Definition: json_writer.h:97
virtual bool remove_element(const meta::Metadata &metadata, const Json_data_extension &)
Remove an element.
Definition: json_writer.cc:125
Common metadata.
Definition: meta.h:39
Define rapidjson::SizeType to be std::size_t.
Definition: keyring_encryption_service_definition.h:32
required uint64 version
Definition: replication_group_member_actions.proto:41