22 #ifndef NDN_UTIL_IO_HPP 23 #define NDN_UTIL_IO_HPP 26 #include "../encoding/block.hpp" 34 class Error :
public std::runtime_error
39 :
std::runtime_error(what)
73 static_assert(std::is_base_of<tlv::Error, typename T::Error>::value,
74 "T::Error, if declared, must inherit from ndn::tlv::Error");
103 detail::checkInnerError<T>(
nullptr);
111 return make_shared<T>(*block);
124 std::ifstream is(filename);
125 return load<T>(is, encoding);
144 detail::checkInnerError<T>(
nullptr);
148 block = obj.wireEncode();
151 BOOST_THROW_EXCEPTION(
Error(e.what()));
163 std::ofstream os(filename);
164 save(obj, os, encoding);
170 #endif // NDN_UTIL_IO_HPP optional< Block > loadBlock(std::istream &is, IoEncoding encoding)
loads a TLV block from a stream
void saveBlock(const Block &block, std::ostream &os, IoEncoding encoding)
saves a TLV block to a stream
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< T > load(std::istream &is, IoEncoding encoding=BASE64)
loads a TLV element from a stream
void save(const T &obj, std::ostream &os, IoEncoding encoding=BASE64)
saves a TLV element to a stream
Class representing a wire element of NDN-TLV packet format.
Error(const std::string &what)
static void checkInnerError(...)
a concept check for TLV abstraction with .wireEncode method
constexpr IoEncoding DEPRECATED(BASE_64)
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
represents an error in TLV encoding or decoding
IoEncoding
indicates how a file or stream is encoded