encoding: change Block::fromBuffer return type

Block::fromBuffer is changed from taking constructed Block as output parameter
to returning the constructed Block as part of returned tuple.

Old API becomes deprecated.

refs #2553

Change-Id: I64610353b8c0780ee09ebe9089c539fa27506a5e
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index 4bbfe52..7bd6a88 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -124,21 +124,52 @@
   static Block
   fromStream(std::istream& is);
 
-  /** @brief Try to construct block from Buffer, referencing data block pointed by wire
+  /** @brief Try to construct block from Buffer
+   *  @param buffer the buffer to construct block from
+   *  @note buffer is passed by value because the constructed block
+   *        takes shared ownership of the buffer
+   *  @param offset offset from beginning of \p buffer to construct Block from
    *
    *  This method does not throw upon decoding error.
-   *  @return true if Block successfully created, false if block cannot be created
+   *  This method does not copy the bytes.
+   *
+   *  @return true and the Block, if Block is successfully created; otherwise false
    */
-  static bool
-  fromBuffer(const ConstBufferPtr& wire, size_t offset, Block& block);
+  static std::tuple<bool, Block>
+  fromBuffer(ConstBufferPtr buffer, size_t offset);
 
-  /** @brief Try to construct block from Buffer, referencing data block pointed by wire
-   *
-   *  This method does not throw upon decoding error.
-   *  @return true if Block successfully created, false if block cannot be created
+  /** @deprecated use fromBuffer(ConstBufferPtr, size_t)
    */
   static bool
-  fromBuffer(const uint8_t* buffer, size_t maxSize, Block& block);
+  fromBuffer(const ConstBufferPtr& buffer, size_t offset, Block& block)
+  {
+    bool isOk = false;
+    std::tie(isOk, block) = Block::fromBuffer(buffer, offset);
+    return isOk;
+  }
+
+  /** @brief Try to construct block from raw buffer
+   *  @param buffer the raw buffer to copy bytes from
+   *  @param maxSize the maximum size of constructed block;
+   *                 @p buffer must have a size of at least @p maxSize
+   *
+   *  This method does not throw upon decoding error.
+   *  This method copies the bytes into a new Buffer.
+   *
+   *  @return true and the Block, if Block is successfully created; otherwise false
+   */
+  static std::tuple<bool, Block>
+  fromBuffer(const uint8_t* buffer, size_t maxSize);
+
+  /** @deprecated use fromBuffer(const uint8_t*, size_t)
+   */
+  static bool
+  fromBuffer(const uint8_t* buffer, size_t maxSize, Block& block)
+  {
+    bool isOk = false;
+    std::tie(isOk, block) = Block::fromBuffer(buffer, maxSize);
+    return isOk;
+  }
 
 public: // wire format
   /** @brief Check if the Block is empty