C/C++ API Reference
Loading...
Searching...
No Matches
pw::bytes Namespace Reference

Binary data manipulation utilities. More...

Functions

template<typename B = std::byte, typename... Args>
PW_CONSTEVAL auto Concat (Args... args)
 
template<typename B = std::byte, size_t kSize, typename Indices = std::make_index_sequence<kSize - 1>>
PW_CONSTEVAL auto String (const char(&str)[kSize])
 
template<typename B = std::byte>
PW_CONSTEVAL auto String (const char(&)[1])
 
template<typename B , auto... values>
PW_CONSTEVAL auto Array ()
 
template<auto... values>
PW_CONSTEVAL auto Array ()
 
template<typename B , size_t kSize, typename T >
constexpr auto Initialized (const T &value_or_function)
 
template<size_t kSize, typename T >
constexpr auto Initialized (const T &value_or_function)
 
template<typename B = std::byte, typename... Args>
constexpr auto MakeArray (const Args &... args)
 
template<std::size_t kBitWidth, typename T >
constexpr T SignExtend (T nbit_value)
 
template<typename OutType , std::size_t kMsb, std::size_t kLsb, typename InType >
constexpr OutType ExtractBits (InType value)
 
template<typename T >
constexpr T ConvertOrder (endian from, endian to, T value)
 
template<typename T >
constexpr T ConvertOrderTo (endian to_endianness, T value)
 
template<typename T >
constexpr T ConvertOrderFrom (endian from_endianness, T value)
 Converts a value from the specified byte order to the native byte order.
 
template<typename T , typename U >
constexpr void CopyInOrder (endian order, T value, U *dest)
 
template<typename T >
constexpr auto CopyInOrder (endian order, T value)
 Copies the provided value to a std::array with the specified endianness.
 
template<typename T >
ReadInOrder (endian order, const void *buffer)
 
template<typename T >
ReadInOrder (endian order, const void *buffer, size_t max_bytes_to_read)
 
template<typename T , typename B , size_t kBufferSize, typename = std::enable_if_t<kBufferSize != dynamic_extent && sizeof(B) == sizeof(std::byte)>>
ReadInOrder (endian order, span< B, kBufferSize > buffer)
 Reads a value from a static-extent span, with compile-time bounds checking.
 
template<typename T , typename B , size_t kBufferSize>
ReadInOrder (endian order, const std::array< B, kBufferSize > &buffer)
 Reads a value from a std::array, with compile-time bounds checking.
 
template<typename T , typename B , size_t kBufferSize>
ReadInOrder (endian order, const B(&buffer)[kBufferSize])
 Reads a value from a C array, with compile-time bounds checking.
 
template<typename T >
bool ReadInOrder (endian order, ConstByteSpan buffer, T &value)
 
constexpr unsigned long long int B (unsigned long long int bytes)
 
constexpr unsigned long long int KiB (unsigned long long int kibibytes)
 
constexpr unsigned long long int MiB (unsigned long long int mebibytes)
 
constexpr unsigned long long int GiB (unsigned long long int gibibytes)
 
constexpr unsigned long long int TiB (unsigned long long int tebibytes)
 
constexpr unsigned long long int PiB (unsigned long long int pebibytes)
 
constexpr unsigned long long int EiB (unsigned long long int exbibytes)
 

Variables

constexpr unsigned long long int kBytesInKibibyte = 1ull << 10
 
constexpr unsigned long long int kBytesInMebibyte = 1ull << 20
 
constexpr unsigned long long int kBytesInGibibyte = 1ull << 30
 
constexpr unsigned long long int kBytesInTebibyte = 1ull << 40
 
constexpr unsigned long long int kBytesInPebibyte = 1ull << 50
 
constexpr unsigned long long int kBytesInExbibyte = 1ull << 60
 

Detailed Description

Binary data manipulation utilities.

Function Documentation

◆ ExtractBits()

template<typename OutType , std::size_t kMsb, std::size_t kLsb, typename InType >
constexpr OutType pw::bytes::ExtractBits ( InType  value)
constexpr

Extracts bits between msb and lsb from a value.

Template Parameters
OutTypeThe type of output number to be extracted from input number.
kMsbThe left bit (included) that extraction starts at.
kLsbThe right bit (included) that extraction ends at.
InTypeThe type of input number.
Parameters
[in]valueThe input number.

Example (extrat bits between 10 and 5 from a uint32_t and return as a uint8_t):

constexpr uint32_t number = 0xA0A0A0A0;
constexpr uint8_t extracted_number = ExtractBits<uint8_t, 10, 5>(number);

◆ SignExtend()

template<std::size_t kBitWidth, typename T >
constexpr T pw::bytes::SignExtend ( nbit_value)
constexpr

Extends the nth bit to the left. Useful for expanding singed values into larger integer types.