mirror of
https://github.com/matrix-construct/construct
synced 2024-05-28 15:53:46 +02:00
ircd::json: Abstract the source json::object out of m::event for all tuples by default.
This commit is contained in:
parent
de8fc1d05f
commit
c1692de5ed
|
@ -33,7 +33,7 @@ struct tuple_base
|
|||
///
|
||||
/// Here we represent a JSON object with a named tuple, allowing the programmer
|
||||
/// to create a structure specifying all of the potentially valid members of the
|
||||
/// object. Thus at runtime, the tuple only carries around its values like a
|
||||
/// object. Thus at runtime, the tuple carries around its values like a
|
||||
/// `struct`. Unlike a `struct`, the tuple is abstractly iterable and we have
|
||||
/// implemented logic operating on all JSON tuples regardless of their makeup
|
||||
/// without any effort from a developer when creating a new tuple.
|
||||
|
@ -62,6 +62,12 @@ struct tuple
|
|||
operator json::value() const;
|
||||
operator crh::sha256::buf() const;
|
||||
|
||||
/// For json::object constructions, the source JSON (string_view) is
|
||||
/// carried with the instance. This is important to convey additional
|
||||
/// keys not enumerated in the tuple. This will be default-initialized
|
||||
/// for other constructions when no source JSON buffer is available.
|
||||
json::object source;
|
||||
|
||||
template<class name> constexpr decltype(auto) get(name&&) const noexcept;
|
||||
template<class name> constexpr decltype(auto) get(name&&) noexcept;
|
||||
template<class name> constexpr decltype(auto) at(name&&) const;
|
||||
|
@ -183,6 +189,10 @@ template<class... T>
|
|||
template<class U>
|
||||
tuple<T...>::tuple(const json::object &object,
|
||||
const json::keys<U> &keys)
|
||||
:source
|
||||
{
|
||||
object
|
||||
}
|
||||
{
|
||||
std::for_each(std::begin(object), std::end(object), [this, &keys]
|
||||
(const auto &member)
|
||||
|
@ -194,6 +204,10 @@ tuple<T...>::tuple(const json::object &object,
|
|||
|
||||
template<class... T>
|
||||
tuple<T...>::tuple(const json::object &object)
|
||||
:source
|
||||
{
|
||||
object
|
||||
}
|
||||
{
|
||||
std::for_each(std::begin(object), std::end(object), [this]
|
||||
(const auto &member)
|
||||
|
@ -226,6 +240,10 @@ template<class... T>
|
|||
template<class U>
|
||||
tuple<T...>::tuple(const tuple &t,
|
||||
const keys<U> &keys)
|
||||
:source
|
||||
{
|
||||
t.source
|
||||
}
|
||||
{
|
||||
for_each(t, [this, &keys]
|
||||
(const auto &key, const auto &val)
|
||||
|
@ -238,6 +256,10 @@ tuple<T...>::tuple(const tuple &t,
|
|||
template<class... T>
|
||||
template<class... U>
|
||||
tuple<T...>::tuple(const tuple<U...> &t)
|
||||
:source
|
||||
{
|
||||
t.source
|
||||
}
|
||||
{
|
||||
for_each(t, [this]
|
||||
(const auto &key, const auto &val)
|
||||
|
|
|
@ -131,13 +131,6 @@ struct ircd::m::event
|
|||
static sha256::buf hash(const json::object &);
|
||||
static json::object hashes(const mutable_buffer &, json::iov &event, const string_view &content);
|
||||
|
||||
/// For json::object constructions, the source JSON (string_view) is
|
||||
/// carried with the m::event instance. This is important to convey
|
||||
/// additional keys not enumerated in the m::event tuple. This will be
|
||||
/// default-initialized for other constructions when no source JSON buffer
|
||||
/// is available.
|
||||
json::object source;
|
||||
|
||||
/// Always set for PDU's, not set for EDU's. The reference to the event_id
|
||||
/// for this event. For v1 events, this may point to somewhere inside the
|
||||
/// source; otherwise the event source may have been hashed into a buffer
|
||||
|
|
|
@ -1120,10 +1120,6 @@ ircd::m::event::event(const json::object &source)
|
|||
{
|
||||
source
|
||||
}
|
||||
,source
|
||||
{
|
||||
source
|
||||
}
|
||||
,event_id
|
||||
{
|
||||
defined(json::get<"event_id"_>(*this))?
|
||||
|
@ -1139,10 +1135,6 @@ ircd::m::event::event(const json::object &source,
|
|||
{
|
||||
source, keys
|
||||
}
|
||||
,source
|
||||
{
|
||||
source
|
||||
}
|
||||
,event_id
|
||||
{
|
||||
defined(json::get<"event_id"_>(*this))?
|
||||
|
@ -1180,10 +1172,6 @@ try
|
|||
{
|
||||
source
|
||||
}
|
||||
,source
|
||||
{
|
||||
source
|
||||
}
|
||||
,event_id
|
||||
{
|
||||
event_id?
|
||||
|
@ -1215,10 +1203,6 @@ try
|
|||
{
|
||||
source, keys
|
||||
}
|
||||
,source
|
||||
{
|
||||
source
|
||||
}
|
||||
,event_id
|
||||
{
|
||||
event_id?
|
||||
|
|
Loading…
Reference in a new issue