From 6382fc9836956352f1570cbb54d9a911f127f2a6 Mon Sep 17 00:00:00 2001 From: Martin Anderseck Date: Tue, 21 Sep 2021 11:52:09 +0200 Subject: chdr: Rename var max_size_bytes to avoid confusion The variable max_size_bytes has a different name in the source than in the header and is not self-explanatory in both. Therefore when comparing against it in the assertion in line 142 one could assume that a number of bytes needs to be compared with a byte value. Change variable to `buff_size` in source and header file to avoid confusion and add documentation. --- host/include/uhd/rfnoc/chdr_types.hpp | 44 +++++++++++++++++++++++++---------- host/lib/rfnoc/chdr_types.cpp | 18 +++++++------- 2 files changed, 41 insertions(+), 21 deletions(-) (limited to 'host') diff --git a/host/include/uhd/rfnoc/chdr_types.hpp b/host/include/uhd/rfnoc/chdr_types.hpp index fac0331e0..ceeb8d12a 100644 --- a/host/include/uhd/rfnoc/chdr_types.hpp +++ b/host/include/uhd/rfnoc/chdr_types.hpp @@ -315,19 +315,24 @@ public: // Functions } //! Deserialize the payload from a uint64_t buffer + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer + //! \param conv_byte_order Byte order converter function (buffer to host endianness) void deserialize(const uint64_t* buff, - size_t num_elems, + size_t buff_size, const std::function& conv_byte_order); //! Deserialize the payload from a uint64_t buffer (no conversion function) + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer template - void deserialize(const uint64_t* buff, size_t num_elems) + void deserialize(const uint64_t* buff, size_t buff_size) { auto conv_byte_order = [](uint64_t x) -> uint64_t { return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx(x) : uhd::wtohx(x); }; - deserialize(buff, num_elems, conv_byte_order); + deserialize(buff, buff_size, conv_byte_order); } //! Get the serialized size of this payload in 64 bit words @@ -439,19 +444,24 @@ public: // Functions } //! Deserialize the payload from a uint64_t buffer + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer + //! \param conv_byte_order Byte order converter function (buffer to host endianness) void deserialize(const uint64_t* buff, - size_t num_elems, + size_t buff_size, const std::function& conv_byte_order); //! Deserialize the payload from a uint64_t buffer (no conversion function) + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer template - void deserialize(const uint64_t* buff, size_t num_elems) + void deserialize(const uint64_t* buff, size_t buff_size) { auto conv_byte_order = [](uint64_t x) -> uint64_t { return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx(x) : uhd::wtohx(x); }; - deserialize(buff, num_elems, conv_byte_order); + deserialize(buff, buff_size, conv_byte_order); } //! Get the serialized size of this payload in 64 bit words @@ -541,19 +551,24 @@ public: // Functions } //! Deserialize the payload from a uint64_t buffer + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer + //! \param conv_byte_order Byte order converter function (buffer to host endianness) void deserialize(const uint64_t* buff, - size_t num_elems, + size_t buff_size, const std::function& conv_byte_order); //! Deserialize the payload from a uint64_t buffer (no conversion function) + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer template - void deserialize(const uint64_t* buff, size_t num_elems) + void deserialize(const uint64_t* buff, size_t buff_size) { auto conv_byte_order = [](uint64_t x) -> uint64_t { return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx(x) : uhd::wtohx(x); }; - deserialize(buff, num_elems, conv_byte_order); + deserialize(buff, buff_size, conv_byte_order); } //! Get the serialized size of this payload in 64 bit words @@ -847,19 +862,24 @@ public: } //! Deserialize the payload from a uint64_t buffer + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer + //! \param conv_byte_order Byte order converter function (buffer to host endianness) void deserialize(const uint64_t* buff, - size_t num_elems, + size_t buff_size, const std::function& conv_byte_order); //! Deserialize the payload from a uint64_t buffer (no conversion function) + //! \param buff Buffer to deserialize the payload from + //! \param buff_size Number of elements in the buffer template - void deserialize(const uint64_t* buff, size_t num_elems) + void deserialize(const uint64_t* buff, size_t buff_size) { auto conv_byte_order = [](uint64_t x) -> uint64_t { return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx(x) : uhd::wtohx(x); }; - deserialize(buff, num_elems, conv_byte_order); + deserialize(buff, buff_size, conv_byte_order); } //! Get the serialized size of this payload in 64 bit words diff --git a/host/lib/rfnoc/chdr_types.cpp b/host/lib/rfnoc/chdr_types.cpp index 7975a0228..aea76dbc4 100644 --- a/host/lib/rfnoc/chdr_types.cpp +++ b/host/lib/rfnoc/chdr_types.cpp @@ -99,7 +99,7 @@ size_t ctrl_payload::serialize(uint64_t* buff, } void ctrl_payload::deserialize(const uint64_t* buff, - size_t max_size_bytes, + size_t buff_size, const std::function& conv_byte_order) { // We assume that buff has room to hold the entire packet @@ -140,7 +140,7 @@ void ctrl_payload::deserialize(const uint64_t* buff, } data_vtr[i] = get_field_u64(data_word, LO_DATA_OFFSET, 32); } - UHD_ASSERT_THROW(ptr <= max_size_bytes); + UHD_ASSERT_THROW(ptr <= buff_size); } size_t ctrl_payload::get_length() const @@ -226,10 +226,10 @@ size_t strs_payload::serialize(uint64_t* buff, } void strs_payload::deserialize(const uint64_t* buff, - size_t num_elems, + size_t buff_size, const std::function& conv_byte_order) { - UHD_ASSERT_THROW(num_elems >= 4); + UHD_ASSERT_THROW(buff_size >= 4); // Read first word uint64_t word0 = conv_byte_order(buff[0]); @@ -313,10 +313,10 @@ size_t strc_payload::serialize(uint64_t* buff, } void strc_payload::deserialize(const uint64_t* buff, - size_t num_elems, + size_t buff_size, const std::function& conv_byte_order) { - UHD_ASSERT_THROW(num_elems >= 2); + UHD_ASSERT_THROW(buff_size >= 2); // Read first word uint64_t word0 = conv_byte_order(buff[0]); @@ -515,14 +515,14 @@ size_t mgmt_payload::serialize(uint64_t* buff, } void mgmt_payload::deserialize(const uint64_t* buff, - size_t num_elems, + size_t buff_size, const std::function& conv_byte_order) { - UHD_ASSERT_THROW(num_elems > 1); + UHD_ASSERT_THROW(buff_size > 1); // We use a list and copy just for ease of implementation // These transactions are not performance critical - std::list src_list(buff, buff + (num_elems * (_padding_size + 1))); + std::list src_list(buff, buff + (buff_size * (_padding_size + 1))); _hops.clear(); -- cgit v1.2.3