From 4a453166f14a2920f213cdf3b3da5a38caf07338 Mon Sep 17 00:00:00 2001 From: greyes Date: Wed, 1 Nov 2023 19:28:22 +0100 Subject: [PATCH] Removed bytearray utils --- lib/Service/Util.cpp | 93 --------------------------------- lib/Service/Util.h | 121 +++++++++++-------------------------------- 2 files changed, 29 insertions(+), 185 deletions(-) diff --git a/lib/Service/Util.cpp b/lib/Service/Util.cpp index 4ff4d4f1..a0a7434d 100644 --- a/lib/Service/Util.cpp +++ b/lib/Service/Util.cpp @@ -150,99 +150,6 @@ void Util::intToStr(char* str, size_t size, int32_t value) } } -void Util::int16ToByteArray(uint8_t* buffer, size_t size, int16_t value) -{ - if ((nullptr != buffer) && (sizeof(int16_t) <= size)) - { - buffer[0U] = ((value >> 8U) & 0xFF); - buffer[1U] = ((value >> 0U) & 0xFF); - } -} - -void Util::uint16ToByteArray(uint8_t* buffer, size_t size, uint16_t value) -{ - if ((nullptr != buffer) && (sizeof(uint16_t) <= size)) - { - buffer[0U] = ((value >> 8U) & 0xFF); - buffer[1U] = ((value >> 0U) & 0xFF); - } -} - -void Util::int32ToByteArray(uint8_t* buffer, size_t size, int32_t value) -{ - if ((nullptr != buffer) && (sizeof(int32_t) <= size)) - { - uint16_t hiBytes = ((value >> 16U) & 0xFFFF); - uint16_t lowBytes = ((value >> 0U) & 0xFFFF); - - buffer[0U] = ((hiBytes >> 8U) & 0xFF); - buffer[1U] = ((hiBytes >> 0U) & 0xFF); - buffer[2U] = ((lowBytes >> 8U) & 0xFF); - buffer[3U] = ((lowBytes >> 0U) & 0xFF); - } -} - -void Util::uint32ToByteArray(uint8_t* buffer, size_t size, uint32_t value) -{ - if ((nullptr != buffer) && (sizeof(uint32_t) <= size)) - { - uint16_t hiBytes = ((value >> 16U) & 0xFFFF); - uint16_t lowBytes = ((value >> 0U) & 0xFFFF); - - buffer[0U] = ((hiBytes >> 8U) & 0xFF); - buffer[1U] = ((hiBytes >> 0U) & 0xFF); - buffer[2U] = ((lowBytes >> 8U) & 0xFF); - buffer[3U] = ((lowBytes >> 0U) & 0xFF); - } -} - -bool Util::byteArrayToInt16(const uint8_t* buffer, size_t size, int16_t& value) -{ - bool isSuccess = false; - - if ((nullptr != buffer) && (sizeof(int16_t) <= size)) - { - value = ((static_cast(buffer[0U]) << 8U) & 0xFF00) | - ((static_cast(buffer[1U]) << 0U) & 0x00FF) ; - - isSuccess = true; - } - - return isSuccess; -} - -bool Util::byteArrayToUint16(const uint8_t* buffer, size_t size, uint16_t& value) -{ - bool isSuccess = false; - - if ((nullptr != buffer) && (sizeof(uint16_t) <= size)) - { - value = ((static_cast(buffer[0U]) << 8U) & 0xFF00) | - ((static_cast(buffer[1U]) << 0U) & 0x00FF) ; - - isSuccess = true; - } - - return isSuccess; -} - -bool Util::byteArrayToUint32(const uint8_t* buffer, size_t size, uint32_t& value) -{ - bool isSuccess = false; - - if ((nullptr != buffer) && (sizeof(uint32_t) <= size)) - { - value = ((static_cast(buffer[0U]) << 24U) & 0xFF000000) | - ((static_cast(buffer[1U]) << 16U) & 0x00FF0000) | - ((static_cast(buffer[2U]) << 8U) & 0x0000FF00) | - ((static_cast(buffer[3U]) << 0U) & 0x000000FF) ; - - isSuccess = true; - } - - return isSuccess; -} - /****************************************************************************** * Local Functions *****************************************************************************/ diff --git a/lib/Service/Util.h b/lib/Service/Util.h index 8e39b72b..da44f7ab 100644 --- a/lib/Service/Util.h +++ b/lib/Service/Util.h @@ -52,98 +52,35 @@ namespace Util { -/****************************************************************************** - * Macros - *****************************************************************************/ - -/****************************************************************************** - * Types and Classes - *****************************************************************************/ - -/****************************************************************************** - * Functions - *****************************************************************************/ - -/** - * Unsigned integer to string, without preceeding zeros. - * - * @param[out] str Destination string - * @param[in] size Size of the destination string in byte - * @param[in] value Value - */ -void uintToStr(char* str, size_t size, uint32_t value); - -/** - * Signed integer to string, without preceeding zeros. - * - * @param[out] str Destination string - * @param[in] size Size of the destination string in byte - * @param[in] value Value - */ -void intToStr(char* str, size_t size, int32_t value); - -/** - * Signed 16-bit integer to byte array. - * Endianness: Big endian - * @param[out] buffer Destination array - * @param[in] size Size of the destination buffer in byte - * @param[in] value Value - */ -void int16ToByteArray(uint8_t* buffer, size_t size, int16_t value); - -/** - * Unsigned 16-bit integer to byte array. - * Endianness: Big endian - * @param[out] buffer Destination array - * @param[in] size Size of the destination buffer in byte - * @param[in] value Value - */ -void uint16ToByteArray(uint8_t* buffer, size_t size, uint16_t value); - -/** - * Signed 32-bit integer to byte array. - * Endianness: Big endian - * @param[out] buffer Destination array - * @param[in] size Size of the destination buffer in byte - * @param[in] value Value - */ -void int32ToByteArray(uint8_t* buffer, size_t size, int32_t value); - -/** - * Unsigned 32-bit integer to byte array. - * Endianness: Big endian. - * @param[out] buffer Destination array. - * @param[in] size Size of the destination buffer in byte. - * @param[in] value Value. - */ -void uint32ToByteArray(uint8_t* buffer, size_t size, uint32_t value); - -/** - * Big endian byte array to int16_t. - * @param[in] buffer Source Array. - * @param[in] size Size of source array. - * @param[out] value Destination integer. - * @returns true if succesfully parsed. Otherwise, false. - */ -bool byteArrayToInt16(const uint8_t* buffer, size_t size, int16_t& value); - -/** - * Big endian byte array to uint16_t. - * @param[in] buffer Source Array. - * @param[in] size Size of source array. - * @param[out] value Destination integer. - * @returns true if succesfully parsed. Otherwise, false. - */ -bool byteArrayToUint16(const uint8_t* buffer, size_t size, uint16_t& value); - -/** - * Big endian byte array to uint32_t. - * @param[in] buffer Source Array. - * @param[in] size Size of source array. - * @param[out] value Destination integer. - * @returns true if succesfully parsed. Otherwise, false. - */ -bool byteArrayToUint32(const uint8_t* buffer, size_t size, uint32_t& value); + /****************************************************************************** + * Macros + *****************************************************************************/ + + /****************************************************************************** + * Types and Classes + *****************************************************************************/ + + /****************************************************************************** + * Functions + *****************************************************************************/ + + /** + * Unsigned integer to string, without preceeding zeros. + * + * @param[out] str Destination string + * @param[in] size Size of the destination string in byte + * @param[in] value Value + */ + void uintToStr(char* str, size_t size, uint32_t value); + + /** + * Signed integer to string, without preceeding zeros. + * + * @param[out] str Destination string + * @param[in] size Size of the destination string in byte + * @param[in] value Value + */ + void intToStr(char* str, size_t size, int32_t value); } // namespace Util