22#ifndef NDN_CXX_UTIL_IO_HPP
23#define NDN_CXX_UTIL_IO_HPP
32class Error :
public std::runtime_error
35 using std::runtime_error::runtime_error;
69 static_assert(std::is_convertible_v<typename T::Error*, tlv::Error*>,
70 "T::Error, if defined, must be a subclass of ndn::tlv::Error");
106 return T(
Block(buf));
108 catch (
const std::exception& e) {
121[[deprecated(
"use loadTlv")]]
126 detail::checkNestedError<T>(
nullptr);
132 catch (
const std::invalid_argument&) {
135 catch (
const std::runtime_error&) {
140 return make_shared<T>(block);
155[[deprecated(
"use loadTlv")]]
159 std::ifstream is(filename);
160 return load<T>(is, encoding);
185 block = obj.wireEncode();
187 catch (
const std::exception& e) {
202[[deprecated(
"use saveTlv")]]
207 detail::checkNestedError<T>(
nullptr);
211 block = obj.wireEncode();
228[[deprecated(
"use saveTlv")]]
232 std::ofstream os(filename);
233 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)
constexpr void checkNestedError(typename T::Error *)
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.
void saveBuffer(span< const uint8_t > buf, std::ostream &os, IoEncoding encoding)
Writes a sequence of bytes to a stream.
shared_ptr< T > load(std::istream &is, IoEncoding encoding=BASE64)
Reads a TLV element from a stream.
void saveTlv(const T &obj, std::ostream &os, IoEncoding encoding=BASE64)
Writes a TLV element of type T 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.