0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 00:10:59 +01:00

ircd:Ⓜ️:state: Add unmake_key() inverse convenience to make_key().

This commit is contained in:
Jason Volk 2018-10-23 13:46:03 -07:00
parent 33aea3fd19
commit 537b7e26aa
2 changed files with 17 additions and 0 deletions

View file

@ -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 &);

View file

@ -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