generated from DARMA-tasking/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from DARMA-tasking/63-add-arbitrary-attributes…
…-to-json-validator #63: Add attributes reading for json reader
- Loading branch information
Showing
7 changed files
with
298 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
//@HEADER | ||
// ***************************************************************************** | ||
// | ||
// qoi_serializer.h | ||
// DARMA/vt-tv => Virtual Transport -- Task Visualizer | ||
// | ||
// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC | ||
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. | ||
// Government retains certain rights in this software. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// | ||
// * Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// | ||
// * Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// | ||
// * Neither the name of the copyright holder nor the names of its | ||
// contributors may be used to endorse or promote products derived from this | ||
// software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
// Questions? Contact [email protected] | ||
// | ||
// ***************************************************************************** | ||
//@HEADER | ||
*/ | ||
|
||
#if !defined INCLUDED_VT_TV_API_QOI_SERIALIZER_H | ||
#define INCLUDED_VT_TV_API_QOI_SERIALIZER_H | ||
|
||
#include "vt-tv/api/types.h" | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <variant> | ||
|
||
namespace nlohmann | ||
{ | ||
template <> | ||
struct adl_serializer<::vt::tv::QOIVariantTypes> { | ||
using VariantTypes = ::vt::tv::QOIVariantTypes; | ||
|
||
// Produce compilation error if variant types were modified | ||
static_assert(std::is_same_v<int, std::variant_alternative_t<0, VariantTypes>>); | ||
static_assert(std::is_same_v<double, std::variant_alternative_t<1, VariantTypes>>); | ||
static_assert(std::is_same_v<std::string, std::variant_alternative_t<2, VariantTypes>>); | ||
|
||
static void to_json(json &j, const VariantTypes &value) { | ||
std::visit([&](auto const &arg) | ||
{ j = arg; }, | ||
value); | ||
} | ||
|
||
static void from_json(const json &j, VariantTypes &value) { | ||
if (j.is_number_integer()) { | ||
value = j.get<int>(); | ||
} else if (j.is_number_float()) { | ||
value = j.get<double>(); | ||
} else if (j.is_string()) { | ||
value = j.get<std::string>(); | ||
} | ||
} | ||
}; | ||
|
||
} /* end namespace nlohmann */ | ||
|
||
#endif /* INCLUDED_VT_TV_API_QOI_SERIALIZER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
"metadata": { | ||
"rank": 0, | ||
"shared_node": { | ||
"id": 0, | ||
"num_nodes": 1, | ||
"rank": 0, | ||
"size": 4 | ||
}, | ||
"type": "LBDatafile", | ||
"attributes": { | ||
"intSample": 1, | ||
"doubleSample": 2.213, | ||
"stringSample": "abc" | ||
} | ||
}, | ||
"phases": [ | ||
{ | ||
"communications": [ | ||
{ | ||
"bytes": 112.0, | ||
"from": { | ||
"home": 0, | ||
"id": 0, | ||
"migratable": false, | ||
"type": "object" | ||
}, | ||
"messages": 2, | ||
"to": { | ||
"home": 1, | ||
"id": 5, | ||
"migratable": false, | ||
"type": "object" | ||
}, | ||
"type": "SendRecv" | ||
} | ||
], | ||
"id": 0, | ||
"tasks": [ | ||
{ | ||
"entity": { | ||
"collection_id": 7, | ||
"home": 0, | ||
"id": 3407875, | ||
"index": [ | ||
12 | ||
], | ||
"migratable": true, | ||
"type": "object" | ||
}, | ||
"node": 0, | ||
"resource": "cpu", | ||
"subphases": [ | ||
{ | ||
"id": 0, | ||
"time": 1.1263000033068238e-05 | ||
}, | ||
{ | ||
"id": 1, | ||
"time": 1.1333999964335817e-05 | ||
}, | ||
{ | ||
"id": 2, | ||
"time": 1.1196000059499056e-05 | ||
} | ||
], | ||
"time": 3.379300005690311e-05, | ||
"user_defined": { | ||
"isSample": 1 | ||
}, | ||
"attributes": { | ||
"intSample": -100, | ||
"doubleSample": 0.0, | ||
"stringSample": "" | ||
} | ||
} | ||
], | ||
"user_defined": { | ||
"isSample": 1 | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.