Skip to content
Snippets Groups Projects
Packet_Structure_Json.h 1.09 KiB
Newer Older
Valerio Pastore's avatar
Valerio Pastore committed
/*
 * PacketLib.h
 *
 *  Created on: Nov 24, 2022
 *      Author: valerio
 */

#ifndef INCLUDE_INAF_OAS_PACKET_STRUCTURE_JSON_H_
#define INCLUDE_INAF_OAS_PACKET_STRUCTURE_JSON_H_

#include <Base_Packet.h>
#include <fstream>
astri's avatar
astri committed
#include <fifo_map.hpp>
Valerio Pastore's avatar
Valerio Pastore committed
#include <nlohmann/json.hpp>

astri's avatar
astri committed
using namespace nlohmann;

// A workaround to give to use fifo_map as map, we are just ignoring the 'less' compare
template<class K, class V, class dummy_compare, class A>
using my_workaround_fifo_map = fifo_map<K, V, fifo_map_compare<K>, A>;
using my_json = basic_json<my_workaround_fifo_map>;

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

class PacketStructureJson : public inaf::oasbo::PacketLib::BasePacketStructure {

protected:
	static std::optional<Structure> convertToTupleVector(const my_json &data, uint &count);
	static Structure readStructureFromSource(std::string source);
Valerio Pastore's avatar
Valerio Pastore committed
public:
	PacketStructureJson(std::string source) : BasePacketStructure(source, &readStructureFromSource){
	PacketStructureJson(const BasePacketStructure &other) : BasePacketStructure(other){
Valerio Pastore's avatar
Valerio Pastore committed
};
}

#endif /* INCLUDE_INAF_OAS_PACKET_STRUCTURE_JSON_H_ */