22 #ifndef NDN_UTIL_IO_HPP 23 #define NDN_UTIL_IO_HPP 33 class Error :
public std::runtime_error
36 using std::runtime_error::runtime_error;
66 static_assert(std::is_base_of<tlv::Error, typename T::Error>::value,
67 "T::Error, if declared, must inherit from ndn::tlv::Error");
96 detail::checkInnerError<T>(
nullptr);
98 optional<Block> block =
loadBlock(is, encoding);
104 return make_shared<T>(*block);
117 std::ifstream is(filename);
118 return load<T>(is, encoding);
137 detail::checkInnerError<T>(
nullptr);
141 block = obj.wireEncode();
156 std::ofstream os(filename);
157 save(obj, os, encoding);
163 #endif // NDN_UTIL_IO_HPP optional< Block > loadBlock(std::istream &is, IoEncoding encoding)
loads a TLV block from a stream
#define NDN_THROW_NESTED(e)
void saveBlock(const Block &block, std::ostream &os, IoEncoding encoding)
saves a TLV block to a stream
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
Represents a TLV element of NDN packet format.
static void checkInnerError(...)
a concept check for TLV abstraction with .wireEncode method
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