diff --git a/include/bytepack/bytepack.hpp b/include/bytepack/bytepack.hpp index c64079f..f5a4859 100644 --- a/include/bytepack/bytepack.hpp +++ b/include/bytepack/bytepack.hpp @@ -113,6 +113,16 @@ concept NetworkSerializableBasic = template concept NetworkSerializableBasicArray = std::is_array_v && NetworkSerializableBasic>; +template +concept NetworkSerializableArray = + requires { + typename T::value_type; + { + std::tuple_size::value + }; + } && std::is_same_v::value>> + && NetworkSerializableBasic; + template concept NetworkSerializableVector = std::is_same_v> && NetworkSerializableBasic; @@ -121,7 +131,8 @@ concept NetworkSerializableString = std::same_as || std::same_as template concept NetworkSerializableType = NetworkSerializableBasic || NetworkSerializableBasicArray - || NetworkSerializableString || NetworkSerializableVector; + || NetworkSerializableArray || NetworkSerializableString + || NetworkSerializableVector; template concept IntegralType = std::is_integral_v; @@ -215,7 +226,7 @@ class binary_stream final std::memcpy(buffer_.as() + write_index_, value, sizeof(T)); write_index_ += sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (std::size_t i = 0; i < numElements; ++i) { std::memcpy(buffer_.as() + write_index_, &value[i], elementSize); std::ranges::reverse(buffer_.as() + write_index_, @@ -242,7 +253,7 @@ class binary_stream final std::memcpy(buffer_.as() + write_index_, array.data(), N * sizeof(T)); write_index_ += N * sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (std::size_t i = 0; i < N; ++i) { std::memcpy(buffer_.as() + write_index_, &array[i], sizeof(T)); std::ranges::reverse(buffer_.as() + write_index_, @@ -280,7 +291,7 @@ class binary_stream final std::memcpy(buffer_.as() + write_index_, vector.data(), vector.size() * sizeof(T)); write_index_ += vector.size() * sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (std::size_t i = 0; i < vector.size(); ++i) { std::memcpy(buffer_.as() + write_index_, &vector[i], sizeof(T)); std::ranges::reverse(buffer_.as() + write_index_, @@ -305,7 +316,7 @@ class binary_stream final std::memcpy(buffer_.as() + write_index_, vector.data(), N * sizeof(T)); write_index_ += N * sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (std::size_t i = 0; i < N; ++i) { std::memcpy(buffer_.as() + write_index_, &vector[i], sizeof(T)); std::ranges::reverse(buffer_.as() + write_index_, @@ -436,7 +447,7 @@ class binary_stream final std::memcpy(value, buffer_.as() + read_index_, sizeof(T)); read_index_ += sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (size_t i = 0; i < numElements; ++i) { std::memcpy(&value[i], buffer_.as() + read_index_, elementSize); std::ranges::reverse(reinterpret_cast(&value[i]), @@ -463,7 +474,7 @@ class binary_stream final std::memcpy(array.data(), buffer_.as() + read_index_, N * sizeof(T)); read_index_ += N * sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (size_t i = 0; i < N; ++i) { std::memcpy(&array[i], buffer_.as() + read_index_, sizeof(T)); std::ranges::reverse(reinterpret_cast(&array[i]), @@ -480,7 +491,7 @@ class binary_stream final bool read(std::vector& vector) noexcept { SizeType size_custom{}; - // vector size cannot be negative, and zero-size is also unusual so it's treated as an error. + // vector size cannot be negative, and zero-size is also unusual, so it's treated as an error. if (read(size_custom) == false || size_custom < 1) { return false; } @@ -498,7 +509,7 @@ class binary_stream final std::memcpy(vector.data(), buffer_.as() + read_index_, size * sizeof(T)); read_index_ += size * sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (std::size_t i = 0; i < size; ++i) { std::memcpy(&vector[i], buffer_.as() + read_index_, sizeof(T)); std::ranges::reverse(reinterpret_cast(&vector[i]), @@ -525,7 +536,7 @@ class binary_stream final std::memcpy(vector.data(), buffer_.as() + read_index_, N * sizeof(T)); read_index_ += N * sizeof(T); } else { - // For multi-byte types with differing endianness, handle each element individually + // For multibyte types with differing endianness, handle each element individually for (std::size_t i = 0; i < N; ++i) { std::memcpy(&vector[i], buffer_.as() + read_index_, sizeof(T)); std::ranges::reverse(reinterpret_cast(&vector[i]), @@ -553,7 +564,7 @@ class binary_stream final reinterpret_cast(&str_length) + sizeof(SizeType)); } - // String length cannot be negative, and zero-length is also unusual so it's treated as an error. + // String length cannot be negative, and zero-length is also unusual, so it's treated as an error. if (str_length < 1) { return false; }