@@ -308,9 +308,9 @@ namespace py = pybind11;
308308 // 2. call class method to serialize external state
309309
310310 // Serialize main state of the Python module
311- // We want this to end up in a string that we pass back to Cereal.
312- // a. We first pickle the python into an in-memory byte stream.
313- // b. We then convert that to a Base64 std::string that is returned.
311+ // We want this to end up in a string that we pass back to Cereal.
312+ // a. We first pickle the python into an in-memory byte stream.
313+ // b. We then convert that to a Base64 std::string that is returned.
314314 //
315315 // Basicly, we are executing the following Python code:
316316 // import io
@@ -322,32 +322,32 @@ namespace py = pybind11;
322322 // content = str(base64.b64encode(b))
323323 // f.close()
324324
325- py::tuple args;
326- auto f = py::module::import (" io" ).attr (" BytesIO" )();
325+ py::tuple args;
326+ auto f = py::module::import (" io" ).attr (" BytesIO" )();
327327
328328#if PY_MAJOR_VERSION >= 3
329- auto pickle = py::module::import (" pickle" );
329+ auto pickle = py::module::import (" pickle" );
330330 auto highest = pickle.attr (" HIGHEST_PROTOCOL" );
331- args = py::make_tuple (node_, f, highest); // use type 3,4, or 5 protocol
331+ args = py::make_tuple (node_, f, highest); // use type 3,4, or 5 protocol
332332#else
333- auto pickle = py::module::import (" cPickle" );
334- args = py::make_tuple (node_, f, 2 ); // use type 2 protocol
333+ auto pickle = py::module::import (" cPickle" );
334+ args = py::make_tuple (node_, f, 2 ); // use type 2 protocol
335335#endif
336- pickle.attr (" dump" )(*args);
336+ pickle.attr (" dump" )(*args);
337337
338- // copy the pickle stream into the content as a base64 encoded utf8 string
338+ // copy the pickle stream into the content as a base64 encoded utf8 string
339339 py::bytes b = f.attr (" getvalue" )();
340340 args = py::make_tuple (b);
341- std::string content = py::str (py::module::import (" base64" ).attr (" b64encode" )(*args));
342- if (content[1 ] == ' \' ' ) // strip off leading "b'" and trailing "'"
341+ std::string content = py::str (py::module::import (" base64" ).attr (" b64encode" )(*args));
342+ if (content[1 ] == ' \' ' ) { // strip off leading "b'" and trailing "'"
343343 content = content.substr (2 , content.length () - 3 );
344-
345- f.attr (" close" )();
346- return content;
344+ }
345+ f.attr (" close" )();
346+ return content;
347347 }
348348 std::string PyBindRegion::extraSerialize () const
349349 {
350- std::string tmp_extra = " extra.tmp" ;
350+ std::string tmp_extra = " extra.tmp" ;
351351
352352 // 2. External state
353353 // Call the Python serializeExtraData() method to write additional data.
@@ -356,21 +356,21 @@ namespace py = pybind11;
356356 // Need to put the None result in py::Ptr to decrement the ref count
357357 node_.attr (" serializeExtraData" )(*args);
358358
359- // copy the extra data into the extra string
360- std::ifstream efile (tmp_extra.c_str (), std::ios::binary);
361- std::string extra ((std::istreambuf_iterator<char >(efile)),
362- std::istreambuf_iterator<char >());
363- efile.close ();
364- Path::remove (tmp_extra);
365- return extra;
359+ // copy the extra data into the extra string
360+ std::ifstream efile (tmp_extra.c_str (), std::ios::binary);
361+ std::string extra ((std::istreambuf_iterator<char >(efile)),
362+ std::istreambuf_iterator<char >());
363+ efile.close ();
364+ Path::remove (tmp_extra);
365+ return extra;
366366
367367 }
368368
369369 void PyBindRegion::pickleDeserialize (std::string p) {
370370 // 1. deserialize main state using pickle
371371 // 2. call class method to deserialize external state
372372 //
373- // Tell Python to un-pickle using what is in the string p.
373+ // Tell Python to un-pickle using what is in the string p.
374374 // but first we need to convert the base64 string into bytes.
375375 //
376376 // Basically we are executing the following Python code:
@@ -386,7 +386,7 @@ namespace py = pybind11;
386386 args = py::make_tuple (py::bytes (p));
387387 py::bytes b = py::module::import (" base64" ).attr (" b64decode" )(*args);
388388 args = py::make_tuple (b);
389- auto f = py::module::import (" io" ).attr (" BytesIO" )(*args);
389+ auto f = py::module::import (" io" ).attr (" BytesIO" )(*args);
390390
391391#if PY_MAJOR_VERSION >= 3
392392 auto pickle = py::module::import (" pickle" );
@@ -397,19 +397,19 @@ namespace py = pybind11;
397397 node_ = pickle.attr (" load" )(*args);
398398
399399 f.attr (" close" )();
400- }
400+ }
401401
402- void PyBindRegion::extraDeserialize (std::string e) {
402+ void PyBindRegion::extraDeserialize (std::string e) {
403403 // 2. External state
404- std::string tmp_extra = " extra.tmp" ;
405- std::ofstream efile (tmp_extra.c_str (), std::ios::binary);
406- efile.write (e.c_str (), e.size ());
407- efile.close ();
404+ std::string tmp_extra = " extra.tmp" ;
405+ std::ofstream efile (tmp_extra.c_str (), std::ios::binary);
406+ efile.write (e.c_str (), e.size ());
407+ efile.close ();
408408
409409 // Call the Python deSerializeExtraData() method
410410 py::tuple args = py::make_tuple (tmp_extra);
411411 node_.attr (" deSerializeExtraData" )(*args);
412- Path::remove (tmp_extra);
412+ Path::remove (tmp_extra);
413413 }
414414
415415
0 commit comments