Skip to content

Commit

Permalink
fix buffer_view data access with ValidBufferAccessType concept to ens…
Browse files Browse the repository at this point in the history
…ure valid access types are used
  • Loading branch information
farukeryilmaz committed Jan 9, 2024
1 parent 84ebaf1 commit c519b31
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/bytepack/bytepack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

/**
* @file bytepack.hpp
* @brief Simple C++ binary serialization library with endianness control, avoiding custom encoding.
* @brief BytePack is a simple, flexible and efficient header-only C++20 library designed for binary serialization and
* deserialization, especially suited for network communication. It offers endianness control and avoids
* library-specific encodings, ensuring adaptability to various data formats and external interfaces without imposing
* rigid standardizations. It supports both internally allocated buffers and user-supplied buffers.
*/

#ifndef BYTEPACK_HPP
Expand All @@ -35,6 +38,9 @@ template<typename T>
concept SerializableBuffer =
std::is_fundamental_v<T> && std::is_pointer_v<T> == false && std::is_reference_v<T> == false;

template<typename T>
concept ValidBufferAccessType = sizeof(T) == 1 || std::is_void_v<T>;

/**
* @class buffer_view
* @brief A non-owning mutable class that represents a buffer to provide an interface to access binary data
Expand Down Expand Up @@ -90,7 +96,7 @@ class buffer_view
* @return Pointer to the buffer's data cast to the specified type.
*/
template<typename T>
requires SerializableBuffer<T>
requires ValidBufferAccessType<T>
[[nodiscard]] constexpr T* as() const noexcept
{
return static_cast<T*>(data_);
Expand Down

0 comments on commit c519b31

Please sign in to comment.