Update paraglob serialization.

This commit is contained in:
Zeke Medley 2019-06-20 15:13:31 -07:00
parent a5f6757d7d
commit f1779a2518
2 changed files with 20 additions and 17 deletions

View file

@ -1047,36 +1047,42 @@ bool ParaglobVal::operator==(const ParaglobVal& other) const
return *(this->internal_paraglob) == *(other.internal_paraglob); return *(this->internal_paraglob) == *(other.internal_paraglob);
} }
IMPLEMENT_SERIAL(ParaglobVal, SER_PARAGLOB_VAL) IMPLEMENT_OPAQUE_VALUE(ParaglobVal)
bool ParaglobVal::DoSerialize(SerialInfo* info) const broker::expected<broker::data> ParaglobVal::DoSerialize() const
{ {
DO_SERIALIZE(SER_PARAGLOB_VAL, OpaqueVal) broker::vector d;
std::unique_ptr<std::vector<uint8_t>> iv = this->internal_paraglob->serialize(); std::unique_ptr<std::vector<uint8_t>> iv = this->internal_paraglob->serialize();
for (uint8_t a : *(iv.get()))
return SERIALIZE(iv.get()); d.emplace_back(static_cast<uint64_t>(a));
return {std::move(d)};
} }
bool ParaglobVal::DoUnserialize(UnserialInfo* info) bool ParaglobVal::DoUnserialize(const broker::data& data)
{ {
DO_UNSERIALIZE(OpaqueVal) auto d = caf::get_if<broker::vector>(&data);
if ( ! d )
return false;
std::unique_ptr<std::vector<uint8_t>> iv (new std::vector<uint8_t>); std::unique_ptr<std::vector<uint8_t>> iv (new std::vector<uint8_t>);
iv->resize(d->size());
bool success = UNSERIALIZE(iv.get()); for (std::vector<broker::data>::size_type i = 0; i < d->size(); ++i)
{
get_vector_idx<uint64_t>(*d, i, iv.get()->data() + i);
}
try { try {
this->internal_paraglob = build_unique<paraglob::Paraglob>(std::move(iv)); this->internal_paraglob = build_unique<paraglob::Paraglob>(std::move(iv));
} catch (const paraglob::underflow_error& e) { } catch (const paraglob::underflow_error& e) {
reporter->Error(e.what()); reporter->Error("Paraglob underflow error -> %s", e.what());
return false; return false;
} catch (const paraglob::overflow_error& e) { } catch (const paraglob::overflow_error& e) {
reporter->Error(e.what()); reporter->Error("Paraglob overflow error -> %s", e.what());
return false; return false;
} }
return success; return true;
} }
Val* ParaglobVal::DoClone(CloneState* state) Val* ParaglobVal::DoClone(CloneState* state)

View file

@ -3,12 +3,9 @@
#ifndef OPAQUEVAL_H #ifndef OPAQUEVAL_H
#define OPAQUEVAL_H #define OPAQUEVAL_H
<<<<<<< HEAD
#include <typeinfo> #include <typeinfo>
#include <memory> // std::unique_ptr #include <memory> // std::unique_ptr
=======
>>>>>>> upstream/master
#include "RandTest.h" #include "RandTest.h"
#include "Val.h" #include "Val.h"
#include "digest.h" #include "digest.h"
@ -333,6 +330,8 @@ public:
protected: protected:
ParaglobVal() : OpaqueVal(paraglob_type) {} ParaglobVal() : OpaqueVal(paraglob_type) {}
DECLARE_OPAQUE_VALUE(ParaglobVal)
private: private:
std::unique_ptr<paraglob::Paraglob> internal_paraglob; std::unique_ptr<paraglob::Paraglob> internal_paraglob;
// Small convenience function. Does what std::make_unique does in C++14. Wont // Small convenience function. Does what std::make_unique does in C++14. Wont
@ -341,8 +340,6 @@ private:
std::unique_ptr<T> build_unique (Args&&... args) { std::unique_ptr<T> build_unique (Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
} }
DECLARE_SERIAL(ParaglobVal)
}; };
#endif #endif