/* * Copyright (c) 2011 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include #include #include #include #include #include using namespace Swift; PayloadPersister::PayloadPersister() { } PayloadPersister::~PayloadPersister() { } void PayloadPersister::savePayload(boost::shared_ptr payload, const boost::filesystem::path& path) { if (!boost::filesystem::exists(path.parent_path())) { try { boost::filesystem::create_directories(path.parent_path()); } catch (const boost::filesystem::filesystem_error& e) { std::cerr << "ERROR: " << e.what() << std::endl; } } boost::filesystem::ofstream file(path); file << getSerializer()->serialize(payload); file.close(); } boost::shared_ptr PayloadPersister::loadPayload(const boost::filesystem::path& path) { if (boost::filesystem::exists(path)) { ByteArray data; readByteArrayFromFile(data, path.string()); boost::shared_ptr parser(createParser()); PayloadParserTester tester(parser.get()); tester.parse(byteArrayToString(data)); return parser->getPayload(); } else { return boost::shared_ptr(); } }