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_convertible<typename T::Error*, tlv::Error*>::value,
67 "T::Error, if defined, must be a subclass of ndn::tlv::Error");
103 detail::checkInnerError<T>(
nullptr);
111 return make_shared<T>(*block);
127 std::ifstream is(filename);
128 return load<T>(is, encoding);
156 detail::checkInnerError<T>(
nullptr);
160 block = obj.wireEncode();
179 std::ofstream os(filename);
180 save(obj, os, encoding);
186 #endif // NDN_UTIL_IO_HPP optional< Block > loadBlock(std::istream &is, IoEncoding encoding)
Reads a TLV block from a stream.
#define NDN_THROW_NESTED(e)
void saveBlock(const Block &block, std::ostream &os, IoEncoding encoding)
Writes a TLV block to a stream.
shared_ptr< T > load(std::istream &is, IoEncoding encoding=BASE64)
Reads a TLV element from a stream.
void save(const T &obj, std::ostream &os, IoEncoding encoding=BASE64)
Writes a TLV element to a stream.
Represents a TLV element of NDN packet format.
void saveBuffer(const uint8_t *buf, size_t size, std::ostream &os, IoEncoding encoding)
Writes a byte buffer to a stream.
Raw binary, without encoding.
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
shared_ptr< Buffer > loadBuffer(std::istream &is, IoEncoding encoding)
Reads bytes from a stream until EOF.
IoEncoding
Indicates how a file or stream of bytes is encoded.