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-2023 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::encoding {
28 
36 class Estimator : noncopyable
37 {
38 public: // common interface between Encoder and Estimator
42  constexpr size_t
43  prependBytes(span<const uint8_t> bytes) const noexcept
44  {
45  return bytes.size();
46  }
47 
51  constexpr size_t
52  appendBytes(span<const uint8_t> bytes) const noexcept
53  {
54  return bytes.size();
55  }
56 
60  template<class Iterator>
61  constexpr size_t
62  prependRange(Iterator first, Iterator last) const noexcept
63  {
64  return static_cast<size_t>(std::distance(first, last));
65  }
66 
70  template<class Iterator>
71  constexpr size_t
72  appendRange(Iterator first, Iterator last) const noexcept
73  {
74  return static_cast<size_t>(std::distance(first, last));
75  }
76 
80  constexpr size_t
81  prependVarNumber(uint64_t n) const noexcept
82  {
83  return tlv::sizeOfVarNumber(n);
84  }
85 
89  constexpr size_t
90  appendVarNumber(uint64_t n) const noexcept
91  {
92  return tlv::sizeOfVarNumber(n);
93  }
94 
98  constexpr size_t
99  prependNonNegativeInteger(uint64_t n) const noexcept
100  {
102  }
103 
107  constexpr size_t
108  appendNonNegativeInteger(uint64_t n) const noexcept
109  {
111  }
112 };
113 
114 } // namespace ndn::encoding
115 
116 #endif // NDN_CXX_ENCODING_ESTIMATOR_HPP
Helper class to estimate size of TLV encoding.
Definition: estimator.hpp:37
constexpr size_t prependBytes(span< const uint8_t > bytes) const noexcept
Prepend a sequence of bytes.
Definition: estimator.hpp:43
constexpr size_t appendRange(Iterator first, Iterator last) const noexcept
Append bytes from the range [first, last)
Definition: estimator.hpp:72
constexpr size_t prependNonNegativeInteger(uint64_t n) const noexcept
Prepend n in NonNegativeInteger encoding.
Definition: estimator.hpp:99
constexpr size_t appendNonNegativeInteger(uint64_t n) const noexcept
Append n in NonNegativeInteger encoding.
Definition: estimator.hpp:108
constexpr size_t appendBytes(span< const uint8_t > bytes) const noexcept
Append a sequence of bytes.
Definition: estimator.hpp:52
constexpr size_t appendVarNumber(uint64_t n) const noexcept
Append n in VarNumber encoding.
Definition: estimator.hpp:90
constexpr size_t prependRange(Iterator first, Iterator last) const noexcept
Prepend bytes from the range [first, last)
Definition: estimator.hpp:62
constexpr size_t prependVarNumber(uint64_t n) const noexcept
Prepend n in VarNumber encoding.
Definition: estimator.hpp:81
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:405
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:430