22 #ifndef NDN_UTIL_IO_HPP 23 #define NDN_UTIL_IO_HPP 26 #include "../encoding/block.hpp" 33 class Error :
public std::runtime_error
38 :
std::runtime_error(what)
70 static_assert(std::is_base_of<tlv::Error, typename T::Error>::value,
71 "T::Error, if declared, must inherit from ndn::tlv::Error");
100 detail::checkInnerError<T>(
nullptr);
108 return make_shared<T>(*block);
121 std::ifstream is(filename);
122 return load<T>(is, encoding);
141 detail::checkInnerError<T>(
nullptr);
145 block = obj.wireEncode();
148 BOOST_THROW_EXCEPTION(
Error(e.what()));
160 std::ofstream os(filename);
161 save(obj, os, encoding);
167 #endif // NDN_UTIL_IO_HPP optional< Block > loadBlock(std::istream &is, IoEncoding encoding)
loads a TLV block from a stream
static void checkInnerError(typename T::Error *)
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
Represents a TLV element of NDN packet format.
Error(const std::string &what)
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