ndn::io Namespace Reference

Namespaces

 detail
 

Classes

class  Error
 

Enumerations

enum  IoEncoding {
  NO_ENCODING ,
  BASE64 ,
  HEX
}
 Indicates how a file or stream of bytes is encoded. More...
 

Functions

template<typename T >
shared_ptr< T > load (const std::string &filename, IoEncoding encoding=BASE64)
 Reads a TLV element from a file. More...
 
template<typename T >
shared_ptr< T > load (std::istream &is, IoEncoding encoding=BASE64)
 Reads a TLV element from a stream. More...
 
shared_ptr< BufferloadBuffer (std::istream &is, IoEncoding encoding=BASE64)
 Reads bytes from a stream until EOF. More...
 
template<typename T >
loadTlv (std::istream &is, IoEncoding encoding=BASE64)
 Reads a TLV element of type T from a stream. More...
 
template<typename T >
void save (const T &obj, const std::string &filename, IoEncoding encoding=BASE64)
 Writes a TLV element to a file. More...
 
template<typename T >
void save (const T &obj, std::ostream &os, IoEncoding encoding=BASE64)
 Writes a TLV element to a stream. More...
 
void saveBuffer (span< const uint8_t > buf, std::ostream &os, IoEncoding encoding=BASE64)
 Writes a sequence of bytes to a stream. More...
 

Enumeration Type Documentation

◆ IoEncoding

Indicates how a file or stream of bytes is encoded.

Enumerator
NO_ENCODING 

Raw binary, without encoding.

BASE64 

Base64 encoding.

save() inserts a newline after every 64 characters, load() can accept base64 text with or without newlines.

HEX 

Hexadecimal encoding.

save() uses uppercase letters A-F, load() can accept mixed-case.

Definition at line 40 of file io.hpp.

Function Documentation

◆ load() [1/2]

template<typename T >
shared_ptr<T> ndn::io::load ( const std::string &  filename,
IoEncoding  encoding = BASE64 
)

Reads a TLV element from a file.

Template Parameters
TType of TLV element; T must be WireDecodable and the nested type T::Error, if defined, must be a subclass of ndn::tlv::Error.
Returns
The TLV element, or nullptr if an error occurs.
Note
This function has a peculiar error handling behavior. Consider using loadTlv() instead.

Definition at line 151 of file io.hpp.

◆ load() [2/2]

template<typename T >
shared_ptr<T> ndn::io::load ( std::istream &  is,
IoEncoding  encoding = BASE64 
)

Reads a TLV element from a stream.

Template Parameters
TType of TLV element; T must be WireDecodable and the nested type T::Error, if defined, must be a subclass of ndn::tlv::Error.
Returns
The TLV element, or nullptr if an error occurs.
Note
This function has a peculiar error handling behavior. Consider using loadTlv() instead.

Definition at line 118 of file io.hpp.

◆ loadBuffer()

shared_ptr< Buffer > ndn::io::loadBuffer ( std::istream &  is,
IoEncoding  encoding = BASE64 
)

Reads bytes from a stream until EOF.

Returns
A Buffer containing the bytes read from the stream.
Exceptions
ErrorAn error occurred, e.g., malformed input.
std::invalid_argumentThe specified encoding is not supported.

Definition at line 36 of file io.cpp.

◆ loadTlv()

template<typename T >
T ndn::io::loadTlv ( std::istream &  is,
IoEncoding  encoding = BASE64 
)

Reads a TLV element of type T from a stream.

Template Parameters
TClass type representing the TLV element; must be WireDecodable.
Returns
The parsed TLV element.
Exceptions
ErrorAn error occurred, e.g., malformed input.
std::invalid_argumentThe specified encoding is not supported.

Definition at line 96 of file io.hpp.

◆ save() [1/2]

template<typename T >
void ndn::io::save ( const T &  obj,
const std::string &  filename,
IoEncoding  encoding = BASE64 
)

Writes a TLV element to a file.

Template Parameters
Ttype of TLV element; T must be WireEncodable and the nested type T::Error, if defined, must be a subclass of ndn::tlv::Error
Exceptions
Errorerror during encoding or saving
std::invalid_argumentthe specified encoding is not supported

Definition at line 197 of file io.hpp.

◆ save() [2/2]

template<typename T >
void ndn::io::save ( const T &  obj,
std::ostream &  os,
IoEncoding  encoding = BASE64 
)

Writes a TLV element to a stream.

Template Parameters
Ttype of TLV element; T must be WireEncodable and the nested type T::Error, if defined, must be a subclass of ndn::tlv::Error
Exceptions
Errorerror during encoding or saving
std::invalid_argumentthe specified encoding is not supported

Definition at line 173 of file io.hpp.

◆ saveBuffer()

void ndn::io::saveBuffer ( span< const uint8_t >  buf,
std::ostream &  os,
IoEncoding  encoding = BASE64 
)

Writes a sequence of bytes to a stream.

Exceptions
Errorerror during saving
std::invalid_argumentthe specified encoding is not supported

Definition at line 62 of file io.cpp.