3131#include < cstdint>
3232#include < cstring>
3333#include < array>
34+ #include < iostream>
3435#include " dataview-uniq.h"
3536
3637namespace taste {
@@ -49,6 +50,13 @@ struct Request final
4950 */
5051 Request ();
5152
53+ /* *
54+ * @brief Constructor
55+ *
56+ * Constructs Request with provided arguments
57+ */
58+ Request (const asn1SccPID sender_pid, const uint8_t * const data, const size_t length);
59+
5260 // / @brief default copy constructor
5361 Request (const Request& other) = default ;
5462
@@ -65,16 +73,16 @@ struct Request final
6573 *
6674 * @return the actual length of data
6775 */
68- uint32_t length () const ;
76+ size_t length () const ;
6977
7078 /* *
7179 * @brief set the request length
7280 *
73- * The value shall be between 0 and PARAMETER_SIZE
81+ * The length shall be between 0 and PARAMETER_SIZE
7482 *
75- * @param value new length value
83+ * @param length new length value
7684 */
77- void set_length (uint32_t value );
85+ void set_length (size_t length );
7886
7987 /* *
8088 * @brief get the request data
@@ -105,31 +113,45 @@ struct Request final
105113 void set_sender_pid (asn1SccPID sender_pid);
106114
107115 private:
108- uint32_t m_length;
109- std::array<uint8_t , PARAMETER_SIZE > m_data;
116+ void check_length (size_t length) const ;
117+
118+ private:
119+ size_t m_length;
110120 asn1SccPID m_sender_pid;
121+ std::array<uint8_t , PARAMETER_SIZE > m_data;
111122};
112123
113124template <size_t PARAMETER_SIZE >
114125Request<PARAMETER_SIZE >::Request()
115126 : m_length(0 )
127+ , m_sender_pid(PID_env)
116128{
117129}
118130
119131template <size_t PARAMETER_SIZE >
120- uint32_t
132+ Request<PARAMETER_SIZE >::Request(const asn1SccPID sender_pid, const uint8_t * const data, const size_t length)
133+ : m_length(length)
134+ , m_sender_pid(sender_pid)
135+ {
136+ check_length (length);
137+
138+ memcpy (m_data.data (), data, length);
139+ }
140+
141+ template <size_t PARAMETER_SIZE >
142+ size_t
121143Request<PARAMETER_SIZE >::length() const
122144{
123145 return m_length;
124146}
125147
126148template <size_t PARAMETER_SIZE >
127149void
128- Request<PARAMETER_SIZE >::set_length(uint32_t value )
150+ Request<PARAMETER_SIZE >::set_length(size_t length )
129151{
130- if (value <= PARAMETER_SIZE && value >= 0 ) {
131- m_length = value;
132- }
152+ check_length (length);
153+
154+ m_length = length;
133155}
134156
135157template <size_t PARAMETER_SIZE >
@@ -159,6 +181,19 @@ Request<PARAMETER_SIZE>::set_sender_pid(asn1SccPID sender_pid)
159181{
160182 m_sender_pid = sender_pid;
161183}
184+
185+ template <size_t PARAMETER_SIZE >
186+ void
187+ Request<PARAMETER_SIZE >::check_length(size_t length) const
188+ {
189+ if (length > PARAMETER_SIZE ) {
190+ std::cerr << " Request data size shall be <= " << PARAMETER_SIZE << " - new length value ("
191+ << length << " ) is greater than " << PARAMETER_SIZE << std::endl;
192+
193+ exit (EXIT_FAILURE );
194+ }
195+ }
196+
162197} // namespace taste
163198
164199#endif
0 commit comments