|
10 | 10 |
|
11 | 11 | #pragma once |
12 | 12 |
|
13 | | -#include <vector> // std::vector |
14 | 13 | #include <cstdint> // uint8_t, UINT16_MAX |
15 | 14 | #include <cstddef> // size_t |
| 15 | +#include <vector> // std::vector |
16 | 16 |
|
17 | 17 | #include "ByteVector.hpp" // ByteVector |
| 18 | +#include "Reader.hpp" |
18 | 19 |
|
19 | 20 | namespace tcp_in { |
20 | 21 |
|
@@ -50,28 +51,11 @@ class DecodeBuffer { |
50 | 51 | } |
51 | 52 |
|
52 | 53 | /** |
53 | | - * @brief Copies IPFIX data from buffer. |
54 | | - * |
55 | | - * The data may be any part of message (possibly incomplete or even multiple messages) but |
56 | | - * multiple calls to this method must be with the message data in correct order so that it can |
57 | | - * be reconstructed. |
58 | | - * @param data data with the message |
59 | | - * @param size size of the data in `data` |
| 54 | + * @brief Read data using generic reader function. |
| 55 | + * @param reader Generic reader function. |
| 56 | + * @param consume Minimum number of bytes that should be read from reader if possible. |
60 | 57 | */ |
61 | | - void read_from(const uint8_t *data, size_t size); |
62 | | - |
63 | | - /** |
64 | | - * @brief Copies IPFIX data from circular buffer. |
65 | | - * |
66 | | - * The data may be any part of message (possibly incomplete or even multiple messages) but |
67 | | - * multiple calls to this metod must be with the message data in correct order so that it can be |
68 | | - * reconstructed. |
69 | | - * @param data data of the circullar buffer |
70 | | - * @param buffer_size size of the circullar buffer (allocated space) |
71 | | - * @param data_size size of data to copy from the buffer |
72 | | - * @param position start position of the data in the buffer. |
73 | | - */ |
74 | | - void read_from(const uint8_t *data, size_t buffer_size, size_t data_size, size_t position); |
| 58 | + void read_from(Reader &reader, std::size_t consume = 0); |
75 | 59 |
|
76 | 60 | /** |
77 | 61 | * @brief Checks whether enough data has been read since last time. When this returns true, |
@@ -104,32 +88,23 @@ class DecodeBuffer { |
104 | 88 | private: |
105 | 89 | /** |
106 | 90 | * @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. |
| 91 | + * @param reader Reader from which to read. |
109 | 92 | * @return `true` if the whole header could be read. |
110 | 93 | */ |
111 | | - bool read_header(const uint8_t **data, size_t *size); |
| 94 | + bool read_header(Reader &reader); |
112 | 95 | /** |
113 | 96 | * @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. |
| 97 | + * @param reader Reader from which to read. |
116 | 98 | * @return `true` if the whole header could be read. |
117 | 99 | */ |
118 | | - bool read_body(const uint8_t **data, size_t *size); |
| 100 | + bool read_body(Reader &reader); |
119 | 101 | /** |
120 | 102 | * @brief Reads to `m_part_decoded` until it reaches length of `n`. |
121 | 103 | * @param n Target length for `m_part_decoded`. |
122 | | - * @param[in,out] data Data to read from. It is modified by the read amount. |
123 | | - * @param[in,out] data_len Length of data to read. It is modified by the read amount. |
| 104 | + * @param reader Generic reader from which to read. |
124 | 105 | * @return `true` if `m_part_decoded` has reached length of `n`. |
125 | 106 | */ |
126 | | - bool read_until_n(size_t n, const uint8_t **data, size_t *data_len); |
127 | | - /** |
128 | | - * @brief Adds N elements from `src` to `m_part_decoded` where N is the smaller of the two |
129 | | - * sizes. |
130 | | - * @return The smaller of the two sizes. |
131 | | - */ |
132 | | - size_t read_min(const uint8_t *data, size_t size1, size_t size2); |
| 107 | + bool read_until_n(size_t n, Reader &reader); |
133 | 108 |
|
134 | 109 | /** number of bytes readed since last call to `get_decoded` */ |
135 | 110 | size_t m_total_bytes_decoded; |
|
0 commit comments