estimator.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "estimator.hpp"
23 
24 namespace ndn {
25 namespace encoding {
26 
27 Estimator::Estimator(size_t totalReserve, size_t reserveFromBack)
28 {
29 }
30 
31 size_t
32 Estimator::prependByte(uint8_t value)
33 {
34  return 1;
35 }
36 
37 size_t
38 Estimator::appendByte(uint8_t value)
39 {
40  return 1;
41 }
42 
43 
44 size_t
45 Estimator::prependByteArray(const uint8_t* array, size_t length)
46 {
47  return length;
48 }
49 
50 size_t
51 Estimator::appendByteArray(const uint8_t* array, size_t length)
52 {
53  return prependByteArray(array, length);
54 }
55 
56 size_t
57 Estimator::prependVarNumber(uint64_t varNumber)
58 {
59  if (varNumber < 253) {
60  return 1;
61  }
62  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
63  return 3;
64  }
65  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
66  return 5;
67  }
68  else {
69  return 9;
70  }
71 }
72 
73 size_t
74 Estimator::appendVarNumber(uint64_t varNumber)
75 {
76  return prependVarNumber(varNumber);
77 }
78 
79 
80 size_t
82 {
83  if (varNumber <= std::numeric_limits<uint8_t>::max()) {
84  return 1;
85  }
86  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
87  return 2;
88  }
89  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
90  return 4;
91  }
92  else {
93  return 8;
94  }
95 }
96 
97 size_t
99 {
100  return prependNonNegativeInteger(varNumber);
101 }
102 
103 
104 size_t
105 Estimator::prependByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize)
106 {
107  size_t totalLength = arraySize;
108  totalLength += prependVarNumber(arraySize);
109  totalLength += prependVarNumber(type);
110 
111  return totalLength;
112 }
113 
114 size_t
115 Estimator::appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize)
116 {
117  return prependByteArrayBlock(type, array, arraySize);
118 }
119 
120 
121 size_t
123 {
124  if (block.hasWire()) {
125  return block.size();
126  }
127  else {
128  return prependByteArrayBlock(block.type(), block.value(), block.value_size());
129  }
130 }
131 
132 size_t
134 {
135  return prependBlock(block);
136 }
137 
138 
139 } // namespace encoding
140 } // namespace ndn
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
size_t prependByte(uint8_t value)
Prepend a byte.
Definition: estimator.cpp:32
size_t prependByteArrayBlock(uint32_t type, const uint8_t *array, size_t arraySize)
Prepend TLV block of type type and value from buffer array of size arraySize.
Definition: estimator.cpp:105
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
size_t appendByteArray(const uint8_t *array, size_t length)
Append a byte array array of length length.
Definition: estimator.cpp:51
size_t prependByteArray(const uint8_t *array, size_t length)
Prepend a byte array array of length length.
Definition: estimator.cpp:45
size_t size() const
Get size of encoded wire, including Type-Length-Value.
Definition: block.cpp:299
size_t appendByteArrayBlock(uint32_t type, const uint8_t *array, size_t arraySize)
Append TLV block of type type and value from buffer array of size arraySize.
Definition: estimator.cpp:115
size_t prependVarNumber(uint64_t varNumber)
Prepend VarNumber varNumber of NDN TLV encoding.
Definition: estimator.cpp:57
size_t appendNonNegativeInteger(uint64_t integer)
Append non-negative integer integer of NDN TLV encoding.
Definition: estimator.cpp:98
Estimator(size_t totalReserve=0, size_t reserveFromBack=0)
Create instance of the estimator.
Definition: estimator.cpp:27
size_t prependBlock(const Block &block)
Prepend TLV block block.
Definition: estimator.cpp:122
size_t appendBlock(const Block &block)
Append TLV block block.
Definition: estimator.cpp:133
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
Definition: block.cpp:317
uint32_t type() const
Get TLV-TYPE.
Definition: block.hpp:235
size_t appendByte(uint8_t value)
Append a byte.
Definition: estimator.cpp:38
size_t appendVarNumber(uint64_t varNumber)
Prepend VarNumber varNumber of NDN TLV encoding.
Definition: estimator.cpp:74
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:250
const uint8_t * value() const
Get pointer to TLV-VALUE.
Definition: block.cpp:311
size_t prependNonNegativeInteger(uint64_t integer)
Prepend non-negative integer integer of NDN TLV encoding.
Definition: estimator.cpp:81