Skip to content

Commit 6cf5089

Browse files
committed
UnicharAndFonts, Shape: Use new serialization API
Signed-off-by: Stefan Weil <[email protected]>
1 parent 07b363f commit 6cf5089

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/classify/shapetable.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ int UnicharRating::FirstResultWithUnichar(
6767

6868
// Writes to the given file. Returns false in case of error.
6969
bool UnicharAndFonts::Serialize(FILE* fp) const {
70-
if (fwrite(&unichar_id, sizeof(unichar_id), 1, fp) != 1) return false;
71-
return font_ids.Serialize(fp);
70+
return tesseract::Serialize(fp, &unichar_id) && font_ids.Serialize(fp);
7271
}
7372
// Reads from the given file. Returns false in case of error.
7473

7574
bool UnicharAndFonts::DeSerialize(TFile* fp) {
76-
if (fp->FReadEndian(&unichar_id, sizeof(unichar_id), 1) != 1) return false;
77-
return font_ids.DeSerialize(fp);
75+
return fp->DeSerialize(&unichar_id) && font_ids.DeSerialize(fp);
7876
}
7977

8078
// Sort function to sort a pair of UnicharAndFonts by unichar_id.
@@ -87,15 +85,13 @@ int UnicharAndFonts::SortByUnicharId(const void* v1, const void* v2) {
8785
// Writes to the given file. Returns false in case of error.
8886
bool Shape::Serialize(FILE* fp) const {
8987
uint8_t sorted = unichars_sorted_;
90-
if (fwrite(&sorted, sizeof(sorted), 1, fp) != 1)
91-
return false;
92-
return unichars_.SerializeClasses(fp);
88+
return tesseract::Serialize(fp, &sorted) && unichars_.SerializeClasses(fp);
9389
}
9490
// Reads from the given file. Returns false in case of error.
9591

9692
bool Shape::DeSerialize(TFile* fp) {
9793
uint8_t sorted;
98-
if (fp->FRead(&sorted, sizeof(sorted), 1) != 1) return false;
94+
if (!fp->DeSerialize(&sorted)) return false;
9995
unichars_sorted_ = sorted != 0;
10096
return unichars_.DeSerializeClasses(fp);
10197
}

0 commit comments

Comments
 (0)