1#ifndef NDNPH_CLI_IO_HPP
2#define NDNPH_CLI_IO_HPP
4#include "../tlv/decoder.hpp"
5#include "../tlv/encoder.hpp"
13template<
typename T,
int bufferSize = 4096>
15input(
Region& region, T& target, std::istream& is = std::cin) {
16 uint8_t* buffer = region.
alloc(bufferSize);
17 if (buffer ==
nullptr) {
18 fprintf(stderr,
"ndnph::cli::input alloc error\n");
21 is.read(
reinterpret_cast<char*
>(buffer), bufferSize);
24 fprintf(stderr,
"ndnph::cli::input decode error\n");
31template<
typename Encodable,
int bufferSize = 65536>
33output(
const Encodable& packet, std::ostream& os = std::cout) {
37 fprintf(stderr,
"ndnph::cli::output encode error\n");
40 os.write(
reinterpret_cast<const char*
>(encoder.
begin()), encoder.
size());
33output(
const Encodable& packet, std::ostream& os = std::cout) {
…}
TLV decoder.
Definition decoder.hpp:10
bool decode(T &target) const
Decode first TLV into target object.
Definition decoder.hpp:158
TLV encoder that accepts items in reverse order.
Definition encoder.hpp:10
bool prepend(const First &first, const Arg &... arg)
Prepend a sequence of values.
Definition encoder.hpp:123
const uint8_t * begin() const
Get output begin.
Definition encoder.hpp:34
size_t size() const
Get output size.
Definition encoder.hpp:44
Region-based memory allocator thats owns memory of NDNph objects.
Definition region.hpp:9
uint8_t * alloc(size_t size)
Allocate a buffer with no alignment requirement.
Definition region.hpp:27
Region with statically allocated memory.
Definition region.hpp:143
bool input(Region ®ion, T &target, std::istream &is=std::cin)
Read and decode from input stream.
Definition io.hpp:15
void output(const Encodable &packet, std::ostream &os=std::cout)
Write an Encodable to output stream.
Definition io.hpp:33