MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / SerializeToFile

Method SerializeToFile

src/DartsDict.cpp:441–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

439}
440
441void DartsDict::SerializeToFile(FILE* fp) const {
442 if (internal->doubleArray == nullptr) {
443 throw InvalidFormat(
444 "Cannot serialize a legacy 64-bit OCD dictionary; "
445 "rebuild via NewFromDict first");
446 }
447 Darts::DoubleArray& dict = *internal->doubleArray;
448
449 fwrite(OCDHEADER, sizeof(char), strlen(OCDHEADER), fp);
450
451 // Write dartsSize as uint32_t so the file is platform-independent.
452 // id_type is fixed at uint32_t, so total_size() always fits in 32 bits.
453 uint32_t dartsSize = static_cast<uint32_t>(dict.total_size());
454 fwrite(&dartsSize, sizeof(uint32_t), 1, fp);
455 fwrite(dict.array(), sizeof(char), dartsSize, fp);
456
457 internal->binary.reset(new BinaryDict(lexicon));
458 internal->binary->SerializeToFile(fp);
459}

Callers

nothing calls this directly

Calls 4

fwriteFunction · 0.85
total_sizeMethod · 0.45
arrayMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected