19 : m_type(std::numeric_limits<uint32_t>::max())
24 : m_buffer(buffer.m_buffer)
25 , m_begin(buffer.begin())
27 , m_size(m_end - m_begin)
36 throw Tlv::Error(
"TLV length doesn't match buffer length");
42 const Buffer::const_iterator& begin,
const Buffer::const_iterator& end,
43 const Buffer::const_iterator& valueBegin,
const Buffer::const_iterator& valueEnd)
48 , m_size(m_end - m_begin)
49 , m_value_begin(valueBegin)
50 , m_value_end(valueEnd)
56 , m_begin(m_buffer->begin())
57 , m_end(m_buffer->end())
58 , m_size(m_end - m_begin)
68 throw Tlv::Error(
"TLV length doesn't match buffer length");
73 const Buffer::const_iterator& begin,
const Buffer::const_iterator& end,
78 , m_size(m_end - m_begin)
89 throw Tlv::Error(
"TLV length doesn't match buffer length");
96 std::istream_iterator<uint8_t> tmp_begin(is);
97 std::istream_iterator<uint8_t> tmp_end;
109 char* buf =
new char[length];
111 is.read(buf+1, length-1);
113 if (length != static_cast<uint64_t>(is.gcount()) + 1)
116 throw Tlv::Error(
"Not enough data in the buffer to fully parse TLV");
119 os.write(buf, length);
135 const uint8_t* tmp_begin = buffer;
136 const uint8_t* tmp_end = buffer + maxlength;
141 if (length > static_cast<uint64_t>(tmp_end - tmp_begin))
143 throw Tlv::Error(
"Not enough data in the buffer to fully parse TLV");
146 m_buffer = ptr_lib::make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
158 const uint8_t* buffer =
reinterpret_cast<const uint8_t*
>(bufferX);
160 const uint8_t* tmp_begin = buffer;
161 const uint8_t* tmp_end = buffer + maxlength;
166 if (length > static_cast<uint64_t>(tmp_end - tmp_begin))
168 throw Tlv::Error(
"Not enough data in the buffer to fully parse TLV");
171 m_buffer = ptr_lib::make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
189 , m_begin(m_buffer->end())
190 , m_end(m_buffer->end())
191 , m_value_begin(m_buffer->begin())
192 , m_value_end(m_buffer->end())
198 : m_buffer(value.m_buffer)
200 , m_begin(m_buffer->end())
201 , m_end(m_buffer->end())
202 , m_value_begin(value.begin())
203 , m_value_end(value.end())
211 Buffer::const_iterator tempBegin = wire->begin() + offset;
223 if (length > static_cast<uint64_t>(wire->end() - tempBegin))
228 block =
Block(wire, type,
229 wire->begin() + offset, tempBegin + length,
230 tempBegin, tempBegin + length);
238 const uint8_t* tempBegin = buffer;
239 const uint8_t* tempEnd = buffer + maxSize;
251 if (length > static_cast<uint64_t>(tempEnd - tempBegin))
256 BufferPtr sharedBuffer = make_shared<Buffer>(buffer, tempBegin + length);
257 block =
Block(sharedBuffer, type,
258 sharedBuffer->begin(), sharedBuffer->end(),
259 sharedBuffer->begin() + (tempBegin - buffer), sharedBuffer->end());
275 Buffer::const_iterator element_begin =
begin;
280 if (length > static_cast<uint64_t>(end - begin))
283 throw Tlv::Error(
"TLV length exceeds buffer length");
285 Buffer::const_iterator element_end = begin + length;
289 element_begin, element_end,
290 begin, element_end));
317 size_t valueSize = 0;
319 valueSize += i->size();
326 os.write(reinterpret_cast<const char*>(i->wire()), i->size());
327 else if (i->hasValue()) {
330 os.write(reinterpret_cast<const char*>(i->value()), i->value_size());
333 throw Error(
"Underlying value buffer is empty");
355 throw Error(
"Underlying value buffer is empty");
360 Buffer::const_iterator element_begin =
begin;
365 if (length != static_cast<uint64_t>(
end - begin))
366 throw Tlv::Error(
"TLV length mismatches buffer length");
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
bool hasValue() const
Check if the Block has value block (no type and length are encoded)
size_t writeVarNumber(std::ostream &os, uint64_t varNumber)
Write VAR-NUMBER to the specified stream.
size_t sizeOfVarNumber(uint64_t varNumber)
Get number of bytes necessary to hold value of VAR-NUMBER.
Buffer::const_iterator end() const
Buffer::const_iterator m_begin
bool readVarNumber(InputIterator &begin, const InputIterator &end, uint64_t &number)
Read VAR-NUMBER in NDN-TLV encoding.
ptr_lib::shared_ptr< Buffer > BufferPtr
Class representing wire element of the NDN packet.
Buffer::const_iterator value_begin() const
Buffer::const_iterator value_end() const
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
Buffer::const_iterator m_value_end
Block blockFromValue() const
ptr_lib::shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
element_container::const_iterator element_const_iterator
size_t value_size() const
void parse() const
Parse wire buffer into subblocks.
void encode()
Encode subblocks into wire buffer.
element_container m_subBlocks
Buffer::const_iterator m_end
bool hasWire() const
Check if the Block has fully encoded wire.
static bool fromBuffer(const ConstBufferPtr &wire, size_t offset, Block &block)
Try to construct block from Buffer, referencing data block pointed by wire.
const uint8_t * value() const
bool readType(InputIterator &begin, const InputIterator &end, uint32_t &type)
Read TLV Type.
Buffer::const_iterator m_value_begin
Block()
Default constructor to create an empty Block.
Error that can be thrown from Block.
Buffer::const_iterator begin() const