22 #ifndef NDN_CXX_UTIL_IO_HPP
23 #define NDN_CXX_UTIL_IO_HPP
34 class Error :
public std::runtime_error
37 using std::runtime_error::runtime_error;
65 checkNestedError(
typename T::Error*)
67 static_assert(std::is_convertible<typename T::Error*, tlv::Error*>::value,
68 "T::Error, if defined, must be a subclass of ndn::tlv::Error");
104 return T(
Block(buf));
106 catch (
const std::exception& e) {
123 detail::checkNestedError<T>(
nullptr);
129 catch (
const std::invalid_argument&) {
132 catch (
const std::runtime_error&) {
137 return make_shared<T>(block);
155 std::ifstream is(filename);
156 return load<T>(is, encoding);
178 detail::checkNestedError<T>(
nullptr);
182 block = obj.wireEncode();
201 std::ofstream os(filename);
202 save(obj, os, encoding);
Represents a TLV element of the NDN packet format.
const uint8_t * wire() const
Return a raw pointer to the beginning of the encoded wire.
size_t size() const
Return the size of the encoded wire, i.e.
a concept check for TLV abstraction with .wireDecode method and constructible from Block
a concept check for TLV abstraction with .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.