Skip to content

Commit

Permalink
✨ feat(serialize): add magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
y.qiu committed Jul 19, 2022
1 parent be67a03 commit 009cc13
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ppf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace ppf {

const int VERSION = 100;
const int MAGIC = 0x7F27F;

const float M_2PI = 2 * M_PI;

Expand Down Expand Up @@ -469,6 +470,7 @@ void Detector::save(const std::string &filename) const {
if (!impl_)
throw std::runtime_error("No trained model in save");

serialize(&of, MAGIC);
serialize(&of, VERSION);
serialize(&of, impl_->samplingDistanceRel);
serialize(&of, impl_->param);
Expand All @@ -484,6 +486,10 @@ void Detector::load(const std::string &filename) {
throw std::runtime_error("failed to open file:" + filename);
impl_ = std::make_unique<IMPL>();

int magic;
deserialize(&ifs, magic);
if (MAGIC != magic)
throw std::runtime_error("unsupported file format:" + filename);
int version;
deserialize(&ifs, version);
deserialize(&ifs, impl_->samplingDistanceRel);
Expand Down

0 comments on commit 009cc13

Please sign in to comment.