22 #ifndef NDN_CXX_UTIL_IO_HPP
23 #define NDN_CXX_UTIL_IO_HPP
32 class Error :
public std::runtime_error
35 using std::runtime_error::runtime_error;
63 checkNestedError(
typename T::Error*)
65 static_assert(std::is_convertible_v<typename T::Error*, tlv::Error*>,
66 "T::Error, if defined, must be a subclass of ndn::tlv::Error");
102 return T(
Block(buf));
104 catch (
const std::exception& e) {
121 detail::checkNestedError<T>(
nullptr);
127 catch (
const std::invalid_argument&) {
130 catch (
const std::runtime_error&) {
135 return make_shared<T>(block);
153 std::ifstream is(filename);
154 return load<T>(is, encoding);
176 detail::checkNestedError<T>(
nullptr);
180 block = obj.wireEncode();
199 std::ofstream os(filename);
200 save(obj, os, encoding);
Represents a TLV element of the NDN packet format.
A concept check for TLV abstraction with a wireDecode(Block) method and constructible from Block.
A concept check for TLV abstraction with a wireEncode() method.
Represents an error in TLV encoding or decoding.
#define NDN_THROW_NESTED(e)
T loadTlv(std::istream &is, IoEncoding encoding=BASE64)
Reads a TLV element of type T from a stream.
void save(const T &obj, std::ostream &os, IoEncoding encoding=BASE64)
Writes a TLV element to a stream.
shared_ptr< T > load(std::istream &is, IoEncoding encoding=BASE64)
Reads a TLV element from a stream.
void saveBuffer(span< const uint8_t > buf, std::ostream &os, IoEncoding encoding)
Writes a sequence of bytes to a stream.
IoEncoding
Indicates how a file or stream of bytes is encoded.
@ NO_ENCODING
Raw binary, without encoding.
@ HEX
Hexadecimal encoding.
shared_ptr< Buffer > loadBuffer(std::istream &is, IoEncoding encoding)
Reads bytes from a stream until EOF.