From fea736428e883eb7f05bfc70baa8a1d4d0c4c611 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Sat, 14 Dec 2019 11:43:22 -0500
Subject: [PATCH] msgpack: take const reference in unpack

---
 include/opendht/crypto.h        | 6 +++---
 include/opendht/default_types.h | 4 ++--
 include/opendht/utils.h         | 2 +-
 include/opendht/value.h         | 4 ++--
 src/crypto.cpp                  | 6 +++---
 src/utils.cpp                   | 2 +-
 src/value.cpp                   | 2 +-
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h
index 284c6486..82e53a3f 100644
--- a/include/opendht/crypto.h
+++ b/include/opendht/crypto.h
@@ -127,7 +127,7 @@ struct OPENDHT_PUBLIC PublicKey
         p.pack_bin_body((const char*)b.data(), b.size());
     }
 
-    void msgpack_unpack(msgpack::object o);
+    void msgpack_unpack(const msgpack::object& o);
 
     gnutls_digest_algorithm_t getPreferredDigest() const;
 
@@ -225,7 +225,7 @@ public:
         p.pack_bin_body((const char*)b.data(), b.size());
     }
 
-    void msgpack_unpack(msgpack::object o);
+    void msgpack_unpack(const msgpack::object& o);
 
     void revoke(const Certificate& crt, time_point t = time_point::min());
 
@@ -423,7 +423,7 @@ struct OPENDHT_PUBLIC Certificate {
         p.pack_bin_body((const char*)b.data(), b.size());
     }
 
-    void msgpack_unpack(msgpack::object o);
+    void msgpack_unpack(const msgpack::object& o);
 
     explicit operator bool() const { return cert; }
     PublicKey getPublicKey() const;
diff --git a/include/opendht/default_types.h b/include/opendht/default_types.h
index 11a3c558..e8027a02 100644
--- a/include/opendht/default_types.h
+++ b/include/opendht/default_types.h
@@ -189,7 +189,7 @@ public:
 #endif
     }
 
-    virtual void msgpack_unpack(msgpack::object o)
+    virtual void msgpack_unpack(const msgpack::object& o)
     {
         if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
         if (o.via.array.size < 2) throw msgpack::type_error();
@@ -229,7 +229,7 @@ public:
         pk.pack_bin_body((const char*)addr.get(), addr.getLength());
     }
 
-    virtual void msgpack_unpack(msgpack::object o)
+    virtual void msgpack_unpack(const msgpack::object& o)
     {
         if (o.type == msgpack::type::BIN)
             addr = {(sockaddr*)o.via.bin.ptr, (socklen_t)o.via.bin.size};
diff --git a/include/opendht/utils.h b/include/opendht/utils.h
index 4df44f6b..a8099547 100644
--- a/include/opendht/utils.h
+++ b/include/opendht/utils.h
@@ -133,7 +133,7 @@ using Blob = std::vector<uint8_t>;
 /**
  * Provides backward compatibility with msgpack 1.0
  */
-OPENDHT_PUBLIC Blob unpackBlob(msgpack::object& o);
+OPENDHT_PUBLIC Blob unpackBlob(const msgpack::object& o);
 
 template <typename Type>
 Blob
diff --git a/include/opendht/value.h b/include/opendht/value.h
index bf5b8b61..5677d459 100644
--- a/include/opendht/value.h
+++ b/include/opendht/value.h
@@ -551,7 +551,7 @@ struct OPENDHT_PUBLIC Value
             }
     }
 
-    void msgpack_unpack(msgpack::object o);
+    void msgpack_unpack(const msgpack::object& o);
     void msgpack_unpack_body(const msgpack::object& o);
     Blob getPacked() const {
         msgpack::sbuffer buffer;
@@ -658,7 +658,7 @@ struct OPENDHT_PUBLIC FieldValue
         }
     }
 
-    void msgpack_unpack(msgpack::object msg) {
+    void msgpack_unpack(const msgpack::object& msg) {
         hashValue = {};
         blobValue.clear();
 
diff --git a/src/crypto.cpp b/src/crypto.cpp
index 216253a5..ba69b8e6 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -447,7 +447,7 @@ PublicKey::toString() const
 }
 
 void
-PublicKey::msgpack_unpack(msgpack::object o)
+PublicKey::msgpack_unpack(const msgpack::object& o)
 {
     if (o.type == msgpack::type::BIN)
         unpack((const uint8_t*)o.via.bin.ptr, o.via.bin.size);
@@ -792,7 +792,7 @@ Certificate::unpack(const uint8_t* dat, size_t dat_size)
 }
 
 void
-Certificate::msgpack_unpack(msgpack::object o)
+Certificate::msgpack_unpack(const msgpack::object& o)
 {
     if (o.type == msgpack::type::BIN)
         unpack((const uint8_t*)o.via.bin.ptr, o.via.bin.size);
@@ -1252,7 +1252,7 @@ RevocationList::unpack(const uint8_t* dat, size_t dat_size)
 }
 
 void
-RevocationList::msgpack_unpack(msgpack::object o)
+RevocationList::msgpack_unpack(const msgpack::object& o)
 {
     try {
         if (o.type == msgpack::type::BIN)
diff --git a/src/utils.cpp b/src/utils.cpp
index 3d6576e9..3067905b 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -246,7 +246,7 @@ std::time_t to_time_t(time_point t) {
 }
 
 Blob
-unpackBlob(msgpack::object& o) {
+unpackBlob(const msgpack::object& o) {
     switch (o.type) {
     case msgpack::type::BIN:
         return {o.via.bin.ptr, o.via.bin.ptr+o.via.bin.size};
diff --git a/src/value.cpp b/src/value.cpp
index 7dc83fba..ed2a10d1 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -94,7 +94,7 @@ Value::size() const
 }
 
 void
-Value::msgpack_unpack(msgpack::object o)
+Value::msgpack_unpack(const msgpack::object& o)
 {
     if (o.type != msgpack::type::MAP) throw msgpack::type_error();
     if (o.via.map.size < 2) throw msgpack::type_error();
-- 
GitLab