6 #ifndef NDN_UTIL_IO_HPP
7 #define NDN_UTIL_IO_HPP
9 #include "../common.hpp"
11 #include "../encoding/block.hpp"
16 #include "../security/cryptopp.hpp"
22 class Error :
public std::runtime_error
27 : std::runtime_error(what)
42 typedef typename T::Error TypeError;
45 using namespace CryptoPP;
47 shared_ptr<T>
object = make_shared<T>();
55 FileSource ss(is,
true,
new FileSink(os));
60 FileSource ss(is,
true,
new Base64Decoder(
new FileSink(os)));
65 FileSource ss(is,
true,
new HexDecoder(
new FileSink(os)));
69 return shared_ptr<T>();
72 object->wireDecode(
Block(os.buf()));
75 catch (CryptoPP::Exception& e)
77 return shared_ptr<T>();
81 return shared_ptr<T>();
85 return shared_ptr<T>();
93 std::ifstream is(file.c_str());
94 return load<T>(is, encoding);
101 typedef typename T::Error TypeError;
104 using namespace CryptoPP;
106 Block block =
object.wireEncode();
112 StringSource ss(block.wire(), block.size(),
true,
118 StringSource ss(block.wire(), block.size(),
true,
119 new Base64Encoder(
new FileSink(os),
true, 64));
124 StringSource ss(block.wire(), block.size(),
true,
125 new HexEncoder(
new FileSink(os)));
133 catch (CryptoPP::Exception& e)
135 throw Error(e.what());
139 throw Error(e.what());
143 throw Error(e.what());
151 std::ofstream os(file.c_str());
152 save(
object, os, encoding);
158 #endif // NDN_UTIL_IO_HPP
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
Class representing wire element of the NDN packet.
shared_ptr< T > load(std::istream &is, IoEncoding encoding=BASE_64)
Error(const std::string &what)
void save(const T &object, std::ostream &os, IoEncoding encoding=BASE_64)