Skip to content
Snippets Groups Projects
Packet_Structure_Json.h 2.48 KiB
Newer Older
Valerio Pastore's avatar
Valerio Pastore committed
/*
**************************************************************************
* Copyright (C) 2023 INAF
* 
* This program is free software: you can redistribute it and/or modify it 
* under the terms of the GNU Lesser General Public License as published by 
* the Free Software Foundation, either version 3 of the License
* or (at your option) any later version. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* See the GNU Lesser General Public License for more details. 
* You should have received a copy of the GNU Lesser General Public License 
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* 
* Authors:
* 
* <>Valerio Pastore INAF-OAS Bologna  valerio.pastore@inaf.it
****************************************************************************
*/
Valerio Pastore's avatar
Valerio Pastore committed
#pragma once
Valerio Pastore's avatar
Valerio Pastore committed

#include <Base_Packet.h>
#include <fstream>
#include <nlohmann/json.hpp>

astri's avatar
astri committed
using namespace nlohmann;

Valerio Pastore's avatar
Valerio Pastore committed
namespace inaf::oasbo::Packets {

Valerio Pastore's avatar
Valerio Pastore committed
/**
 * @brief Represents a JSON packet structure for ASTRI DAQ.
 * 
 * This class extends the BasePacketStructure class and provides functionality
 * to convert JSON data into a tuple vector and read the structure from a source.
 * The compatible json files are in config folder.
 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
class PacketStructureJson: public inaf::oasbo::Packets::BasePacketStructure {
protected:
Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Converts JSON data into a tuple vector.
	 * 
	 * @param data The JSON data to convert.
	 * @param count The count of tuples in the vector.
	 * @return An optional structure representing the tuple vector.
	 */
	static std::optional<Structure> convertToTupleVector(const ordered_json &data,
Valerio Pastore's avatar
.  
Valerio Pastore committed
			uint &count);
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Reads the packet structure from a source.
	 * 
	 * @param source The source from which to read the structure.
	 * @return The structure read from the source.
	 */
	static Structure readStructureFromSource(std::string source);
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
public:
Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Constructs a PacketStructureJson object with the specified source.
	 * 
	 * @param source The source from which to read the structure.
	 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
	PacketStructureJson(std::string source) :
			BasePacketStructure(source, &readStructureFromSource) {
Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Constructs a PacketStructureJson object from another BasePacketStructure object.
	 * 
	 * @param other The BasePacketStructure object to copy from.
	 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
	PacketStructureJson(const BasePacketStructure &other) :
			BasePacketStructure(other) {
Valerio Pastore's avatar
Valerio Pastore committed
};
}