1010
1111#pragma once
1212
13- #include < vector> // std::vector
1413#include < cstdint> // uint8_t, UINT16_MAX
1514#include < cstddef> // size_t
15+ #include < vector> // std::vector
1616
1717#include " ByteVector.hpp" // ByteVector
18+ #include " Reader.hpp"
1819
1920namespace tcp_in {
2021
@@ -60,6 +61,12 @@ class DecodeBuffer {
6061 */
6162 void read_from (const uint8_t *data, size_t size);
6263
64+ /* *
65+ * @brief Read data using generic reader function.
66+ * @param reader generic reader function.
67+ */
68+ void read_from (Reader &reader);
69+
6370 /* *
6471 * @brief Copies IPFIX data from circular buffer.
6572 *
@@ -104,18 +111,18 @@ class DecodeBuffer {
104111private:
105112 /* *
106113 * @brief Reads the length from ipfix header to `m_decoded_size`.
107- * @param[in,out] data Pointer to data. It is modified by the amount of read data.
108- * @param[in,out] size Size of the data. It is modified by the amount of read data.
114+ * @param state state of the reader. This may be anything for which is read_unitl_n implemented.
109115 * @return `true` if the whole header could be read.
110116 */
111- bool read_header (const uint8_t **data, size_t *size);
117+ template <typename ... State>
118+ bool read_header (State &&...state);
112119 /* *
113120 * @brief Reads the body of ipfix message.
114- * @param data Pointer to data. It is modified by the amount of read data.
115- * @param size Size of the data. It is modified by the amount of read data.
121+ * @param state state of the reader. This may be anything for which is read_unitl_n implemented.
116122 * @return `true` if the whole header could be read.
117123 */
118- bool read_body (const uint8_t **data, size_t *size);
124+ template <typename ... State>
125+ bool read_body (State &&...state);
119126 /* *
120127 * @brief Reads to `m_part_decoded` until it reaches length of `n`.
121128 * @param n Target length for `m_part_decoded`.
@@ -124,6 +131,13 @@ class DecodeBuffer {
124131 * @return `true` if `m_part_decoded` has reached length of `n`.
125132 */
126133 bool read_until_n (size_t n, const uint8_t **data, size_t *data_len);
134+ /* *
135+ * @brief Reads to `m_part_decoded` until it reaches length of `n`.
136+ * @param n Target length for `m_part_decoded`.
137+ * @param reader Generic reader from which to read.
138+ * @return `true` if `m_part_decoded` has reached length of `n`.
139+ */
140+ bool read_until_n (size_t n, Reader &reader);
127141 /* *
128142 * @brief Adds N elements from `src` to `m_part_decoded` where N is the smaller of the two
129143 * sizes.
0 commit comments