Skip to content

Commit

Permalink
Merge pull request #377
Browse files Browse the repository at this point in the history
  • Loading branch information
Neverlord committed Dec 15, 2023
2 parents 091d6f2 + be7241d commit 0643e87
Show file tree
Hide file tree
Showing 17 changed files with 915 additions and 83 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.8.0-dev.20 | 2023-12-15 20:59:14 +0100

* Implement encoding for text and binary formats (Dominik Charousset, Corelight)

- implement new encoding functions for both text and binary
- start versioning the Broker data formats in the API
- integrate the new encoding functions into text rendering and serialization

2.8.0-dev.18 | 2023-12-14 19:56:46 -0800

* CI updates (Christian Kreibich, Corelight)
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ set(BROKER_SRC
src/entity_id.cc
src/error.cc
src/filter_type.cc
src/format/bin.cc
src/internal/clone_actor.cc
src/internal/connector.cc
src/internal/connector_adapter.cc
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.0-dev.18
2.8.0-dev.20
6 changes: 5 additions & 1 deletion include/broker/data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public:
enum_value,
set,
table,
vector,
list,
vector = list, // Alias for backward compatibility.
};

template <class T>
Expand Down Expand Up @@ -369,6 +370,9 @@ DATA_TAG_ORACLE(vector);

} // namespace detail

template <class T>
inline constexpr data::type data_tag_v = detail::data_tag_oracle<T>::value;

/// Returns the `data::type` tag for `T`.
/// @relates data
template <class T>
Expand Down
81 changes: 79 additions & 2 deletions include/broker/detail/type_traits.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#pragma once

#include <cstddef>

#include <list>
#include <map>
#include <optional>
#include <type_traits>
#include <unordered_map>
#include <variant>
#include <vector>

namespace broker {

Expand All @@ -14,6 +19,60 @@ class topic;

namespace broker::detail {

template <class>
struct is_variant_oracle : std::false_type {};

template <class... Ts>
struct is_variant_oracle<std::variant<Ts...>> : std::true_type {};

template <class T>
inline constexpr bool is_variant = is_variant_oracle<T>::value;

template <class>
struct is_optional_oracle : std::false_type {};

template <class T>
struct is_optional_oracle<std::optional<T>> : std::true_type {};

template <class T>
inline constexpr bool is_optional = is_optional_oracle<T>::value;

template <class>
struct is_array_oracle : std::false_type {};

template <class T, size_t N>
struct is_array_oracle<std::array<T, N>> : std::true_type {};

template <class T, size_t N>
struct is_array_oracle<T[N]> : std::true_type {};

template <class T>
inline constexpr bool is_array = is_array_oracle<T>::value;

template <class>
struct is_map_oracle : std::false_type {};

template <class Key, class Val>
struct is_map_oracle<std::map<Key, Val>> : std::true_type {};

template <class Key, class Val>
struct is_map_oracle<std::unordered_map<Key, Val>> : std::true_type {};

template <class T>
inline constexpr bool is_map = is_map_oracle<T>::value;

template <class>
struct is_list_oracle : std::false_type {};

template <class T>
struct is_list_oracle<std::list<T>> : std::true_type {};

template <class T>
struct is_list_oracle<std::vector<T>> : std::true_type {};

template <class T>
inline constexpr bool is_list = is_list_oracle<T>::value;

template <class T>
struct tag {
using type = T;
Expand All @@ -36,7 +95,7 @@ struct are_same<A, B> {

template <class A, class B, class C, class... Ts>
struct are_same<A, B, C, Ts...> {
static constexpr bool value =
static constexpr bool value = //
std::is_same_v<A, B> && are_same<B, C, Ts...>::value;
};

Expand Down Expand Up @@ -131,3 +190,21 @@ template <class F>
using signature_of_t = typename signature_of_oracle<F>::type;

} // namespace broker::detail

#define BROKER_DEF_HAS_ENCODE_IN_NS(ns_name) \
template <class T, class OutIter> \
class has_encode_overload { \
private: \
template <class U> \
static auto sfinae(U& y) \
-> decltype(::ns_name::encode(y, std::declval<OutIter&>()), \
std::true_type{}); \
static std::false_type sfinae(...); \
using result_type = decltype(sfinae(std::declval<T&>())); \
\
public: \
static constexpr bool value = result_type::value; \
}; \
template <class T, class OutIter> \
inline constexpr bool has_encode_overload_v = \
has_encode_overload<T, OutIter>::value
Loading

0 comments on commit 0643e87

Please sign in to comment.