]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/ObjectStore: helpers for validating map<string,string> and set<string> to bl
authorSage Weil <sage@redhat.com>
Mon, 19 Oct 2015 18:37:04 +0000 (14:37 -0400)
committerSage Weil <sage@redhat.com>
Mon, 19 Oct 2015 19:05:49 +0000 (15:05 -0400)
Test/validate the encoding, and reference the resulting (encoded) data in
a bufferlist.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/ObjectStore.cc
src/os/ObjectStore.h

index 8e8886baa61721ac6af89c59e4e2c7d921a108d2..aa62fbda691d4f6d6012b081eee9f5644b94c5e4 100644 (file)
 #include "newstore/NewStore.h"
 #endif
 
+void decode_str_str_map_to_bl(bufferlist::iterator& p,
+                             bufferlist *out)
+{
+  bufferlist::iterator start = p;
+  __u32 n;
+  ::decode(n, p);
+  unsigned len = 4;
+  while (n--) {
+    __u32 l;
+    ::decode(l, p);
+    p.advance(l);
+    len += 4 + l;
+    ::decode(l, p);
+    p.advance(l);
+    len += 4 + l;
+  }
+  start.copy(len, *out);
+}
+
+void decode_str_set_to_bl(bufferlist::iterator& p,
+                         bufferlist *out)
+{
+  bufferlist::iterator start = p;
+  __u32 n;
+  ::decode(n, p);
+  unsigned len = 4;
+  while (n--) {
+    __u32 l;
+    ::decode(l, p);
+    p.advance(l);
+    len += 4 + l;
+  }
+  start.copy(len, *out);
+}
+
 ObjectStore *ObjectStore::create(CephContext *cct,
                                 const string& type,
                                 const string& data,
index ba4c7d2852d1002fa6f15b2127eb185ed9ded0bb..dcb7e601ccd8530b1d00795b0d83f4fbdfad48fe 100644 (file)
@@ -84,6 +84,10 @@ static inline void encode(const map<string,bufferptr> *attrset, bufferlist &bl)
   ::encode(*attrset, bl);
 }
 
+// this isn't the best place for these, but...
+void decode_str_str_map_to_bl(bufferlist::iterator& p, bufferlist *out);
+void decode_str_set_to_bl(bufferlist::iterator& p, bufferlist *out);
+
 // Flag bits
 typedef uint32_t osflagbits_t;
 const int SKIP_JOURNAL_REPLAY = 1 << 0;
@@ -836,9 +840,15 @@ public:
       void decode_attrset(map<string,bufferlist>& aset) {
         ::decode(aset, data_bl_p);
       }
+      void decode_attrset_bl(bufferlist *pbl) {
+       decode_str_str_map_to_bl(data_bl_p, pbl);
+      }
       void decode_keyset(set<string> &keys){
         ::decode(keys, data_bl_p);
       }
+      void decode_keyset_bl(bufferlist *pbl){
+        decode_str_set_to_bl(data_bl_p, pbl);
+      }
 
       const ghobject_t &get_oid(__le32 oid_id) {
         assert(oid_id < objects.size());