Convert to span and avoid deprecated ndn-cxx functions

Change-Id: I45c50527fe53498b53a3d951458bdff8e7d7778c
diff --git a/daemon/face/datagram-transport.hpp b/daemon/face/datagram-transport.hpp
index 7798cc8..e0e2f58 100644
--- a/daemon/face/datagram-transport.hpp
+++ b/daemon/face/datagram-transport.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -46,7 +46,7 @@
 class DatagramTransport : public Transport
 {
 public:
-  typedef Protocol protocol;
+  using protocol = Protocol;
 
   /** \brief Construct datagram transport.
    *
@@ -58,11 +58,11 @@
   ssize_t
   getSendQueueLength() override;
 
-  /** \brief Receive datagram, translate buffer into packet, deliver to parent class.
+  /**
+   * \brief Receive datagram, translate buffer into packet, deliver to parent class.
    */
   void
-  receiveDatagram(const uint8_t* buffer, size_t nBytesReceived,
-                  const boost::system::error_code& error);
+  receiveDatagram(span<const uint8_t> buffer, const boost::system::error_code& error);
 
 protected:
   void
@@ -170,23 +170,23 @@
 
 template<class T, class U>
 void
-DatagramTransport<T, U>::receiveDatagram(const uint8_t* buffer, size_t nBytesReceived,
+DatagramTransport<T, U>::receiveDatagram(span<const uint8_t> buffer,
                                          const boost::system::error_code& error)
 {
   if (error)
     return processErrorCode(error);
 
-  NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes from " << m_sender);
+  NFD_LOG_FACE_TRACE("Received: " << buffer.size() << " bytes from " << m_sender);
 
   bool isOk = false;
   Block element;
-  std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
+  std::tie(isOk, element) = Block::fromBuffer(buffer);
   if (!isOk) {
     NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << m_sender);
     // This packet won't extend the face lifetime
     return;
   }
-  if (element.size() != nBytesReceived) {
+  if (element.size() != buffer.size()) {
     NFD_LOG_FACE_WARN("Received datagram size and decoded element size don't match");
     // This packet won't extend the face lifetime
     return;
@@ -200,7 +200,7 @@
 void
 DatagramTransport<T, U>::handleReceive(const boost::system::error_code& error, size_t nBytesReceived)
 {
-  receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
+  receiveDatagram(ndn::make_span(m_receiveBuffer).first(nBytesReceived), error);
 
   if (m_socket.is_open())
     m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
diff --git a/daemon/face/ethernet-channel.cpp b/daemon/face/ethernet-channel.cpp
index 512d078..5f3f295 100644
--- a/daemon/face/ethernet-channel.cpp
+++ b/daemon/face/ethernet-channel.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -120,26 +120,24 @@
     return;
   }
 
-  const uint8_t* pkt;
-  size_t len;
+  span<const uint8_t> pkt;
   std::string err;
-  std::tie(pkt, len, err) = m_pcap.readNextPacket();
+  std::tie(pkt, err) = m_pcap.readNextPacket();
 
-  if (pkt == nullptr) {
+  if (pkt.empty()) {
     NFD_LOG_CHAN_WARN("Read error: " << err);
   }
   else {
     const ether_header* eh;
-    std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, m_localEndpoint->getEthernetAddress(),
+    std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_localEndpoint->getEthernetAddress(),
                                                    m_localEndpoint->getEthernetAddress());
     if (eh == nullptr) {
       NFD_LOG_CHAN_DEBUG(err);
     }
     else {
       ethernet::Address sender(eh->ether_shost);
-      pkt += ethernet::HDR_LEN;
-      len -= ethernet::HDR_LEN;
-      processIncomingPacket(pkt, len, sender, onFaceCreated, onReceiveFailed);
+      pkt = pkt.subspan(ethernet::HDR_LEN);
+      processIncomingPacket(pkt, sender, onFaceCreated, onReceiveFailed);
     }
   }
 
@@ -154,7 +152,7 @@
 }
 
 void
-EthernetChannel::processIncomingPacket(const uint8_t* packet, size_t length,
+EthernetChannel::processIncomingPacket(span<const uint8_t> packet,
                                        const ethernet::Address& sender,
                                        const FaceCreatedCallback& onFaceCreated,
                                        const FaceCreationFailedCallback& onReceiveFailed)
@@ -182,7 +180,7 @@
 
   // dispatch the packet to the face for processing
   auto* transport = static_cast<UnicastEthernetTransport*>(face->getTransport());
-  transport->receivePayload(packet, length, sender);
+  transport->receivePayload(packet, sender);
 }
 
 std::pair<bool, shared_ptr<Face>>
diff --git a/daemon/face/ethernet-channel.hpp b/daemon/face/ethernet-channel.hpp
index 7e7fa87..510b7aa 100644
--- a/daemon/face/ethernet-channel.hpp
+++ b/daemon/face/ethernet-channel.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2021,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -111,7 +111,7 @@
              const FaceCreationFailedCallback& onReceiveFailed);
 
   void
-  processIncomingPacket(const uint8_t* packet, size_t length,
+  processIncomingPacket(span<const uint8_t> packet,
                         const ethernet::Address& sender,
                         const FaceCreatedCallback& onFaceCreated,
                         const FaceCreationFailedCallback& onReceiveFailed);
diff --git a/daemon/face/ethernet-protocol.cpp b/daemon/face/ethernet-protocol.cpp
index e5e9a69..0a0ebe1 100644
--- a/daemon/face/ethernet-protocol.cpp
+++ b/daemon/face/ethernet-protocol.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -30,14 +30,13 @@
 namespace nfd {
 namespace ethernet {
 
-std::pair<const ether_header*, std::string>
-checkFrameHeader(const uint8_t* packet, size_t length,
-                 const Address& localAddr, const Address& destAddr)
+std::tuple<const ether_header*, std::string>
+checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Address& destAddr)
 {
-  if (length < HDR_LEN + MIN_DATA_LEN)
-    return {nullptr, "Received frame too short: " + to_string(length) + " bytes"};
+  if (packet.size() < HDR_LEN + MIN_DATA_LEN)
+    return {nullptr, "Received frame too short: " + to_string(packet.size()) + " bytes"};
 
-  const ether_header* eh = reinterpret_cast<const ether_header*>(packet);
+  const ether_header* eh = reinterpret_cast<const ether_header*>(packet.data());
 
   // in some cases VLAN-tagged frames may survive the BPF filter,
   // make sure we do not process those frames (see #3348)
diff --git a/daemon/face/ethernet-protocol.hpp b/daemon/face/ethernet-protocol.hpp
index 639c678..c9b9bdc 100644
--- a/daemon/face/ethernet-protocol.hpp
+++ b/daemon/face/ethernet-protocol.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -27,6 +27,7 @@
 #define NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
 
 #include "core/common.hpp"
+
 #include <ndn-cxx/net/ethernet.hpp>
 #include <net/ethernet.h>
 
@@ -35,9 +36,8 @@
 
 using namespace ndn::ethernet;
 
-std::pair<const ether_header*, std::string>
-checkFrameHeader(const uint8_t* packet, size_t length,
-                 const Address& localAddr, const Address& destAddr);
+std::tuple<const ether_header*, std::string>
+checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Address& destAddr);
 
 } // namespace ethernet
 } // namespace nfd
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index e98a9a7..7aac95a 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -125,17 +125,17 @@
   // pad with zeroes if the payload is too short
   if (block.size() < ethernet::MIN_DATA_LEN) {
     static const uint8_t padding[ethernet::MIN_DATA_LEN] = {};
-    buffer.appendByteArray(padding, ethernet::MIN_DATA_LEN - block.size());
+    buffer.appendBytes(ndn::make_span(padding).subspan(block.size()));
   }
 
   // construct and prepend the ethernet header
   uint16_t ethertype = boost::endian::native_to_big(ethernet::ETHERTYPE_NDN);
-  buffer.prependByteArray(reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN);
-  buffer.prependByteArray(m_srcAddress.data(), m_srcAddress.size());
-  buffer.prependByteArray(m_destAddress.data(), m_destAddress.size());
+  buffer.prependBytes({reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN});
+  buffer.prependBytes(m_srcAddress);
+  buffer.prependBytes(m_destAddress);
 
   // send the frame
-  int sent = pcap_inject(m_pcap, buffer.buf(), buffer.size());
+  int sent = pcap_inject(m_pcap, buffer.data(), buffer.size());
   if (sent < 0)
     handleError("Send operation failed: " + m_pcap.getLastError());
   else if (static_cast<size_t>(sent) < buffer.size())
@@ -168,26 +168,24 @@
     return;
   }
 
-  const uint8_t* pkt;
-  size_t len;
+  span<const uint8_t> pkt;
   std::string err;
-  std::tie(pkt, len, err) = m_pcap.readNextPacket();
+  std::tie(pkt, err) = m_pcap.readNextPacket();
 
-  if (pkt == nullptr) {
+  if (pkt.empty()) {
     NFD_LOG_FACE_WARN("Read error: " << err);
   }
   else {
     const ether_header* eh;
-    std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, m_srcAddress,
+    std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_srcAddress,
                                                    m_destAddress.isMulticast() ? m_destAddress : m_srcAddress);
     if (eh == nullptr) {
       NFD_LOG_FACE_WARN(err);
     }
     else {
       ethernet::Address sender(eh->ether_shost);
-      pkt += ethernet::HDR_LEN;
-      len -= ethernet::HDR_LEN;
-      receivePayload(pkt, len, sender);
+      pkt = pkt.subspan(ethernet::HDR_LEN);
+      receivePayload(pkt, sender);
     }
   }
 
@@ -202,14 +200,13 @@
 }
 
 void
