Browse Source
Breaks: nfd:commit:c0273e3505ac2ccf843401be77a513d8eb663127 Breaks: ChronoSync:commit:e042f83a1df184a8e7a90ef00034d11026891cd1 Change-Id: I8275c6276c5ecfa280f87f584189907521febf5f Refs: #2494, #2490pull/2/head
52 changed files with 1777 additions and 916 deletions
@ -0,0 +1,283 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2013-2015 Regents of the University of California. |
||||
* |
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
||||
* |
||||
* ndn-cxx library is free software: you can redistribute it and/or modify it under the |
||||
* terms of the GNU Lesser General Public License as published by the Free Software |
||||
* Foundation, either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received copies of the GNU General Public License and GNU Lesser |
||||
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
||||
* <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
||||
*/ |
||||
|
||||
#include "encoder.hpp" |
||||
|
||||
namespace ndn { |
||||
namespace encoding { |
||||
|
||||
Encoder::Encoder(size_t totalReserve/* = 8800*/, size_t reserveFromBack/* = 400*/) |
||||
: m_buffer(new Buffer(totalReserve)) |
||||
{ |
||||
m_begin = m_end = m_buffer->end() - (reserveFromBack < totalReserve ? reserveFromBack : 0); |
||||
} |
||||
|
||||
|
||||
Encoder::Encoder(const Block& block) |
||||
: m_buffer(const_pointer_cast<Buffer>(block.getBuffer())) |
||||
, m_begin(m_buffer->begin() + (block.begin() - m_buffer->begin())) |
||||
, m_end(m_buffer->begin() + (block.end() - m_buffer->begin())) |
||||
{ |
||||
} |
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void |
||||
Encoder::reserveBack(size_t size) |
||||
{ |
||||
if ((m_end + size) > m_buffer->end()) |
||||
reserve(m_buffer->size() * 2 + size, false); |
||||
} |
||||
|
||||
void |
||||
Encoder::reserveFront(size_t size) |
||||
{ |
||||
if ((m_buffer->begin() + size) > m_begin) |
||||
reserve(m_buffer->size() * 2 + size, true); |
||||
} |
||||
|
||||
|
||||
Block |
||||
Encoder::block(bool verifyLength/* = true*/) const |
||||
{ |
||||
return Block(m_buffer, |
||||
m_begin, m_end, |
||||
verifyLength); |
||||
} |
||||
|
||||
void |
||||
Encoder::reserve(size_t size, bool addInFront) |
||||
{ |
||||
if (size < m_buffer->size()) { |
||||
size = m_buffer->size(); |
||||
} |
||||
|
||||
if (addInFront) { |
||||
size_t diffEnd = m_buffer->end() - m_end; |
||||
size_t diffBegin = m_buffer->end() - m_begin; |
||||
|
||||
Buffer* buf = new Buffer(size); |
||||
std::copy_backward(m_buffer->begin(), m_buffer->end(), buf->end()); |
||||
|
||||
m_buffer.reset(buf); |
||||
|
||||
m_end = m_buffer->end() - diffEnd; |
||||
m_begin = m_buffer->end() - diffBegin; |
||||
} |
||||
else { |
||||
size_t diffEnd = m_end - m_buffer->begin(); |
||||
size_t diffBegin = m_begin - m_buffer->begin(); |
||||
|
||||
Buffer* buf = new Buffer(size); |
||||
std::copy(m_buffer->begin(), m_buffer->end(), buf->begin()); |
||||
|
||||
m_buffer.reset(buf); |
||||
|
||||
m_end = m_buffer->begin() + diffEnd; |
||||
m_begin = m_buffer->begin() + diffBegin; |
||||
} |
||||
} |
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
size_t |
||||
Encoder::prependByte(uint8_t value) |
||||
{ |
||||
reserveFront(1); |
||||
|
||||
m_begin--; |
||||
*m_begin = value; |
||||
return 1; |
||||
} |
||||
|
||||
size_t |
||||
Encoder::appendByte(uint8_t value) |
||||
{ |
||||
reserveBack(1); |
||||
|
||||
*m_end = value; |
||||
m_end++; |
||||
return 1; |
||||
} |
||||
|
||||
|
||||
size_t |
||||
Encoder::prependByteArray(const uint8_t* array, size_t length) |
||||
{ |
||||
reserveFront(length); |
||||
|
||||
m_begin -= length; |
||||
std::copy(array, array + length, m_begin); |
||||
return length; |
||||
} |
||||
|
||||
size_t |
||||
Encoder::appendByteArray(const uint8_t* array, size_t length) |
||||
{ |
||||
reserveBack(length); |
||||
|
||||
std::copy(array, array + length, m_end); |
||||
m_end += length; |
||||
return length; |
||||
} |
||||
|
||||
|
||||
size_t |
||||
Encoder::prependVarNumber(uint64_t varNumber) |
||||
{ |
||||
if (varNumber < 253) { |
||||
prependByte(static_cast<uint8_t>(varNumber)); |
||||
return 1; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint16_t>::max()) { |
||||
uint16_t value = htobe16(static_cast<uint16_t>(varNumber)); |
||||
prependByteArray(reinterpret_cast<const uint8_t*>(&value), 2); |
||||
prependByte(253); |
||||
return 3; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint32_t>::max()) { |
||||
uint32_t value = htobe32(static_cast<uint32_t>(varNumber)); |
||||
prependByteArray(reinterpret_cast<const uint8_t*>(&value), 4); |
||||
prependByte(254); |
||||
return 5; |
||||
} |
||||
else { |
||||
uint64_t value = htobe64(varNumber); |
||||
prependByteArray(reinterpret_cast<const uint8_t*>(&value), 8); |
||||
prependByte(255); |
||||
return 9; |
||||
} |
||||
} |
||||
|
||||
size_t |
||||
Encoder::appendVarNumber(uint64_t varNumber) |
||||
{ |
||||
if (varNumber < 253) { |
||||
appendByte(static_cast<uint8_t>(varNumber)); |
||||
return 1; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint16_t>::max()) { |
||||
appendByte(253); |
||||
uint16_t value = htobe16(static_cast<uint16_t>(varNumber)); |
||||
appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2); |
||||
return 3; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint32_t>::max()) { |
||||
appendByte(254); |
||||
uint32_t value = htobe32(static_cast<uint32_t>(varNumber)); |
||||
appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4); |
||||
return 5; |
||||
} |
||||
else { |
||||
appendByte(255); |
||||
uint64_t value = htobe64(varNumber); |
||||
appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8); |
||||
return 9; |
||||
} |
||||
} |
||||
|
||||
|
||||
size_t |
||||
Encoder::prependNonNegativeInteger(uint64_t varNumber) |
||||
{ |
||||
if (varNumber <= std::numeric_limits<uint8_t>::max()) { |
||||
return prependByte(static_cast<uint8_t>(varNumber)); |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint16_t>::max()) { |
||||
uint16_t value = htobe16(static_cast<uint16_t>(varNumber)); |
||||
return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 2); |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint32_t>::max()) { |
||||
uint32_t value = htobe32(static_cast<uint32_t>(varNumber)); |
||||
return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 4); |
||||
} |
||||
else { |
||||
uint64_t value = htobe64(varNumber); |
||||
return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 8); |
||||
} |
||||
} |
||||
|
||||
size_t |
||||
Encoder::appendNonNegativeInteger(uint64_t varNumber) |
||||
{ |
||||
if (varNumber <= std::numeric_limits<uint8_t>::max()) { |
||||
return appendByte(static_cast<uint8_t>(varNumber)); |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint16_t>::max()) { |
||||
uint16_t value = htobe16(static_cast<uint16_t>(varNumber)); |
||||
return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2); |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint32_t>::max()) { |
||||
uint32_t value = htobe32(static_cast<uint32_t>(varNumber)); |
||||
return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4); |
||||
} |
||||
else { |
||||
uint64_t value = htobe64(varNumber); |
||||
return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8); |
||||
} |
||||
} |
||||
|
||||
size_t |
||||
Encoder::prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) |
||||
{ |
||||
size_t totalLength = prependByteArray(array, arraySize); |
||||
totalLength += prependVarNumber(arraySize); |
||||
totalLength += prependVarNumber(type); |
||||
|
||||
return totalLength; |
||||
} |
||||
|
||||
size_t |
||||
Encoder::appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) |
||||
{ |
||||
size_t totalLength = appendVarNumber(type); |
||||
totalLength += appendVarNumber(arraySize); |
||||
totalLength += appendByteArray(array, arraySize); |
||||
|
||||
return totalLength; |
||||
} |
||||
|
||||
size_t |
||||
Encoder::prependBlock(const Block& block) |
||||
{ |
||||
if (block.hasWire()) { |
||||
return prependByteArray(block.wire(), block.size()); |
||||
} |
||||
else { |
||||
return prependByteArrayBlock(block.type(), block.value(), block.value_size()); |
||||
} |
||||
} |
||||
|
||||
size_t |
||||
Encoder::appendBlock(const Block& block) |
||||
{ |
||||
if (block.hasWire()) { |
||||
return appendByteArray(block.wire(), block.size()); |
||||
} |
||||
else { |
||||
return appendByteArrayBlock(block.type(), block.value(), block.value_size()); |
||||
} |
||||
} |
||||
|
||||
} // namespace encoding
|
||||
} // namespace ndn
|
@ -0,0 +1,343 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2013-2015 Regents of the University of California. |
||||
* |
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
||||
* |
||||
* ndn-cxx library is free software: you can redistribute it and/or modify it under the |
||||
* terms of the GNU Lesser General Public License as published by the Free Software |
||||
* Foundation, either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received copies of the GNU General Public License and GNU Lesser |
||||
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
||||
* <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
||||
*/ |
||||
|
||||
#ifndef NDN_ENCODING_ENCODER_HPP |
||||
#define NDN_ENCODING_ENCODER_HPP |
||||
|
||||
#include "../common.hpp" |
||||
#include "block.hpp" |
||||
|
||||
namespace ndn { |
||||
namespace encoding { |
||||
|
||||
/**
|
||||
* @brief Helper class to perform TLV encoding |
||||
* Interface of this class (mostly) matches interface of Estimator class
|
||||
* @sa Estimator |
||||
*/ |
||||
class Encoder |
||||
{ |
||||
public: // common interface between Encoder and Estimator
|
||||
/**
|
||||
* @brief Create instance of the encoder with the specified reserved sizes |
||||
* @param totalReserve initial buffer size to reserve |
||||
* @param totalFromBack number of bytes to reserve for append* operations |
||||
*/ |
||||
explicit |
||||
Encoder(size_t totalReserve = 8800, size_t reserveFromBack = 400); |
||||
|
||||
Encoder(const Encoder&) = delete; |
||||
|
||||
Encoder& |
||||
operator=(const Encoder&) = delete; |
||||
|
||||
/**
|
||||
* @brief Prepend a byte |
||||
*/ |
||||
size_t |
||||
prependByte(uint8_t value); |
||||
|
||||
/**
|
||||
* @brief Append a byte |
||||
*/ |
||||
size_t |
||||
appendByte(uint8_t value); |
||||
|
||||
/**
|
||||
* @brief Prepend a byte array @p array of length @p length |
||||
*/ |
||||
size_t |
||||
prependByteArray(const uint8_t* array, size_t length); |
||||
|
||||
/**
|
||||
* @brief Append a byte array @p array of length @p length |
||||
*/ |
||||
size_t |
||||
appendByteArray(const uint8_t* array, size_t length); |
||||
|
||||
/**
|
||||
* @brief Prepend range of bytes from the range [@p first, @p last) |
||||
*/ |
||||
template<class Iterator> |
||||
size_t |
||||
prependRange(Iterator first, Iterator last); |
||||
|
||||
/**
|
||||
* @brief Append range of bytes from the range [@p first, @p last) |
||||
*/ |
||||
template<class Iterator> |
||||
size_t |
||||
appendRange(Iterator first, Iterator last); |
||||
|
||||
/**
|
||||
* @brief Prepend VarNumber @p varNumber of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
prependVarNumber(uint64_t varNumber); |
||||
|
||||
/**
|
||||
* @brief Prepend VarNumber @p varNumber of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
appendVarNumber(uint64_t varNumber); |
||||
|
||||
/**
|
||||
* @brief Prepend non-negative integer @p integer of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
prependNonNegativeInteger(uint64_t integer); |
||||
|
||||
/**
|
||||
* @brief Append non-negative integer @p integer of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
appendNonNegativeInteger(uint64_t integer); |
||||
|
||||
/**
|
||||
* @brief Prepend TLV block of type @p type and value from buffer @p array of size @p arraySize |
||||
*/ |
||||
size_t |
||||
prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize); |
||||
|
||||
/**
|
||||
* @brief Append TLV block of type @p type and value from buffer @p array of size @p arraySize |
||||
*/ |
||||
size_t |
||||
appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize); |
||||
|
||||
/**
|
||||
* @brief Prepend TLV block @p block |
||||
*/ |
||||
size_t |
||||
prependBlock(const Block& block); |
||||
|
||||
/**
|
||||
* @brief Append TLV block @p block |
||||
*/ |
||||
size_t |
||||
appendBlock(const Block& block); |
||||
|
||||
public: // unique interface to the Encoder
|
||||
typedef Buffer::value_type value_type; |
||||
typedef Buffer::iterator iterator; |
||||
typedef Buffer::const_iterator const_iterator; |
||||
|
||||
/**
|
||||
* @brief Create EncodingBlock from existing block |
||||
* |
||||
* This is a dangerous constructor and should be used with caution. |
||||
* It will modify contents of the buffer that is used by block and may |
||||
* impact data in other blocks. |
||||
* |
||||
* The primary purpose for this method is to be used to extend Block |
||||
* after sign operation. |
||||
*/ |
||||
explicit |
||||
Encoder(const Block& block); |
||||
|
||||
/**
|
||||
* @brief Reserve @p size bytes for the underlying buffer |
||||
* @param addInFront if true, then @p size bytes will be available in front (i.e., subsequent call |
||||
* to prepend* will not need to allocate memory). If false, then reservation will be done |
||||
* at the end of the buffer (i.d., for subsequent append* calls) |
||||
* @note Reserve size is exact, unlike reserveFront and reserveBack methods |
||||
* @sa reserveFront, reserveBack |
||||
*/ |
||||
void |
||||
reserve(size_t size, bool addInFront); |
||||
|
||||
/**
|
||||
* @brief Reserve at least @p size bytes at the back of the underlying buffer |
||||
* @note the actual reserve size can be (and in most cases is) larger than specified reservation |
||||
* length |
||||
*/ |
||||
void |
||||
reserveBack(size_t size); |
||||
|
||||
/**
|
||||
* @brief Reserve at least @p isze bytes at the beginning of the underlying buffer |
||||
* @note the actual reserve size can be (and in most cases is) larger than specified reservation |
||||
* length |
||||
*/ |
||||
void |
||||
reserveFront(size_t size); |
||||
|
||||
/**
|
||||
* @brief Get size of the underlying buffer |
||||
*/ |
||||
size_t |
||||
capacity() const; |
||||
|
||||
/**
|
||||
* @brief Get underlying buffer |
||||
*/ |
||||
shared_ptr<Buffer> |
||||
getBuffer(); |
||||
|
||||
public: // accessors
|
||||
|
||||
/**
|
||||
* @brief Get an iterator pointing to the first byte of the encoded buffer |
||||
*/ |
||||
iterator |
||||
begin(); |
||||
|
||||
/**
|
||||
* @brief Get an iterator pointing to the past-the-end byte of the encoded buffer |
||||
*/ |
||||
iterator |
||||
end(); |
||||
|
||||
/**
|
||||
* @brief Get an iterator pointing to the first byte of the encoded buffer |
||||
*/ |
||||
const_iterator |
||||
begin() const; |
||||
|
||||
const_iterator |
||||
end() const; |
||||
|
||||
/**
|
||||
* @brief Get a pointer to the first byte of the encoded buffer |
||||
*/ |
||||
uint8_t* |
||||
buf(); |
||||
|
||||
/**
|
||||
* @brief Get a pointer to the first byte of the encoded buffer |
||||
*/ |
||||
const uint8_t* |
||||
buf() const; |
||||
|
||||
/**
|
||||
* @brief Get size of the encoded buffer |
||||
*/ |
||||
size_t |
||||
size() const; |
||||
|
||||
/**
|
||||
* @brief Create Block from the underlying buffer |
||||
* |
||||
* @param verifyLength If this parameter set to true, Block's constructor |
||||
* will be requested to verify consistency of the encoded |
||||
* length in the Block, otherwise ignored |
||||
*/ |
||||
Block |
||||
block(bool verifyLength = true) const; |
||||
|
||||
private: |
||||
shared_ptr<Buffer> m_buffer; |
||||
|
||||
// invariant: m_begin always points to the position of last-written byte (if prepending data)
|
||||
iterator m_begin; |
||||
// invariant: m_end always points to the position of next unwritten byte (if appending data)
|
||||
iterator m_end; |
||||
}; |
||||
|
||||
|
||||
inline size_t |
||||
Encoder::size() const |
||||
{ |
||||
return m_end - m_begin; |
||||
} |
||||
|
||||
inline shared_ptr<Buffer> |
||||
Encoder::getBuffer() |
||||
{ |
||||
return m_buffer; |
||||
} |
||||
|
||||
inline size_t |
||||
Encoder::capacity() const |
||||
{ |
||||
return m_buffer->size(); |
||||
} |
||||
|
||||
inline Buffer::iterator |
||||
Encoder::begin() |
||||
{ |
||||
return m_begin; |
||||
} |
||||
|
||||
inline Buffer::iterator |
||||
Encoder::end() |
||||
{ |
||||
return m_end; |
||||
} |
||||
|
||||
inline Buffer::const_iterator |
||||
Encoder::begin() const |
||||
{ |
||||
return m_begin; |
||||
} |
||||
|
||||
inline Buffer::const_iterator |
||||
Encoder::end() const |
||||
{ |
||||
return m_end; |
||||
} |
||||
|
||||
inline uint8_t* |
||||
Encoder::buf() |
||||
{ |
||||
return &(*m_begin); |
||||
} |
||||
|
||||
inline const uint8_t* |
||||
Encoder::buf() const |
||||
{ |
||||
return &(*m_begin); |
||||
} |
||||
|
||||
template<class Iterator> |
||||
inline size_t |
||||
Encoder::prependRange(Iterator first, Iterator last) |
||||
{ |
||||
size_t length = std::distance(first, last); |
||||
reserveFront(length); |
||||
|
||||
m_begin -= length; |
||||
std::copy(first, last, m_begin); |
||||
return length; |
||||
} |
||||
|
||||
|
||||
template<class Iterator> |
||||
inline size_t |
||||
Encoder::appendRange(Iterator first, Iterator last) |
||||
{ |
||||
size_t length = std::distance(first, last); |
||||
reserveBack(length); |
||||
|
||||
std::copy(first, last, m_end); |
||||
m_end += length; |
||||
return length; |
||||
} |
||||
|
||||
|
||||
} // namespace encoding
|
||||
} // namespace ndn
|
||||
|
||||
#endif // NDN_ENCODING_ENCODER_HPP
|
@ -0,0 +1,58 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2013-2015 Regents of the University of California. |
||||
* |
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
||||
* |
||||
* ndn-cxx library is free software: you can redistribute it and/or modify it under the |
||||
* terms of the GNU Lesser General Public License as published by the Free Software |
||||
* Foundation, either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received copies of the GNU General Public License and GNU Lesser |
||||
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
||||
* <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
||||
*/ |
||||
|
||||
#ifndef NDN_ENCODING_ENCODING_BUFFER_FWD_HPP |
||||
#define NDN_ENCODING_ENCODING_BUFFER_FWD_HPP |
||||
|
||||
namespace ndn { |
||||
namespace encoding { |
||||
|
||||
typedef bool Tag; |
||||
|
||||
/**
|
||||
* @brief Tag for EncodingImpl to indicate that Encoder is requested |
||||
* Implementation of the tag may change to class. Use of true directly |
||||
* as a template parameter is discouraged. |
||||
*/ |
||||
static const Tag EncoderTag = true; |
||||
|
||||
/**
|
||||
* @brief Tag for EncodingImpl to indicate that Estimator is requested |
||||
* Implementation of the tag may change to class. Use of false directly |
||||
* as a template parameter is discouraged. |
||||
*/ |
||||
static const Tag EstimatorTag = false; |
||||
|
||||
template<Tag TAG> |
||||
class EncodingImpl; |
||||
|
||||
typedef EncodingImpl<EncoderTag> EncodingBuffer; |
||||
typedef EncodingImpl<EstimatorTag> EncodingEstimator; |
||||
|
||||
} // namespace encoding
|
||||
|
||||
using encoding::EncodingImpl; |
||||
using encoding::EncodingBuffer; |
||||
using encoding::EncodingEstimator; |
||||
|
||||
} // namespace ndn
|
||||
|
||||
#endif // NDN_ENCODING_ENCODING_BUFFER_FWD_HPP
|
@ -0,0 +1,140 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2013-2015 Regents of the University of California. |
||||
* |
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
||||
* |
||||
* ndn-cxx library is free software: you can redistribute it and/or modify it under the |
||||
* terms of the GNU Lesser General Public License as published by the Free Software |
||||
* Foundation, either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received copies of the GNU General Public License and GNU Lesser |
||||
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
||||
* <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
||||
*/ |
||||
|
||||
#include "estimator.hpp" |
||||
|
||||
namespace ndn { |
||||
namespace encoding { |
||||
|
||||
Estimator::Estimator(size_t totalReserve, size_t reserveFromBack) |
||||
{ |
||||
} |
||||
|
||||
size_t |
||||
Estimator::prependByte(uint8_t value) |
||||
{ |
||||
return 1; |
||||
} |
||||
|
||||
size_t |
||||
Estimator::appendByte(uint8_t value) |
||||
{ |
||||
return 1; |
||||
} |
||||
|
||||
|
||||
size_t |
||||
Estimator::prependByteArray(const uint8_t* array, size_t length) |
||||
{ |
||||
return length; |
||||
} |
||||
|
||||
size_t |
||||
Estimator::appendByteArray(const uint8_t* array, size_t length) |
||||
{ |
||||
return prependByteArray(array, length); |
||||
} |
||||
|
||||
size_t |
||||
Estimator::prependVarNumber(uint64_t varNumber) |
||||
{ |
||||
if (varNumber < 253) { |
||||
return 1; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint16_t>::max()) { |
||||
return 3; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint32_t>::max()) { |
||||
return 5; |
||||
} |
||||
else { |
||||
return 9; |
||||
} |
||||
} |
||||
|
||||
size_t |
||||
Estimator::appendVarNumber(uint64_t varNumber) |
||||
{ |
||||
return prependVarNumber(varNumber); |
||||
} |
||||
|
||||
|
||||
size_t |
||||
Estimator::prependNonNegativeInteger(uint64_t varNumber) |
||||
{ |
||||
if (varNumber <= std::numeric_limits<uint8_t>::max()) { |
||||
return 1; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint16_t>::max()) { |
||||
return 2; |
||||
} |
||||
else if (varNumber <= std::numeric_limits<uint32_t>::max()) { |
||||
return 4; |
||||
} |
||||
else { |
||||
return 8; |
||||
} |
||||
} |
||||
|
||||
size_t |
||||
Estimator::appendNonNegativeInteger(uint64_t varNumber) |
||||
{ |
||||
return prependNonNegativeInteger(varNumber); |
||||
} |
||||
|
||||
|
||||
size_t |
||||
Estimator::prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) |
||||
{ |
||||
size_t totalLength = arraySize; |
||||
totalLength += prependVarNumber(arraySize); |
||||
totalLength += prependVarNumber(type); |
||||
|
||||
return totalLength; |
||||
} |
||||
|
||||
size_t |
||||
Estimator::appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize) |
||||
{ |
||||
return prependByteArrayBlock(type, array, arraySize); |
||||
} |
||||
|
||||
|
||||
size_t |
||||
Estimator::prependBlock(const Block& block) |
||||
{ |
||||
if (block.hasWire()) { |
||||
return block.size(); |
||||
} |
||||
else { |
||||
return prependByteArrayBlock(block.type(), block.value(), block.value_size()); |
||||
} |
||||
} |
||||
|
||||
size_t |
||||
Estimator::appendBlock(const Block& block) |
||||
{ |
||||
return prependBlock(block); |
||||
} |
||||
|
||||
|
||||
} // namespace encoding
|
||||
} // namespace ndn
|
@ -0,0 +1,162 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2013-2015 Regents of the University of California. |
||||
* |
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
||||
* |
||||
* ndn-cxx library is free software: you can redistribute it and/or modify it under the |
||||
* terms of the GNU Lesser General Public License as published by the Free Software |
||||
* Foundation, either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received copies of the GNU General Public License and GNU Lesser |
||||
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
||||
* <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
||||
*/ |
||||
|
||||
#ifndef NDN_ENCODING_ESTIMATOR_HPP |
||||
#define NDN_ENCODING_ESTIMATOR_HPP |
||||
|
||||
#include "../common.hpp" |
||||
#include "block.hpp" |
||||
|
||||
namespace ndn { |
||||
namespace encoding { |
||||
|
||||
/**
|
||||
* @brief Helper class to estimate size of TLV encoding |
||||
* Interface of this class (mostly) matches interface of Encoder class
|
||||
* @sa Encoder |
||||
*/ |
||||
class Estimator |
||||
{ |
||||
public: // common interface between Encoder and Estimator
|
||||
/**
|
||||
* @brief Create instance of the estimator |
||||
* @param totalReserve not used (for compatibility with the Encoder) |
||||
* @param totalFromBack not used (for compatibility with the Encoder) |
||||
*/ |
||||
explicit |
||||
Estimator(size_t totalReserve = 0, size_t reserveFromBack = 0); |
||||
|
||||
Estimator(const Estimator&) = delete; |
||||
|
||||
Estimator& |
||||
operator=(const Estimator&) = delete; |
||||
|
||||
/**
|
||||
* @brief Prepend a byte |
||||
*/ |
||||
size_t |
||||
prependByte(uint8_t value); |
||||
|
||||
/**
|
||||
* @brief Append a byte |
||||
*/ |
||||
size_t |
||||
appendByte(uint8_t value); |
||||
|
||||
/**
|
||||
* @brief Prepend a byte array @p array of length @p length |
||||
*/ |
||||
size_t |
||||
prependByteArray(const uint8_t* array, size_t length); |
||||
|
||||
/**
|
||||
* @brief Append a byte array @p array of length @p length |
||||
*/ |
||||
size_t |
||||
appendByteArray(const uint8_t* array, size_t length); |
||||
|
||||
/**
|
||||
* @brief Prepend range of bytes from the range [@p first, @p last) |
||||
*/ |
||||
template<class Iterator> |
||||
size_t |
||||
prependRange(Iterator first, Iterator last); |
||||
|
||||
/**
|
||||
* @brief Append range of bytes from the range [@p first, @p last) |
||||
*/ |
||||
template<class Iterator> |
||||
size_t |
||||
appendRange(Iterator first, Iterator last); |
||||
|
||||
/**
|
||||
* @brief Prepend VarNumber @p varNumber of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
prependVarNumber(uint64_t varNumber); |
||||
|
||||
/**
|
||||
* @brief Prepend VarNumber @p varNumber of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
appendVarNumber(uint64_t varNumber); |
||||
|
||||
/**
|
||||
* @brief Prepend non-negative integer @p integer of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
prependNonNegativeInteger(uint64_t integer); |
||||
|
||||
/**
|
||||
* @brief Append non-negative integer @p integer of NDN TLV encoding |
||||
* @sa http://named-data.net/doc/ndn-tlv/
|
||||
*/ |
||||
size_t |
||||
appendNonNegativeInteger(uint64_t integer); |
||||
|
||||
/**
|
||||
* @brief Prepend TLV block of type @p type and value from buffer @p array of size @p arraySize |
||||
*/ |
||||
size_t |
||||
prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize); |
||||
|
||||
/**
|
||||
* @brief Append TLV block of type @p type and value from buffer @p array of size @p arraySize |
||||
*/ |
||||
size_t |
||||
appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize); |
||||
|
||||
/**
|
||||
* @brief Prepend TLV block @p block |
||||
*/ |
||||
size_t |
||||
prependBlock(const Block& block); |
||||
|
||||
/**
|
||||
* @brief Append TLV block @p block |
||||
*/ |
||||
size_t |
||||
appendBlock(const Block& block); |
||||
}; |
||||
|
||||
|
||||
template<class Iterator> |
||||
inline size_t |
||||
Estimator::prependRange(Iterator first, Iterator last) |
||||
{ |
||||
return std::distance(first, last); |
||||
} |
||||
|
||||
|
||||
template<class Iterator> |
||||
inline size_t |
||||
Estimator::appendRange(Iterator first, Iterator last) |
||||
{ |
||||
return prependRange(first, last); |
||||
} |
||||
|
||||
} // namespace encoding
|
||||
} // namespace ndn
|
||||
|
||||
#endif // NDN_ENCODING_ESTIMATOR_HPP
|
@ -0,0 +1,171 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2013-2015 Regents of the University of California. |
||||
* |
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
||||
* |
||||
* ndn-cxx library is free software: you can redistribute it and/or modify it under the |
||||
* terms of the GNU Lesser General Public License as published by the Free Software |
||||
* Foundation, either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received copies of the GNU General Public License and GNU Lesser |
||||
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
||||
* <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
||||
*/ |
||||
|
||||
#include "encoding/encoder.hpp" |
||||
|
||||
#include "boost-test.hpp" |
||||
|
||||
namespace ndn { |
||||
namespace encoding { |
||||
namespace tests { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(EncodingEncoder) |
||||
|
||||
BOOST_AUTO_TEST_CASE(Basic) |
||||
{ |
||||
Encoder e; |
||||
BOOST_CHECK_GT(e.capacity(), 100); |
||||
|
||||
Encoder e1(100); |
||||
BOOST_CHECK_EQUAL(e1.capacity(), 100); |
||||
|
||||
Encoder e2(100, 100); |
||||
BOOST_CHECK_EQUAL(e2.capacity(), 100); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependByte(1), 1); |
||||
BOOST_CHECK_EQUAL(e.appendByte(1), 1); |
||||
|
||||
uint8_t buf1[] = {'t', 'e', 's', 't', '1'}; |
||||
BOOST_CHECK_EQUAL(e1.prependByteArray(buf1, sizeof(buf1)), 5); |
||||
BOOST_CHECK_EQUAL(e1.appendByteArray(buf1, sizeof(buf1)), 5); |
||||
|
||||
std::vector<uint8_t> buf2 = {'t', 'e', 's', 't', '2'}; |
||||
BOOST_CHECK_EQUAL(e1.prependRange(buf2.begin(), buf2.end()), 5); |
||||
BOOST_CHECK_EQUAL(e1.appendRange(buf2.begin(), buf2.end()), 5); |
||||
|
||||
std::list<uint8_t> buf3 = {'t', 'e', 's', 't', '2'}; |
||||
BOOST_CHECK_EQUAL(e2.prependRange(buf3.begin(), buf3.end()), 5); |
||||
BOOST_CHECK_EQUAL(e2.appendRange(buf3.begin(), buf3.end()), 5); |
||||
|
||||
uint8_t expected1[] = {1, 1}; |
||||
BOOST_CHECK_EQUAL_COLLECTIONS(e.buf(), e.buf() + e.size(), |
||||
expected1, expected1 + sizeof(expected1)); |
||||
|
||||
const Encoder& constE = e; |
||||
BOOST_CHECK_EQUAL_COLLECTIONS(constE.buf(), constE.buf() + constE.size(), |
||||
expected1, expected1 + sizeof(expected1)); |
||||
|
||||
uint8_t expected2[] = {'t', 'e', 's', 't', '2', |
||||
't', 'e', 's', 't', '1', 't', 'e', 's', 't', '1', |
||||
't', 'e', 's', 't', '2'}; |
||||
BOOST_CHECK_EQUAL_COLLECTIONS(e1.begin(), e1.end(), |
||||
expected2, expected2 + sizeof(expected2)); |
||||
const Encoder& constE1 = e1; |
||||
BOOST_CHECK_EQUAL_COLLECTIONS(constE1.begin(), constE1.end(), |
||||
expected2, expected2 + sizeof(expected2)); |
||||
|
||||
BOOST_CHECK_THROW(e1.block(), tlv::Error); |
||||
BOOST_CHECK_NO_THROW(e1.block(false)); |
||||
|
||||
e1.prependVarNumber(20); |
||||
e1.prependVarNumber(100); |
||||
|
||||
BOOST_CHECK_NO_THROW(e1.block()); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(Tlv) |
||||
{ |
||||
Encoder e; |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(1), 1); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(1), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(252), 1); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(252), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(253), 3); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(253), 3); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(65536), 5); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(65536), 5); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(4294967296LL), 9); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(4294967296LL), 9); |
||||
|
||||
//
|
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(1), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(1), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(252), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(252), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(253), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(253), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(255), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(255), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(256), 2); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(256), 2); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65535), 2); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65535), 2); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65536), 4); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65536), 4); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(4294967296LL), 8); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(4294967296LL), 8); |
||||
|
||||
//
|
||||
|
||||
uint8_t buf[] = {0x01, 0x03, 0x00, 0x00, 0x00}; |
||||
Block block1(buf, sizeof(buf)); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependByteArrayBlock(100, buf, sizeof(buf)), 7); |
||||
BOOST_CHECK_EQUAL(e.appendByteArrayBlock(100, buf, sizeof(buf)), 7); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependBlock(block1), 5); |
||||
BOOST_CHECK_EQUAL(e.appendBlock(block1), 5); |
||||
|
||||
Block block2(100, block1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependBlock(block2), 7); |
||||
BOOST_CHECK_EQUAL(e.appendBlock(block2), 7); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(Reserve) |
||||
{ |
||||
Encoder e(100, 0); |
||||
BOOST_CHECK_EQUAL(e.capacity(), 100); |
||||
|
||||
e.reserve(100, true); |
||||
BOOST_CHECK_EQUAL(e.capacity(), 100); |
||||
|
||||
e.reserve(200, true); |
||||
BOOST_CHECK_EQUAL(e.capacity(), 200); |
||||
|
||||
e.reserve(100, false); |
||||
BOOST_CHECK_EQUAL(e.capacity(), 200); |
||||
|
||||
e.reserveFront(1000); |
||||
BOOST_CHECK_GT(e.capacity(), 1000); |
||||
|
||||
e.reserveBack(1000); |
||||
BOOST_CHECK_GT(e.capacity(), 2000); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // EncodingEncoder
|
||||
|
||||
} // namespace tests
|
||||
} // namespace encoding
|
||||
} // namespace ndn
|
@ -0,0 +1,120 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
||||
/**
|
||||
* Copyright (c) 2013-2015 Regents of the University of California. |
||||
* |
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
||||
* |
||||
* ndn-cxx library is free software: you can redistribute it and/or modify it under the |
||||
* terms of the GNU Lesser General Public License as published by the Free Software |
||||
* Foundation, either version 3 of the License, or (at your option) any later version. |
||||
* |
||||
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received copies of the GNU General Public License and GNU Lesser |
||||
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
||||
* <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
||||
*/ |
||||
|
||||
#include "encoding/estimator.hpp" |
||||
|
||||
#include "boost-test.hpp" |
||||
|
||||
namespace ndn { |
||||
namespace encoding { |
||||
namespace tests { |
||||
|
||||
BOOST_AUTO_TEST_SUITE(EncodingEstimator) |
||||
|
||||
BOOST_AUTO_TEST_CASE(Basic) |
||||
{ |
||||
Estimator e; |
||||
Estimator e1(100); |
||||
Estimator e2(100, 100); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependByte(1), 1); |
||||
BOOST_CHECK_EQUAL(e.appendByte(1), 1); |
||||
|
||||
uint8_t buf1[] = {'t', 'e', 's', 't', '1'}; |
||||
BOOST_CHECK_EQUAL(e1.prependByteArray(buf1, sizeof(buf1)), 5); |
||||
BOOST_CHECK_EQUAL(e1.appendByteArray(buf1, sizeof(buf1)), 5); |
||||
|
||||
std::vector<uint8_t> buf2 = {'t', 'e', 's', 't', '2'}; |
||||
BOOST_CHECK_EQUAL(e1.prependRange(buf2.begin(), buf2.end()), 5); |
||||
BOOST_CHECK_EQUAL(e1.appendRange(buf2.begin(), buf2.end()), 5); |
||||
|
||||
std::list<uint8_t> buf3 = {'t', 'e', 's', 't', '2'}; |
||||
BOOST_CHECK_EQUAL(e2.prependRange(buf3.begin(), buf3.end()), 5); |
||||
BOOST_CHECK_EQUAL(e2.appendRange(buf3.begin(), buf3.end()), 5); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(Tlv) |
||||
{ |
||||
Estimator e; |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(1), 1); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(1), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(252), 1); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(252), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(253), 3); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(253), 3); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(65536), 5); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(65536), 5); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependVarNumber(4294967296LL), 9); |
||||
BOOST_CHECK_EQUAL(e.appendVarNumber(4294967296LL), 9); |
||||
|
||||
//
|
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(1), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(1), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(252), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(252), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(253), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(253), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(255), 1); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(255), 1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(256), 2); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(256), 2); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65535), 2); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65535), 2); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65536), 4); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65536), 4); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(4294967296LL), 8); |
||||
BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(4294967296LL), 8); |
||||
|
||||
//
|
||||
|
||||
uint8_t buf[] = {0x01, 0x03, 0x00, 0x00, 0x00}; |
||||
Block block1(buf, sizeof(buf)); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependByteArrayBlock(100, buf, sizeof(buf)), 7); |
||||
BOOST_CHECK_EQUAL(e.appendByteArrayBlock(100, buf, sizeof(buf)), 7); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependBlock(block1), 5); |
||||
BOOST_CHECK_EQUAL(e.appendBlock(block1), 5); |
||||
|
||||
Block block2(100, block1); |
||||
|
||||
BOOST_CHECK_EQUAL(e.prependBlock(block2), 7); |
||||
BOOST_CHECK_EQUAL(e.appendBlock(block2), 7); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // EncodingEstimator
|
||||
|
||||
} // namespace tests
|
||||
} // namespace encoding
|
||||
} // namespace ndn
|
Loading…
Reference in new issue