[Bf-blender-cvs] [6852a815162] soc-2021-adaptive-cloth: msgpack: blender::Map<Key, Value>: packer implementation

ishbosamiya noreply at git.blender.org
Wed Aug 4 11:29:31 CEST 2021


Commit: 6852a815162406a53d0b25992625b1856e6eae81
Author: ishbosamiya
Date:   Mon Jul 26 23:56:44 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB6852a815162406a53d0b25992625b1856e6eae81

msgpack: blender::Map<Key, Value>: packer implementation

===================================================================

A	source/blender/blenlib/BLI_map_msgpack.hh
M	source/blender/blenlib/CMakeLists.txt

===================================================================

diff --git a/source/blender/blenlib/BLI_map_msgpack.hh b/source/blender/blenlib/BLI_map_msgpack.hh
new file mode 100644
index 00000000000..8d2a33314c9
--- /dev/null
+++ b/source/blender/blenlib/BLI_map_msgpack.hh
@@ -0,0 +1,54 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bli
+ *
+ * msgpack implementation for `blender::Map<T>`
+ */
+
+#include "BLI_map.hh"
+
+#include "msgpack.hpp"
+
+namespace msgpack {
+MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
+{
+  namespace adaptor {
+
+  template<typename Key, typename Value> struct pack<blender::Map<Key, Value>> {
+    template<typename Stream>
+    msgpack::packer<Stream> &operator()(msgpack::packer<Stream> &o,
+                                        const blender::Map<Key, Value> &v) const
+    {
+      uint32_t size = checked_get_container_size(v.size());
+      o.pack_map(size);
+      auto pack_key_and_value = [&](const Key &key, const Value &value) {
+        o.pack(key);
+        o.pack(value);
+      };
+
+      v.foreach_item(pack_key_and_value);
+
+      return o;
+    }
+  };
+
+  }  // namespace adaptor
+}  // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
+}  // namespace msgpack
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 95c9d340e88..f17bc5b6a38 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -228,6 +228,7 @@ set(SRC
   BLI_listbase.h
   BLI_listbase_wrapper.hh
   BLI_map.hh
+  BLI_map_msgpack.hh
   BLI_map_slots.hh
   BLI_math.h
   BLI_math_base.h



More information about the Bf-blender-cvs mailing list