mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +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
|
@ -586,7 +586,7 @@ void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body) {
|
|||
current_body = new_body;
|
||||
}
|
||||
|
||||
bool ScriptFunc::DeserializeCaptures(const broker::vector& data) {
|
||||
bool ScriptFunc::DeserializeCaptures(BrokerListView data) {
|
||||
auto result = Frame::Unserialize(data);
|
||||
|
||||
ASSERT(result.first);
|
||||
|
@ -649,7 +649,7 @@ FuncPtr ScriptFunc::DoClone() {
|
|||
return other;
|
||||
}
|
||||
|
||||
broker::expected<broker::data> ScriptFunc::SerializeCaptures() const {
|
||||
std::optional<BrokerData> ScriptFunc::SerializeCaptures() const {
|
||||
if ( captures_vec ) {
|
||||
auto& cv = *captures_vec;
|
||||
auto& captures = *type->GetCaptures();
|
||||
|
@ -668,7 +668,7 @@ broker::expected<broker::data> ScriptFunc::SerializeCaptures() const {
|
|||
return captures_frame->Serialize();
|
||||
|
||||
// No captures, return an empty vector.
|
||||
return broker::vector{};
|
||||
return BrokerListBuilder{}.Build();
|
||||
}
|
||||
|
||||
void ScriptFunc::Describe(ODesc* d) const {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue