mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
serializer/broker: Expose to_broker_event() and to_zeek_event()
This is useful for reuse by WebSocket clients that use the JSON v1 encoding.
This commit is contained in:
parent
e8d91c8227
commit
273a6ec1f3
2 changed files with 24 additions and 20 deletions
|
@ -20,15 +20,7 @@
|
||||||
|
|
||||||
using namespace zeek::cluster;
|
using namespace zeek::cluster;
|
||||||
|
|
||||||
namespace {
|
std::optional<broker::zeek::Event> detail::to_broker_event(const detail::Event& ev) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a cluster::detail::Event to a broker::zeek::Event.
|
|
||||||
*
|
|
||||||
* @param ev The cluster::detail::Event
|
|
||||||
* @return A broker::zeek::Event to be serialized, or nullopt in case of errors.
|
|
||||||
*/
|
|
||||||
std::optional<broker::zeek::Event> to_broker_event(const detail::Event& ev) {
|
|
||||||
broker::vector xs;
|
broker::vector xs;
|
||||||
xs.reserve(ev.args.size());
|
xs.reserve(ev.args.size());
|
||||||
|
|
||||||
|
@ -51,15 +43,7 @@ std::optional<broker::zeek::Event> to_broker_event(const detail::Event& ev) {
|
||||||
return broker::zeek::Event(ev.HandlerName(), xs, broker::to_timestamp(ev.timestamp));
|
return broker::zeek::Event(ev.HandlerName(), xs, broker::to_timestamp(ev.timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
std::optional<detail::Event> detail::to_zeek_event(const broker::zeek::Event& ev) {
|
||||||
* Convert a broker::zeek::Event to cluster::detail::Event by looking
|
|
||||||
* it up in Zeek's event handler registry and converting event arguments
|
|
||||||
* to the appropriate Val instances.
|
|
||||||
*
|
|
||||||
* @param broker_ev The broker side event.
|
|
||||||
* @returns A zeek::cluster::detail::Event instance, or std::nullopt if the conversion failed.
|
|
||||||
*/
|
|
||||||
std::optional<detail::Event> to_zeek_event(const broker::zeek::Event& ev) {
|
|
||||||
auto&& name = ev.name();
|
auto&& name = ev.name();
|
||||||
auto&& args = ev.args();
|
auto&& args = ev.args();
|
||||||
|
|
||||||
|
@ -117,8 +101,6 @@ std::optional<detail::Event> to_zeek_event(const broker::zeek::Event& ev) {
|
||||||
return detail::Event{handler, std::move(vl), ts};
|
return detail::Event{handler, std::move(vl), ts};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
bool detail::BrokerBinV1_Serializer::SerializeEvent(detail::byte_buffer& buf, const detail::Event& event) {
|
bool detail::BrokerBinV1_Serializer::SerializeEvent(detail::byte_buffer& buf, const detail::Event& event) {
|
||||||
auto ev = to_broker_event(event);
|
auto ev = to_broker_event(event);
|
||||||
if ( ! ev )
|
if ( ! ev )
|
||||||
|
|
|
@ -4,8 +4,30 @@
|
||||||
|
|
||||||
#include "zeek/cluster/Serializer.h"
|
#include "zeek/cluster/Serializer.h"
|
||||||
|
|
||||||
|
namespace broker::zeek {
|
||||||
|
class Event;
|
||||||
|
}
|
||||||
|
|
||||||
namespace zeek::cluster::detail {
|
namespace zeek::cluster::detail {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a broker::zeek::Event to cluster::detail::Event by looking
|
||||||
|
* it up in Zeek's event handler registry and converting event arguments
|
||||||
|
* to the appropriate Val instances.
|
||||||
|
*
|
||||||
|
* @param ev The broker side event.
|
||||||
|
* @returns A zeek::cluster::detail::Event instance, or std::nullopt if the conversion failed.
|
||||||
|
*/
|
||||||
|
std::optional<detail::Event> to_zeek_event(const broker::zeek::Event& ev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a cluster::detail::Event to a broker::zeek::Event.
|
||||||
|
*
|
||||||
|
* @param ev The cluster::detail::Event
|
||||||
|
* @return A broker::zeek::Event to be serialized, or nullopt in case of errors.
|
||||||
|
*/
|
||||||
|
std::optional<broker::zeek::Event> to_broker_event(const detail::Event& ev);
|
||||||
|
|
||||||
// Implementation of the EventSerializer using the existing broker::detail::val_to_data()
|
// Implementation of the EventSerializer using the existing broker::detail::val_to_data()
|
||||||
// and broker::format::bin::v1::encode().
|
// and broker::format::bin::v1::encode().
|
||||||
class BrokerBinV1_Serializer : public EventSerializer {
|
class BrokerBinV1_Serializer : public EventSerializer {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue