Skip to content

Commit edff1d1

Browse files
committed
BitVector: Use new serialization API
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent bb6c012 commit edff1d1

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/ccutil/bitvector.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
///////////////////////////////////////////////////////////////////////
2121

2222
#include "bitvector.h"
23+
#include <algorithm>
2324
#include <cstring>
2425
#include "helpers.h"
25-
26-
#include <algorithm>
26+
#include "serialis.h" // for tesseract::Serialize
2727

2828
namespace tesseract {
2929

@@ -137,25 +137,22 @@ void BitVector::Init(int length) {
137137

138138
// Writes to the given file. Returns false in case of error.
139139
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;
141141
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);
145143
}
146144

147145
// Reads from the given file. Returns false in case of error.
148146
// If swap is true, assumes a big/little-endian swap is needed.
149147
bool BitVector::DeSerialize(bool swap, FILE* fp) {
150148
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;
152150
if (swap) {
153151
ReverseN(&new_bit_size, sizeof(new_bit_size));
154152
}
155153
Alloc(new_bit_size);
156154
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;
159156
if (swap) {
160157
for (int i = 0; i < wordlen; ++i)
161158
ReverseN(&array_[i], sizeof(array_[i]));

0 commit comments

Comments
 (0)