mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Update paraglob serialization.
This commit is contained in:
parent
a5f6757d7d
commit
f1779a2518
2 changed files with 20 additions and 17 deletions
|
@ -1047,36 +1047,42 @@ bool ParaglobVal::operator==(const ParaglobVal& other) const
|
|||
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();
|
||||
|
||||
return SERIALIZE(iv.get());
|
||||
for (uint8_t a : *(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>);
|
||||
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 {
|
||||
this->internal_paraglob = build_unique<paraglob::Paraglob>(std::move(iv));
|
||||
} catch (const paraglob::underflow_error& e) {
|
||||
reporter->Error(e.what());
|
||||
reporter->Error("Paraglob underflow error -> %s", e.what());
|
||||
return false;
|
||||
} catch (const paraglob::overflow_error& e) {
|
||||
reporter->Error(e.what());
|
||||
reporter->Error("Paraglob overflow error -> %s", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
|
||||
Val* ParaglobVal::DoClone(CloneState* state)
|
||||
|
|
|
@ -3,12 +3,9 @@
|
|||
#ifndef OPAQUEVAL_H
|
||||
#define OPAQUEVAL_H
|
||||
|
||||
<<<<<<< HEAD
|
||||
#include <typeinfo>
|
||||
#include <memory> // std::unique_ptr
|
||||
|
||||
=======
|
||||
>>>>>>> upstream/master
|
||||
#include "RandTest.h"
|
||||
#include "Val.h"
|
||||
#include "digest.h"
|
||||
|
@ -333,6 +330,8 @@ public:
|
|||
protected:
|
||||
ParaglobVal() : OpaqueVal(paraglob_type) {}
|
||||
|
||||
DECLARE_OPAQUE_VALUE(ParaglobVal)
|
||||
|
||||
private:
|
||||
std::unique_ptr<paraglob::Paraglob> internal_paraglob;
|
||||
// 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) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
DECLARE_SERIAL(ParaglobVal)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue