mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Add facade types to avoid using raw Broker types
By avoiding to use `broker::data` directly, we gain a degree of freedom that allows us to swap out `broker::data` for something else (e.g., `broker::variant`) in the future. Furthermore, it also helps us to keep Broker types "local" to the Broker manager and gives us a nicer interface. Also replaces uses of `broker::expected` with `std::optional`. While an `expected `can carry additional information as to why a value is not present, nothing in Zeek ever cared about that. Hence, using `std::optional` removes an unnecessary dependency on a Broker detail while also being more efficient (no extra heap allocation when no value is present).
This commit is contained in:
parent
bc0f85caa8
commit
647fdf7737
30 changed files with 1091 additions and 552 deletions
|
@ -2,8 +2,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <broker/data.hh>
|
||||
#include <broker/expected.hh>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
@ -21,6 +19,9 @@ namespace zeek {
|
|||
|
||||
using ValPtr = IntrusivePtr<Val>;
|
||||
|
||||
class BrokerListView;
|
||||
class BrokerData;
|
||||
|
||||
namespace detail {
|
||||
|
||||
class CallExpr;
|
||||
|
@ -171,7 +172,7 @@ public:
|
|||
* sequence of two-element vectors, the first element reflecting
|
||||
* the frame value, the second its type.
|
||||
*/
|
||||
broker::expected<broker::data> Serialize();
|
||||
std::optional<BrokerData> Serialize();
|
||||
|
||||
/**
|
||||
* Instantiates a Frame from a serialized one.
|
||||
|
@ -180,7 +181,7 @@ public:
|
|||
* and the second is the unserialized frame with reference count +1, or
|
||||
* null if the serialization wasn't successful.
|
||||
*/
|
||||
static std::pair<bool, FramePtr> Unserialize(const broker::vector& data);
|
||||
static std::pair<bool, FramePtr> Unserialize(BrokerListView data);
|
||||
|
||||
// If the frame is run in the context of a trigger condition evaluation,
|
||||
// the trigger needs to be registered.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue