estimator.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_ENCODING_ESTIMATOR_HPP
23 #define NDN_CXX_ENCODING_ESTIMATOR_HPP
24 
26 
27 namespace ndn {
28 namespace encoding {
29 
37 class Estimator : noncopyable
38 {
39 public: // common interface between Encoder and Estimator
43  constexpr size_t
44  prependBytes(span<const uint8_t> bytes) const noexcept
45  {
46  return bytes.size();
47  }
48 
52  constexpr size_t
53  appendBytes(span<const uint8_t> bytes) const noexcept
54  {
55  return bytes.size();
56  }
57 
61  template<class Iterator>
62  constexpr size_t
63  prependRange(Iterator first, Iterator last) const noexcept
64  {
65  return static_cast<size_t>(std::distance(first, last));
66  }
67 
71  template<class Iterator>
72  constexpr size_t
73  appendRange(Iterator first, Iterator last) const noexcept
74  {
75  return static_cast<size_t>(std::distance(first, last));
76  }
77 
81  constexpr size_t
82  prependVarNumber(uint64_t n) const noexcept
83  {
84  return tlv::sizeOfVarNumber(n);
85  }
86 
90  constexpr size_t
91  appendVarNumber(uint64_t n) const noexcept
92  {
93  return tlv::sizeOfVarNumber(n);
94  }
95 
99  constexpr size_t
100  prependNonNegativeInteger(uint64_t n) const noexcept
101  {
103  }
104 
108  constexpr size_t
109  appendNonNegativeInteger(uint64_t n) const noexcept
110  {
112  }
113 };
114 
115 } // namespace encoding
116 } // namespace ndn
117 
118 #endif // NDN_CXX_ENCODING_ESTIMATOR_HPP
Helper class to estimate size of TLV encoding.
Definition: estimator.hpp:38
constexpr size_t prependBytes(span< const uint8_t > bytes) const noexcept
Prepend a sequence of bytes.
Definition: estimator.hpp:44
constexpr size_t appendRange(Iterator first, Iterator last) const noexcept
Append bytes from the range [first, last)
Definition: estimator.hpp:73
constexpr size_t prependNonNegativeInteger(uint64_t n) const noexcept
Prepend n in NonNegativeInteger encoding.
Definition: estimator.hpp:100
constexpr size_t appendNonNegativeInteger(uint64_t n) const noexcept
Append n in NonNegativeInteger encoding.
Definition: estimator.hpp:109
constexpr size_t appendBytes(span< const uint8_t > bytes) const noexcept
Append a sequence of bytes.
Definition: estimator.hpp:53
constexpr size_t appendVarNumber(uint64_t n) const noexcept
Append n in VarNumber encoding.
Definition: estimator.hpp:91
constexpr size_t prependRange(Iterator first, Iterator last) const noexcept
Prepend bytes from the range [first, last)
Definition: estimator.hpp:63
constexpr size_t prependVarNumber(uint64_t n) const noexcept
Prepend n in VarNumber encoding.
Definition: estimator.hpp:82
constexpr size_t sizeOfVarNumber(uint64_t number) noexcept
Get the number of bytes necessary to hold the value of number encoded as VAR-NUMBER.
Definition: tlv.hpp:438
constexpr size_t sizeOfNonNegativeInteger(uint64_t integer) noexcept
Get the number of bytes necessary to hold the value of integer encoded as NonNegativeInteger.
Definition: tlv.hpp:490
Definition: data.cpp:25