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:
Dominik Charousset 2023-11-11 09:21:00 +01:00
parent bc0f85caa8
commit 647fdf7737
30 changed files with 1091 additions and 552 deletions

View file

@ -18,17 +18,12 @@
#include "zeek/ZeekArgs.h"
#include "zeek/ZeekList.h"
namespace broker {
class data;
using vector = std::vector<data>;
template<class>
class expected;
} // namespace broker
namespace zeek {
class Val;
class FuncType;
class BrokerData;
class BrokerListView;
namespace detail {
@ -231,14 +226,14 @@ public:
*
* @return a serialized version of the function's capture frame.
*/
virtual broker::expected<broker::data> SerializeCaptures() const;
virtual std::optional<BrokerData> SerializeCaptures() const;
/**
* Sets the captures frame to one built from *data*.
*
* @param data a serialized frame
*/
bool DeserializeCaptures(const broker::vector& data);
bool DeserializeCaptures(BrokerListView data);
using Func::AddBody;