| 182 | } // namespace |
| 183 | |
| 184 | std::string encode(const BinaryArray &data) { |
| 185 | size_t full_block_count = data.size() / full_block_size; |
| 186 | size_t last_block_size = data.size() % full_block_size; |
| 187 | size_t res_size = full_block_count * full_encoded_block_size + encoded_block_sizes[last_block_size]; |
| 188 | |
| 189 | std::string res(res_size, '*'); // All asterisks must be replaced after encoding |
| 190 | for (size_t i = 0; i < full_block_count; ++i) { |
| 191 | encode_block(data.data() + i * full_block_size, full_block_size, &res[i * full_encoded_block_size]); |
| 192 | } |
| 193 | if (last_block_size > 0) { |
| 194 | encode_block(data.data() + full_block_count * full_block_size, last_block_size, |
| 195 | &res[full_block_count * full_encoded_block_size]); |
| 196 | } |
| 197 | return res; |
| 198 | } |
| 199 | |
| 200 | bool decode(const std::string &enc, BinaryArray *data) { |
| 201 | size_t full_block_count = enc.size() / full_encoded_block_size; |
no test coverage detected