-EthernetTransport::receivePayload(const uint8_t* payload, size_t length,
-                                  const ethernet::Address& sender)
+EthernetTransport::receivePayload(span<const uint8_t> payload, const ethernet::Address& sender)
 {
-  NFD_LOG_FACE_TRACE("Received: " << length << " bytes from " << sender);
+  NFD_LOG_FACE_TRACE("Received: " << payload.size() << " bytes from " << sender);
 
   bool isOk = false;
   Block element;
-  std::tie(isOk, element) = Block::fromBuffer(payload, length);
+  std::tie(isOk, element) = Block::fromBuffer(payload);
   if (!isOk) {
     NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << sender);
     // This packet won't extend the face lifetime
diff --git a/daemon/face/ethernet-transport.hpp b/daemon/face/ethernet-transport.hpp
index 8c929d1..1379899 100644
--- a/daemon/face/ethernet-transport.hpp
+++ b/daemon/face/ethernet-transport.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -49,13 +49,11 @@
 
   /**
    * @brief Processes the payload of an incoming frame
-   * @param payload Pointer to the first byte of data after the Ethernet header
-   * @param length Payload length
+   * @param payload Payload bytes, starting from the first byte after the Ethernet header
    * @param sender Sender address
    */
   void
-  receivePayload(const uint8_t* payload, size_t length,
-                 const ethernet::Address& sender);
+  receivePayload(span<const uint8_t> payload, const ethernet::Address& sender);
 
 protected:
   EthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
diff --git a/daemon/face/lp-reassembler.cpp b/daemon/face/lp-reassembler.cpp
index d19f799..77a7120 100644
--- a/daemon/face/lp-reassembler.cpp
+++ b/daemon/face/lp-reassembler.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -69,10 +69,9 @@
 
   // check for fast path
   if (fragIndex == 0 && fragCount == 1) {
-    ndn::Buffer::const_iterator fragBegin, fragEnd;
-    std::tie(fragBegin, fragEnd) = packet.get<lp::FragmentField>();
-    Block netPkt(&*fragBegin, std::distance(fragBegin, fragEnd));
-    return std::make_tuple(true, netPkt, packet);
+    auto frag = packet.get<lp::FragmentField>();
+    Block netPkt({frag.first, frag.second});
+    return {true, netPkt, packet};
   }
 
   // check Sequence and compute message identifier
@@ -140,7 +139,7 @@
     it = std::copy(fragBegin, fragEnd, it);
   }
 
-  return Block(&*(fragBuffer.cbegin()), std::distance(fragBuffer.cbegin(), fragBuffer.cend()));
+  return Block(fragBuffer);
 }
 
 void
diff --git a/daemon/face/lp-reliability.cpp b/daemon/face/lp-reliability.cpp
index f387add..95849b1 100644
--- a/daemon/face/lp-reliability.cpp
+++ b/daemon/face/lp-reliability.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -174,7 +174,7 @@
       // Check for recent received Sequences to remove
       auto now = time::steady_clock::now();
       auto rto = m_rttEst.getEstimatedRto();
-      while (m_recentRecvSeqsQueue.size() > 0 &&
+      while (!m_recentRecvSeqsQueue.empty() &&
              now > m_recentRecvSeqs[m_recentRecvSeqsQueue.front()] + rto) {
         m_recentRecvSeqs.erase(m_recentRecvSeqsQueue.front());
         m_recentRecvSeqsQueue.pop();
@@ -226,7 +226,7 @@
 {
   lp::Sequence txSeq = ++m_lastTxSeqNo;
   frag.set<lp::TxSequenceField>(txSeq);
-  if (m_unackedFrags.size() > 0 && m_lastTxSeqNo == m_firstUnackedFrag->first) {
+  if (!m_unackedFrags.empty() && m_lastTxSeqNo == m_firstUnackedFrag->first) {
     NDN_THROW(std::length_error("TxSequence range exceeded"));
   }
   return m_lastTxSeqNo;
@@ -310,10 +310,8 @@
     // Notify strategy of dropped Interest (if any)
     if (netPkt->isInterest) {
       BOOST_ASSERT(netPkt->pkt.has<lp::FragmentField>());
-      ndn::Buffer::const_iterator fragBegin, fragEnd;
-      std::tie(fragBegin, fragEnd) = netPkt->pkt.get<lp::FragmentField>();
-      Block frag(&*fragBegin, std::distance(fragBegin, fragEnd));
-      onDroppedInterest(Interest(frag));
+      auto frag = netPkt->pkt.get<lp::FragmentField>();
+      onDroppedInterest(Interest(Block({frag.first, frag.second})));
     }
 
     // Delete this LpPacket from m_unackedFrags
diff --git a/daemon/face/pcap-helper.cpp b/daemon/face/pcap-helper.cpp
index b7873fe..d481ac5 100644
--- a/daemon/face/pcap-helper.cpp
+++ b/daemon/face/pcap-helper.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2021,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -79,7 +79,7 @@
 }
 
 void
-PcapHelper::close()
+PcapHelper::close() noexcept
 {
   if (m_pcap) {
     pcap_close(m_pcap);
@@ -100,7 +100,7 @@
 }
 
 std::string
-PcapHelper::getLastError() const
+PcapHelper::getLastError() const noexcept
 {
   return pcap_geterr(m_pcap);
 }
@@ -128,19 +128,19 @@
     NDN_THROW(Error("pcap_setfilter: " + getLastError()));
 }
 
-std::tuple<const uint8_t*, size_t, std::string>
-PcapHelper::readNextPacket() const
+std::tuple<span<const uint8_t>, std::string>
+PcapHelper::readNextPacket() const noexcept
 {
   pcap_pkthdr* header;
   const uint8_t* packet;
 
   int ret = pcap_next_ex(m_pcap, &header, &packet);
   if (ret < 0)
-    return std::make_tuple(nullptr, 0, getLastError());
+    return {span<uint8_t>{}, getLastError()};
   else if (ret == 0)
-    return std::make_tuple(nullptr, 0, "timed out");
+    return {span<uint8_t>{}, "timed out"};
   else
-    return std::make_tuple(packet, header->caplen, "");
+    return {{packet, header->caplen}, ""};
 }
 
 } // namespace face
diff --git a/daemon/face/pcap-helper.hpp b/daemon/face/pcap-helper.hpp
index 1f08d85..30a8deb 100644
--- a/daemon/face/pcap-helper.hpp
+++ b/daemon/face/pcap-helper.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2021,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -79,7 +79,7 @@
    * @sa pcap_close(3pcap)
    */
   void
-  close();
+  close() noexcept;
 
   /**
    * @brief Obtain a file descriptor that can be used in calls such as select(2) and poll(2).
@@ -98,7 +98,7 @@
    * @sa pcap_geterr(3pcap)
    */
   std::string
-  getLastError() const;
+  getLastError() const noexcept;
 
   /**
    * @brief Get the number of packets dropped by the kernel, as reported by libpcap.
@@ -120,18 +120,17 @@
 
   /**
    * @brief Read the next packet captured on the interface.
-   * @return If successful, returns a tuple containing a pointer to the received packet
-   *         (including the link-layer header) and the size of the packet; the third
-   *         element must be ignored. On failure, returns a tuple containing nullptr,
-   *         0, and the reason for the failure.
-   * @warning The returned pointer must not be freed by the caller, and is valid only
-   *          until the next call to this function.
+   * @return If successful, returns a tuple containing a read-only view of the received
+   *         packet bytes (including the link-layer header) and a second element that
+   *         must be ignored. On failure, returns a tuple containing an empty span and
+   *         the reason for the failure.
+   * @warning The returned span is valid only until the next call to this function.
    * @sa pcap_next_ex(3pcap)
    */
-  std::tuple<const uint8_t*, size_t, std::string>
-  readNextPacket() const;
+  std::tuple<span<const uint8_t>, std::string>
+  readNextPacket() const noexcept;
 
-  operator pcap_t*() const
+  operator pcap_t*() const noexcept
   {
     return m_pcap;
   }
diff --git a/daemon/face/stream-transport.hpp b/daemon/face/stream-transport.hpp
index a6fcb74..c4ae849 100644
--- a/daemon/face/stream-transport.hpp
+++ b/daemon/face/stream-transport.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -43,7 +43,7 @@
 class StreamTransport : public Transport
 {
 public:
-  typedef Protocol protocol;
+  using protocol = Protocol;
 
   /** \brief Construct stream transport.
    *
@@ -244,16 +244,17 @@
   NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
 
   m_receiveBufferSize += nBytesReceived;
+  auto bufferView = ndn::make_span(m_receiveBuffer, m_receiveBufferSize);
   size_t offset = 0;
   bool isOk = true;
-  while (m_receiveBufferSize - offset > 0) {
+  while (offset < bufferView.size()) {
     Block element;
-    std::tie(isOk, element) = Block::fromBuffer(m_receiveBuffer + offset, m_receiveBufferSize - offset);
+    std::tie(isOk, element) = Block::fromBuffer(bufferView.subspan(offset));
     if (!isOk)
       break;
 
     offset += element.size();
-    BOOST_ASSERT(offset <= m_receiveBufferSize);
+    BOOST_ASSERT(offset <= bufferView.size());
 
     this->receive(element);
   }
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index a5d9dee..bb836d2 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2021,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -141,7 +141,7 @@
 
   // dispatch the datagram to the face for processing
   auto* transport = static_cast<UnicastUdpTransport*>(face->getTransport());
-  transport->receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
+  transport->receiveDatagram(ndn::make_span(m_receiveBuffer).first(nBytesReceived), error);
 
   waitForNewPeer(onFaceCreated, onReceiveFailed);
 }
diff --git a/daemon/face/websocket-transport.cpp b/daemon/face/websocket-transport.cpp
index 3ac0023..33ae643 100644
--- a/daemon/face/websocket-transport.cpp
+++ b/daemon/face/websocket-transport.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -98,7 +98,7 @@
 
   bool isOk = false;
   Block element;
-  std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.data()), msg.size());
+  std::tie(isOk, element) = Block::fromBuffer({reinterpret_cast<const uint8_t*>(msg.data()), msg.size()});
   if (!isOk) {
     NFD_LOG_FACE_WARN("Failed to parse message payload");
     return;