You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

serdes.h 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_SERDES_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_SERDES_H_
  18. #include <fstream>
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. #include <nlohmann/json.hpp>
  23. #include "minddata/dataset/engine/ir/datasetops/dataset_node.h"
  24. #include "minddata/dataset/util/status.h"
  25. namespace mindspore {
  26. namespace dataset {
  27. /// \brief The Serdes class is used to serialize an IR tree into JSON string and dump into file if file name
  28. /// specified.
  29. class Serdes {
  30. public:
  31. /// \brief Constructor
  32. Serdes() {}
  33. /// \brief default destructor
  34. ~Serdes() = default;
  35. /// \brief function to serialize IR tree into JSON string and/or JSON file
  36. /// \param[in] node IR node to be transferred
  37. /// \param[in] filename The file name. If specified, save the generated JSON string into the file
  38. /// \param[out] out_json The result json string
  39. /// \return Status The status code returned
  40. Status SaveToJSON(std::shared_ptr<DatasetNode> node, const std::string &filename, nlohmann::json *out_json);
  41. protected:
  42. /// \brief Helper function to save JSON to a file
  43. /// \param[in] json_string The JSON string to be saved to the file
  44. /// \param[in] file_name The file name
  45. /// \return Status The status code returned
  46. Status SaveJSONToFile(nlohmann::json json_string, const std::string &file_name);
  47. };
  48. } // namespace dataset
  49. } // namespace mindspore
  50. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_SERDES_H_