41
41
#include < nil/crypto3/multiprecision/cpp_int.hpp>
42
42
#include < nil/crypto3/multiprecision/number.hpp>
43
43
44
+ #include < nil/marshalling/algorithms/pack.hpp>
45
+ #include < nil/marshalling/algorithms/unpack.hpp>
44
46
#include < nil/crypto3/marshalling/types/integral.hpp>
45
47
46
48
template <class T >
@@ -89,7 +91,7 @@ void print_byteblob(TIter iter_begin, TIter iter_end) {
89
91
90
92
template <class T , std::size_t TSize>
91
93
void test_round_trip_fixed_size_container_fixed_precision_big_endian (
92
- nil::marshalling::container::static_vector <T, TSize> val_container) {
94
+ std::array <T, TSize> val_container) {
93
95
using namespace nil ::crypto3::marshalling;
94
96
std::size_t units_bits = 8 ;
95
97
using unit_type = unsigned char ;
@@ -115,27 +117,24 @@ void test_round_trip_fixed_size_container_fixed_precision_big_endian(
115
117
export_bits (val_container[i], cv.begin () + unitblob_size * i + begin_index, units_bits, true );
116
118
}
117
119
118
- auto read_iter = cv.begin ();
119
- nil::marshalling::status_type status = test_val_container.read (read_iter, cv.size ());
120
- BOOST_CHECK (status == nil::marshalling::status_type::success);
120
+ nil::marshalling::status_type status;
121
+ std::array<T, TSize> test_val =
122
+ nil::marshalling::pack<nil::marshalling::option::big_endian,
123
+ std::array<T, TSize>>(cv, status);
121
124
122
- for (std::size_t i = 0 ; i < val_container.size (); i++) {
123
- BOOST_CHECK (val_container[i] == test_val_container.value ()[i].value ());
124
- }
125
+ BOOST_CHECK (std::equal (val_container.begin (), val_container.end (), test_val.begin ()));
126
+ BOOST_CHECK (status == nil::marshalling::status_type::success);
125
127
126
- std::vector<unit_type> test_val_byteblob;
127
- test_val_byteblob.resize (cv.size ());
128
- auto write_iter = test_val_byteblob.begin ();
128
+ std::vector<unit_type> test_cv =
129
+ nil::marshalling::unpack<nil::marshalling::option::big_endian, unit_type>(val_container, status);
129
130
130
- status = test_val_container. write (write_iter, test_val_byteblob. size () * units_bits );
131
+ BOOST_CHECK ( std::equal (test_cv. begin (), test_cv. end (), cv. begin ()) );
131
132
BOOST_CHECK (status == nil::marshalling::status_type::success);
132
-
133
- BOOST_CHECK (cv == test_val_byteblob);
134
133
}
135
134
136
135
template <class T , std::size_t TSize>
137
136
void test_round_trip_fixed_size_container_fixed_precision_little_endian (
138
- nil::marshalling::container::static_vector <T, TSize> val_container) {
137
+ std::array <T, TSize> val_container) {
139
138
using namespace nil ::crypto3::marshalling;
140
139
std::size_t units_bits = 8 ;
141
140
using unit_type = unsigned char ;
@@ -158,32 +157,29 @@ void test_round_trip_fixed_size_container_fixed_precision_little_endian(
158
157
export_bits (val_container[i], cv.begin () + unitblob_size * i, units_bits, false );
159
158
}
160
159
161
- auto read_iter = cv.begin ();
162
- nil::marshalling::status_type status = test_val_container.read (read_iter, cv.size ());
163
- BOOST_CHECK (status == nil::marshalling::status_type::success);
160
+ nil::marshalling::status_type status;
161
+ std::array<T, TSize> test_val =
162
+ nil::marshalling::pack<nil::marshalling::option::little_endian,
163
+ std::array<T, TSize>>(cv, status);
164
164
165
- for (std::size_t i = 0 ; i < val_container.size (); i++) {
166
- BOOST_CHECK (val_container[i] == test_val_container.value ()[i].value ());
167
- }
165
+ BOOST_CHECK (std::equal (val_container.begin (), val_container.end (), test_val.begin ()));
166
+ BOOST_CHECK (status == nil::marshalling::status_type::success);
168
167
169
- std::vector<unit_type> test_val_byteblob;
170
- test_val_byteblob.resize (cv.size ());
171
- auto write_iter = test_val_byteblob.begin ();
168
+ std::vector<unit_type> test_cv =
169
+ nil::marshalling::unpack<nil::marshalling::option::little_endian, unit_type>(val_container, status);
172
170
173
- status = test_val_container. write (write_iter, test_val_byteblob. size () * units_bits );
171
+ BOOST_CHECK ( std::equal (test_cv. begin (), test_cv. end (), cv. begin ()) );
174
172
BOOST_CHECK (status == nil::marshalling::status_type::success);
175
-
176
- BOOST_CHECK (cv == test_val_byteblob);
177
173
}
178
174
179
175
template <class T , std::size_t TSize>
180
176
void test_round_trip_fixed_size_container_fixed_precision () {
181
177
std::cout << std::hex;
182
178
std::cerr << std::hex;
183
179
for (unsigned i = 0 ; i < 1000 ; ++i) {
184
- nil::marshalling::container::static_vector <T, TSize> val_container;
180
+ std::array <T, TSize> val_container;
185
181
for (std::size_t i = 0 ; i < TSize; i++) {
186
- val_container. push_back ( generate_random<T>() );
182
+ val_container[i] = generate_random<T>();
187
183
}
188
184
test_round_trip_fixed_size_container_fixed_precision_big_endian<T, TSize>(val_container);
189
185
test_round_trip_fixed_size_container_fixed_precision_little_endian<T, TSize>(val_container);
0 commit comments