Skip to content

Commit

Permalink
UnicharAndFonts, Shape: Use new serialization API
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Jul 18, 2018
1 parent 07b363f commit 6cf5089
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/classify/shapetable.cpp
Expand Up @@ -67,14 +67,12 @@ int UnicharRating::FirstResultWithUnichar(

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

bool UnicharAndFonts::DeSerialize(TFile* fp) {
if (fp->FReadEndian(&unichar_id, sizeof(unichar_id), 1) != 1) return false;
return font_ids.DeSerialize(fp);
return fp->DeSerialize(&unichar_id) && font_ids.DeSerialize(fp);
}

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

bool Shape::DeSerialize(TFile* fp) {
uint8_t sorted;
if (fp->FRead(&sorted, sizeof(sorted), 1) != 1) return false;
if (!fp->DeSerialize(&sorted)) return false;
unichars_sorted_ = sorted != 0;
return unichars_.DeSerializeClasses(fp);
}
Expand Down

0 comments on commit 6cf5089

Please sign in to comment.