]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add encode and decode routines for opaque vectors of bytes
authorJeff Layton <jlayton@redhat.com>
Tue, 4 May 2021 18:22:43 +0000 (14:22 -0400)
committerXiubo Li <xiubli@redhat.com>
Thu, 13 Jan 2022 13:08:21 +0000 (21:08 +0800)
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/include/encoding.h

index 49f2f77be30bb246e48b8c4ce413773a72fcfb6b..40ba9d39c76f819573c181cd41de5ad59be86b38 100644 (file)
@@ -246,6 +246,23 @@ inline void encode(const char *s, bufferlist& bl)
   encode(std::string_view(s, strlen(s)), bl);
 }
 
+// opaque byte vectors
+inline void encode(std::vector<uint8_t>& v, bufferlist& bl)
+{
+  uint32_t len = v.size();
+  encode(len, bl);
+  if (len)
+    bl.append((char *)v.data(), len);
+}
+
+inline void decode(std::vector<uint8_t>& v, bufferlist::const_iterator& p)
+{
+  uint32_t len;
+
+  decode(len, p);
+  v.resize(len);
+  p.copy(len, (char *)v.data());
+}
 
 // -----------------------------
 // buffers