NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
ndnSIM
ndnSIM documentation
All Attributes
All GlobalValues
All LogComponents
All TraceSources
Todo List
Deprecated List
Modules
Namespaces
Classes
Files
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
io.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
#include "
io.hpp
"
23
#include "../encoding/buffer-stream.hpp"
24
#include "../security/transform.hpp"
25
26
namespace
ndn
{
27
namespace
io {
28
29
optional<Block>
30
loadBlock
(std::istream& is,
IoEncoding
encoding)
31
{
32
namespace
t =
ndn::security::transform
;
33
34
OBufferStream
os;
35
try
{
36
switch
(encoding) {
37
case
NO_ENCODING
:
38
t::streamSource
(is) >>
t::streamSink
(os);
39
break
;
40
case
BASE64
:
41
t::streamSource
(is) >>
t::stripSpace
(
"\n"
) >>
t::base64Decode
(
false
) >>
t::streamSink
(os);
42
break
;
43
case
HEX
:
44
t::streamSource
(is) >>
t::hexDecode
() >>
t::streamSink
(os);
45
break
;
46
default
:
47
return
nullopt
;
48
}
49
}
50
catch
(
const
t::Error&) {
51
return
nullopt
;
52
}
53
54
try
{
55
return
make_optional<Block>(os.
buf
());
56
}
57
catch
(
const
tlv::Error
&) {
58
return
nullopt
;
59
}
60
}
61
62
void
63
saveBlock
(
const
Block
& block, std::ostream& os,
IoEncoding
encoding)
64
{
65
namespace
t =
ndn::security::transform
;
66
67
try
{
68
switch
(encoding) {
69
case
NO_ENCODING
:
70
t::bufferSource
(block.
wire
(), block.
size
()) >>
t::streamSink
(os);
71
break
;
72
case
BASE64
:
73
t::bufferSource
(block.
wire
(), block.
size
()) >>
t::base64Encode
() >>
t::streamSink
(os);
74
break
;
75
case
HEX
:
76
t::bufferSource
(block.
wire
(), block.
size
()) >>
t::hexEncode
(
true
) >>
t::streamSink
(os);
77
break
;
78
default
:
79
BOOST_THROW_EXCEPTION(
Error
(
"unrecognized IoEncoding"
));
80
}
81
}
82
catch
(
const
t::Error& e) {
83
BOOST_THROW_EXCEPTION(
Error
(e.what()));
84
}
85
}
86
87
}
// namespace io
88
}
// namespace ndn
ndn::io::loadBlock
optional< Block > loadBlock(std::istream &is, IoEncoding encoding)
loads a TLV block from a stream
Definition:
io.cpp:30
ndn::nullopt
constexpr nullopt_t nullopt
Definition:
backports-optional.hpp:108
ndn::io::saveBlock
void saveBlock(const Block &block, std::ostream &os, IoEncoding encoding)
saves a TLV block to a stream
Definition:
io.cpp:63
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
io.hpp
ndn::security::transform::base64Decode
unique_ptr< Transform > base64Decode(bool expectNewlineEvery64Bytes)
Definition:
base64-decode.cpp:129
ndn::security::transform::hexEncode
unique_ptr< Transform > hexEncode(bool useUpperCase)
Definition:
hex-encode.cpp:69
ndn::io::Error
Definition:
io.hpp:33
ndn::optional
Definition:
backports-optional.hpp:93
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:42
ndn::security::transform::stripSpace
unique_ptr< Transform > stripSpace(const char *whitespaces)
constructs a StripSpace transform
Definition:
strip-space.cpp:55
ndn::Block::size
size_t size() const
Get size of encoded wire, including Type-Length-Value.
Definition:
block.cpp:299
ndn::security::transform
Definition:
security-common.hpp:142
ndn::io::HEX
hexadecimal encoding
Definition:
io.hpp:61
ndn::io::NO_ENCODING
binary without encoding
Definition:
io.hpp:48
ndn::security::transform::streamSink
unique_ptr< Sink > streamSink(std::ostream &os)
Definition:
stream-sink.cpp:53
ndn::security::transform::bufferSource
BufferSource bufferSource
Definition:
buffer-source.hpp:73
ndn::security::transform::hexDecode
unique_ptr< Transform > hexDecode()
Definition:
hex-decode.cpp:111
ndn::OBufferStream::buf
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Definition:
buffer-stream.cpp:54
ndn::Block::wire
const uint8_t * wire() const
Get pointer to encoded wire.
Definition:
block.cpp:290
ndn::OBufferStream
implements an output stream that constructs ndn::Buffer
Definition:
buffer-stream.hpp:70
ndn::io::BASE64
base64 encoding
Definition:
io.hpp:55
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition:
tlv.hpp:50
ndn::security::transform::streamSource
StreamSource streamSource
Definition:
stream-source.hpp:62
ndn::security::transform::base64Encode
unique_ptr< Transform > base64Encode(bool needBreak)
Definition:
base64-encode.cpp:129
ndn::io::IoEncoding
IoEncoding
indicates how a file or stream is encoded
Definition:
io.hpp:45
ndnSIM
ndn-cxx
src
util
io.cpp
Generated on Thu Nov 2 2017 03:30:29 for ndnSIM by
1.8.11