diff --git a/include/bytepack/bytepack.hpp b/include/bytepack/bytepack.hpp index 3db779e..38042e4 100644 --- a/include/bytepack/bytepack.hpp +++ b/include/bytepack/bytepack.hpp @@ -49,7 +49,7 @@ class buffer_view template requires SerializableBuffer explicit constexpr buffer_view(T (&array)[N]) noexcept - : data_{ array }, size_{ N * sizeof(T) }, ssize_{ to_ssize(N * sizeof(T)) } + : data_{ static_cast(array) }, size_{ N * sizeof(T) }, ssize_{ to_ssize(N * sizeof(T)) } {} template @@ -59,19 +59,18 @@ class buffer_view {} explicit buffer_view(std::string& str) noexcept - : data_{ str.data() }, size_{ str.size() }, ssize_{ to_ssize(str.size()) } + : data_{ static_cast(str.data()) }, size_{ str.size() }, ssize_{ to_ssize(str.size()) } {} template requires SerializableBuffer explicit constexpr buffer_view(std::array& array) noexcept - : data_{ array.data() }, size_{ N * sizeof(T) }, ssize_{ to_ssize(N * sizeof(T)) } + : data_{ static_cast(array.data()) }, size_{ N * sizeof(T) }, ssize_{ to_ssize(N * sizeof(T)) } {} /** - * Enables handling of raw memory but lacks type safety. Users must - * ensure correct data interpretation and alignment. Ideal for advanced - * use cases involving low-level memory operations. + * Enables handling of raw memory but lacks type safety. Users must ensure correct data interpretation + * and alignment. Ideal for advanced use cases involving low-level memory operations. * * @param ptr Pointer to raw data. * @param size Size of the data in bytes. @@ -385,10 +384,10 @@ class binary_stream final return true; } - template + template bool write(const StringType& value) noexcept { - if constexpr (Mode == StringMode::NullTerm) { + if constexpr (Mode == bytepack::StringMode::NullTerm) { const std::size_t str_length = value.length() + 1; // +1 for null terminator if (buffer_.size() < (write_index_ + str_length)) { @@ -609,8 +608,7 @@ class binary_stream final // null can optimize performance. If it's not null, we can avoid the search entirely. Otherwise, a binary // search-like method is more efficient for such strings, as it exponentially narrows the search space, quickly // finding the initial null character, thus enhancing performance for longer lengths. - const std::size_t null_pos = value.find('\0'); - if (null_pos != std::string::npos) { + if (const std::size_t null_pos = value.find('\0'); null_pos != std::string::npos) { // If the string in the buffer is null-terminated, resize the string to the actual length value.resize(null_pos); } @@ -619,10 +617,10 @@ class binary_stream final return true; } - template + template bool read(std::string& value) noexcept { - if constexpr (Mode == StringMode::NullTerm) { + if constexpr (Mode == bytepack::StringMode::NullTerm) { std::size_t end_index = read_index_; // Find null terminator in the buffer starting from the current deserialize index while (end_index < buffer_.size() && buffer_.as()[end_index] != '\0') {