mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48:19 +00:00
Reimplement serialization infrastructure for OpaqueVals.
We need this to sender through Broker, and we also leverage it for cloning opaques. The serialization methods now produce Broker data instances directly, and no longer go through the binary formatter. Summary of the new API for types derived from OpaqueVal: - Add DECLARE_OPAQUE_VALUE(<class>) to the class declaration - Add IMPLEMENT_OPAQUE_VALUE(<class>) to the class' implementation file - Implement these two methods (which are declated by the 1st macro): - broker::data DoSerialize() const - bool DoUnserialize(const broker::data& data) This machinery should work correctly from dynamic plugins as well. OpaqueVal provides a default implementation of DoClone() as well that goes through serialization. Derived classes can provide a more efficient version if they want. The declaration of the "OpaqueVal" class has moved into the header file "OpaqueVal.h", along with the new serialization infrastructure. This is breaking existing code that relies on the location, but because the API is changing anyways that seems fine. This adds an internal BiF "Broker::__opaque_clone_through_serialization" that does what the name says: deep-copying an opaque by serializing, then-deserializing. That can be used to tests the new functionality from btests. Not quite done yet. TODO: - Not all tests pass yet: [ 0%] language.named-set-ctors ... failed [ 16%] language.copy-all-opaques ... failed [ 33%] language.set-type-checking ... failed [ 50%] language.table-init-container-ctors ... failed [ 66%] coverage.sphinx-zeekygen-docs ... failed [ 83%] scripts.base.frameworks.sumstats.basic-cluster ... failed (Some of the serialization may still be buggy.) - Clean up the code a bit more.
This commit is contained in:
parent
1ce5521ecc
commit
01e662b3e0
28 changed files with 1556 additions and 52 deletions
|
@ -3,10 +3,15 @@
|
|||
#ifndef PROBABILISTIC_HASHER_H
|
||||
#define PROBABILISTIC_HASHER_H
|
||||
|
||||
#include <broker/Data.h>
|
||||
|
||||
#include "Hash.h"
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
/** Types of derived Hasher classes. */
|
||||
enum HasherType { Default, Double };
|
||||
|
||||
/**
|
||||
* Abstract base class for hashers. A hasher creates a family of hash
|
||||
* functions to hash an element *k* times.
|
||||
|
@ -98,6 +103,9 @@ public:
|
|||
*/
|
||||
seed_t Seed() const { return seed; }
|
||||
|
||||
broker::expected<broker::data> Serialize() const;
|
||||
static std::unique_ptr<Hasher> Unserialize(const broker::data& data);
|
||||
|
||||
protected:
|
||||
Hasher() { }
|
||||
|
||||
|
@ -110,6 +118,8 @@ protected:
|
|||
*/
|
||||
Hasher(size_t arg_k, seed_t arg_seed);
|
||||
|
||||
virtual HasherType Type() const = 0;
|
||||
|
||||
private:
|
||||
size_t k;
|
||||
seed_t seed;
|
||||
|
@ -175,6 +185,9 @@ public:
|
|||
return ! (x == y);
|
||||
}
|
||||
|
||||
broker::expected<broker::data> Serialize() const;
|
||||
static UHF Unserialize(const broker::data& data);
|
||||
|
||||
private:
|
||||
static size_t compute_seed(Hasher::seed_t seed);
|
||||
|
||||
|
@ -205,6 +218,9 @@ public:
|
|||
private:
|
||||
DefaultHasher() { }
|
||||
|
||||
HasherType Type() const override
|
||||
{ return HasherType::Default; }
|
||||
|
||||
std::vector<UHF> hash_functions;
|
||||
};
|
||||
|
||||
|
@ -231,6 +247,9 @@ public:
|
|||
private:
|
||||
DoubleHasher() { }
|
||||
|
||||
HasherType Type() const override
|
||||
{ return HasherType::Double; }
|
||||
|
||||
UHF h1;
|
||||
UHF h2;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue