ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
json.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libfits
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief Contains data structure for FITS keywords
7  */
8 #ifndef DAQ_OCM_DAQ_FITS_JSON_HPP_
9 #define DAQ_OCM_DAQ_FITS_JSON_HPP_
10 #include <nlohmann/json.hpp>
11 #include <variant>
12 #include <vector>
13 
14 #include "keyword.hpp"
15 
16 namespace daq::fits {
17 
18 /**
19  * Parse and return FITS keywords.
20  *
21  * Example string:
22  *
23  * @code
24  * auto keywords = R"([
25  * {
26  * "type":"valueKeyword",
27  * "name":"OBJECT",
28  * "value":"OBJECT,SKY"
29  * },
30  * ...
31  * ]");
32  * auto res = ParseJsonKeywords(keywords);
33  * @endcode
34  *
35  * @param keywords JSON encoded string of keywords
36  *
37  * @throws std::invalid_argument on schema validation error.
38  * @throws nlohmann::json::exception on JSON parsing error.
39  */
40 std::vector<KeywordVariant> ParseJsonKeywords(char const* keywords);
41 
42 /**
43  * Parse and return FITS keywords.
44  *
45  * @param keywords JSON object containing FITS keywords.
46  *
47  * @throws std::invalid_argument on schema validation error.
48  */
49 std::vector<KeywordVariant> ParseJsonKeywords(
50  nlohmann::json const& keywords,
51  nlohmann::json_pointer<nlohmann::json> const& = nlohmann::json_pointer<nlohmann::json>());
52 
53 /**
54  * SerializeJsons the keyword value variant to JSON.
55  *
56  * @param value Value to serialize.
57  * @return JSON value.
58  */
59 nlohmann::json SerializeJsonKeywordValue(BasicKeywordBase::ValueType const& value);
60 
61 /**
62  * SerializeJsons keyword to JSON.
63  *
64  * @param keyword keyword to serialize.
65  * @returns JSON object.
66  */
67 nlohmann::json SerializeJsonKeyword(KeywordVariant const& keyword);
68 
69 /**
70  * SerializeJsons keyword to JSON.
71  *
72  * @param keywords keywords to serialize.
73  * @returns JSON array of keywords.
74  */
75 nlohmann::json SerializeJsonKeywords(std::vector<KeywordVariant> const& keywords);
76 
77 } // namespace daq::fits
78 
79 #endif // #define DAQ_OCM_DAQ_FITS_JSON_HPP_
Contains data structure for FITS keywords.
nlohmann::json SerializeJsonKeywords(std::vector< KeywordVariant > const &keywords)
SerializeJsons keyword to JSON.
Definition: json.cpp:200
nlohmann::json SerializeJsonKeywordValue(BasicKeywordBase::ValueType const &value)
SerializeJsons the keyword value variant to JSON.
Definition: json.cpp:166
std::variant< ValueKeyword, EsoKeyword, LiteralKeyword > KeywordVariant
The different variants of keywords that are supported.
Definition: keyword.hpp:400
std::vector< KeywordVariant > ParseJsonKeywords(char const *keywords)
Parse and return FITS keywords.
Definition: json.cpp:124
nlohmann::json SerializeJsonKeyword(KeywordVariant const &keyword)
SerializeJsons keyword to JSON.
Definition: json.cpp:170
std::variant< std::string, int64_t, uint64_t, double, bool > ValueType
Definition: keyword.hpp:243