From 1019ec1324409fd22f43efe2c353066ac45f2579 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 19 Oct 2015 14:28:34 -0400 Subject: [PATCH] kv/KeyValueDB: add bufferlist-based set() and rmkeys() interface Often the caller has an encoded bl and not an STL map/set. Signed-off-by: Sage Weil --- src/kv/KeyValueDB.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/kv/KeyValueDB.h b/src/kv/KeyValueDB.h index 8691694ef3c5d..ccccf06e25dd4 100644 --- a/src/kv/KeyValueDB.h +++ b/src/kv/KeyValueDB.h @@ -10,6 +10,7 @@ #include #include "include/memory.h" #include +#include "include/encoding.h" using std::string; /** @@ -31,6 +32,23 @@ public: set(prefix, it->first, it->second); } + /// Set Keys (via encoded bufferlist) + void set( + const std::string &prefix, ///< [in] prefix + bufferlist& to_set_bl ///< [in] encoded key/values to set + ) { + bufferlist::iterator p = to_set_bl.begin(); + uint32_t num; + ::decode(num, p); + while (num--) { + string key; + bufferlist value; + ::decode(key, p); + ::decode(value, p); + set(prefix, key, value); + } + } + /// Set Key virtual void set( const std::string &prefix, ///< [in] Prefix for the key @@ -39,6 +57,21 @@ public: ) = 0; + /// Removes Keys (via encoded bufferlist) + void rmkeys( + const std::string &prefix, ///< [in] Prefix to search for + bufferlist &keys_bl ///< [in] Keys to remove + ) { + bufferlist::iterator p = keys_bl.begin(); + uint32_t num; + ::decode(num, p); + while (num--) { + string key; + ::decode(key, p); + rmkey(prefix, key); + } + } + /// Removes Keys void rmkeys( const std::string &prefix, ///< [in] Prefix to search for -- 2.39.5