diff options
author | ishbosamiya <ishbosamiya@gmail.com> | 2021-07-26 15:24:39 +0300 |
---|---|---|
committer | ishbosamiya <ishbosamiya@gmail.com> | 2021-07-26 15:24:39 +0300 |
commit | a4350ffaec80acd22894b3d4470b9bbb2fe2ac3a (patch) | |
tree | a470c1fc70b555c5c137dd0d56bd575921f8030c /source | |
parent | c277047cb37636a16ae84bed5a71000bf8d0d312 (diff) |
msgpack: blender::Vector<T>: packer implementation
Implement msgpack's packer for blender::Vector<T>.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_vector_msgpack.hh | 50 | ||||
-rw-r--r-- | source/blender/blenlib/CMakeLists.txt | 2 |
2 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_vector_msgpack.hh b/source/blender/blenlib/BLI_vector_msgpack.hh new file mode 100644 index 00000000000..59708c16999 --- /dev/null +++ b/source/blender/blenlib/BLI_vector_msgpack.hh @@ -0,0 +1,50 @@ +/* + * 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::Vector<T>` + */ + +#include "BLI_vector.hh" + +#include "msgpack.hpp" + +namespace msgpack { +MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) +{ + namespace adaptor { + + template<typename T> struct pack<blender::Vector<T>> { + template<typename Stream> + msgpack::packer<Stream> &operator()(msgpack::packer<Stream> &o, + const blender::Vector<T> &v) const + { + uint32_t size = checked_get_container_size(v.size()); + o.pack_array(size); + for (const auto &val : v) { + o.pack(val); + } + 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 85c2925eabf..c42623736bf 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -27,6 +27,7 @@ set(INC ../../../intern/guardedalloc ../../../intern/numaapi/include ../../../extern/wcwidth + ../../../extern/msgpack/include ) set(INC_SYS @@ -298,6 +299,7 @@ set(SRC BLI_uvproject.h BLI_vector.hh BLI_vector_adaptor.hh + BLI_vector_msgpack.hh BLI_vector_set.hh BLI_vector_set_slots.hh BLI_vfontdata.h |