From 537b7e26aad9c2e77b7d5f276f32dc2be9bcfe90 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 23 Oct 2018 13:46:03 -0700 Subject: [PATCH] ircd::m::state: Add unmake_key() inverse convenience to make_key(). --- include/ircd/m/state.h | 1 + ircd/m/state.cc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/ircd/m/state.h b/include/ircd/m/state.h index dc43515c6..16823e1a1 100644 --- a/include/ircd/m/state.h +++ b/include/ircd/m/state.h @@ -53,6 +53,7 @@ namespace ircd::m::state bool prefix_eq(const json::array &a, const json::array &b); json::array make_key(const mutable_buffer &out, const string_view &type, const string_view &state_key); json::array make_key(const mutable_buffer &out, const string_view &type); + string_view unmake_key(const mutable_buffer &out, const json::array &); id set_node(db::txn &txn, const mutable_buffer &id, const json::object &node); bool get_node(const std::nothrow_t, const string_view &id, const node_closure &); diff --git a/ircd/m/state.cc b/ircd/m/state.cc index a8a8e0568..0ed078e4c 100644 --- a/ircd/m/state.cc +++ b/ircd/m/state.cc @@ -829,6 +829,22 @@ ircd::m::state::set_node(db::txn &iov, return hashb64; } +/// Convenience inverse of make_key. +ircd::string_view +ircd::m::state::unmake_key(const mutable_buffer &out, + const json::array &key) +{ + window_buffer wb{out}; + for(const auto &part : key) + wb([&part](const mutable_buffer &buf) + { + assert(json::type(part) == json::STRING); + return copy(buf, unquote(part)); + }); + + return wb.completed(); +} + /// Creates a key array from the most common key pattern of a matrix /// room (type,state_key). ircd::json::array