|
20 | 20 | ///////////////////////////////////////////////////////////////////////
|
21 | 21 |
|
22 | 22 | #include "bitvector.h"
|
| 23 | +#include <algorithm> |
23 | 24 | #include <cstring>
|
24 | 25 | #include "helpers.h"
|
25 |
| - |
26 |
| -#include <algorithm> |
| 26 | +#include "serialis.h" // for tesseract::Serialize |
27 | 27 |
|
28 | 28 | namespace tesseract {
|
29 | 29 |
|
@@ -137,25 +137,22 @@ void BitVector::Init(int length) {
|
137 | 137 |
|
138 | 138 | // Writes to the given file. Returns false in case of error.
|
139 | 139 | bool BitVector::Serialize(FILE* fp) const {
|
140 |
| - if (fwrite(&bit_size_, sizeof(bit_size_), 1, fp) != 1) return false; |
| 140 | + if (!tesseract::Serialize(fp, &bit_size_)) return false; |
141 | 141 | int wordlen = WordLength();
|
142 |
| - if (static_cast<int>(fwrite(array_, sizeof(*array_), wordlen, fp)) != wordlen) |
143 |
| - return false; |
144 |
| - return true; |
| 142 | + return tesseract::Serialize(fp, &array_[0], wordlen); |
145 | 143 | }
|
146 | 144 |
|
147 | 145 | // Reads from the given file. Returns false in case of error.
|
148 | 146 | // If swap is true, assumes a big/little-endian swap is needed.
|
149 | 147 | bool BitVector::DeSerialize(bool swap, FILE* fp) {
|
150 | 148 | uint32_t new_bit_size;
|
151 |
| - if (fread(&new_bit_size, sizeof(new_bit_size), 1, fp) != 1) return false; |
| 149 | + if (!tesseract::DeSerialize(fp, &new_bit_size)) return false; |
152 | 150 | if (swap) {
|
153 | 151 | ReverseN(&new_bit_size, sizeof(new_bit_size));
|
154 | 152 | }
|
155 | 153 | Alloc(new_bit_size);
|
156 | 154 | int wordlen = WordLength();
|
157 |
| - if (static_cast<int>(fread(array_, sizeof(*array_), wordlen, fp)) != wordlen) |
158 |
| - return false; |
| 155 | + if (!tesseract::DeSerialize(fp, &array_[0], wordlen)) return false; |
159 | 156 | if (swap) {
|
160 | 157 | for (int i = 0; i < wordlen; ++i)
|
161 | 158 | ReverseN(&array_[i], sizeof(array_[i]));
|
|
0 commit comments