MySQL 9.0.0
Source Code Documentation
json_reader.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_READER_INCLUDED
25#define JSON_READER_INCLUDED
26
27#include <memory>
28#include <string>
29#include <vector>
30
31#define RAPIDJSON_HAS_STDSTRING 1
32
33#include "my_rapidjson_size_t.h"
34
35#include <rapidjson/document.h>
36#include <rapidjson/schema.h>
37
40
41#include "json_ds.h"
42
44
46 std::vector<std::pair<std::pair<meta::Metadata, data::Data>,
47 std::unique_ptr<Json_data_extension>>>;
48
49/**
50 Base Json_reader
51
52 Expected format for version 1.0
53 {
54 "version": "1.0",
55 "elements": [
56 {
57 "user": "<user_name>",
58 "data_id": "<name>",
59 "data_type": "<data_type>",
60 "data": "<hex_of_data>",
61 "extension": [
62 ]
63 },
64 ...
65 ...
66 ]
67 }
68*/
69
71 public:
72 Json_reader(const std::string &schema, const std::string &data,
73 std::string version_key = "version",
74 std::string array_key = "elements");
75
76 Json_reader(const std::string &data);
77
79
80 /** Destructor */
81 virtual ~Json_reader() = default;
82
83 std::string version() const;
84
85 /**
86 Get number of elements in the document
87
88 @returns number elements in the document
89 */
90 size_t num_elements() const;
91
92 /**
93 Fetch element from given position
94
95 @param [in] index Element position
96 @param [out] metadata Data identifier
97 @param [out] data Data
98 @param [out] json_data_extension Backend specific extension
99
100 @return status of operation
101 @retval false Success
102 @retval true Failure
103 */
104 virtual bool get_element(
105 size_t index, meta::Metadata &metadata, data::Data &data,
106 std::unique_ptr<Json_data_extension> &json_data_extension) const;
107
108 /**
109 Get all elements
110
111 @param [out] output Output vector
112
113 @returns status of extracting elements
114 @retval false Success
115 @retval true Failure
116 */
117 virtual bool get_elements(output_vector &output) const;
118
119 bool valid() const { return valid_; }
120
121 private:
122 /** Data in JSON DOM format */
123 rapidjson::Document document_;
124 /** Version key */
125 const std::string version_key_;
126 /** user specific elements array key */
127 const std::string array_key_;
128 /** Validity of the data */
129 bool valid_;
130};
131
132} // namespace keyring_common::json_data
133
134#endif // !JSON_READER_INCLUDED
Sensitive data storage.
Definition: data.h:39
Base Json_reader.
Definition: json_reader.h:70
virtual ~Json_reader()=default
Destructor.
std::string version() const
Get version info.
Definition: json_reader.cc:115
bool valid() const
Definition: json_reader.h:119
virtual bool get_element(size_t index, meta::Metadata &metadata, data::Data &data, std::unique_ptr< Json_data_extension > &json_data_extension) const
Fetch element from given position.
Definition: json_reader.cc:130
virtual bool get_elements(output_vector &output) const
Get all elements.
Definition: json_reader.cc:148
size_t num_elements() const
Get number of elements in the document.
Definition: json_reader.cc:125
rapidjson::Document document_
Data in JSON DOM format.
Definition: json_reader.h:123
const std::string version_key_
Version key.
Definition: json_reader.h:125
Json_reader()
Definition: json_reader.cc:107
const std::string array_key_
user specific elements array key
Definition: json_reader.h:127
bool valid_
Validity of the data.
Definition: json_reader.h:129
Common metadata.
Definition: meta.h:38
Define rapidjson::SizeType to be std::size_t.
Definition: json_ds.h:29
std::vector< std::pair< std::pair< meta::Metadata, data::Data >, std::unique_ptr< Json_data_extension > > > output_vector
Definition: json_reader.h:47