mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
mal_toolkit::ByteArray Struct Reference

A dynamically resizable array of bytes. More...

#include "byte-helper.hpp"

Inheritance diagram for mal_toolkit::ByteArray:
[legend]
Collaboration diagram for mal_toolkit::ByteArray:
[legend]

Public Member Functions

template<typename T >
constexpr T * as ()
 Convert the ByteArray to a typed pointer.
 
template<typename T >
constexpr const T * as () const
 Convert the ByteArray to a const typed pointer.
 
constexpr ByteView as_view () const
 Convert the ByteArray to a ByteView.
 
template<typename First , typename Second , typename... Args>
void append (First &&first, Second &&second, Args &&...args)
 Append multiple data sources to the byte array.
 
template<typename First , typename Second >
void append (First &&first, Second &&second)
 Append two data sources to the byte array.
 
template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void append (const std::vector< T > &other)
 Append a vector of data to the byte array.
 
template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void append (const std::span< T > &other)
 Append a span of data to the byte array.
 
template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void append (const std::basic_string< T > &other)
 Append a string of data to the byte array.
 
template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void append (const std::basic_string_view< T > &other)
 Append a string view of data to the byte array.
 
constexpr ByteView view (size_t from=0) const
 Create a ByteView of a subsequence of the byte array.
 
constexpr ByteView view (size_t from, size_t length) const
 Create a ByteView of a subsequence of the byte array.
 

Static Public Member Functions

template<typename... Args>
static ByteArray from_byte_arrays (Args &&...args)
 Create a byte array from multiple data sources.
 
template<std::integral Integer>
static ByteArray from_integral (const Integer integer)
 Create a byte array from an integral value.
 

Public Attributes

elements
 STL member.
 

Detailed Description

A dynamically resizable array of bytes.

ByteArray is a wrapper around std::vector<std::byte> with additional functionality for convenient manipulation of byte data.

Note
Provides boost serialization if boost is enabled.

Definition at line 88 of file byte-helper.hpp.

Member Function Documentation

◆ append() [1/6]

template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void mal_toolkit::ByteArray::append ( const std::basic_string< T > & other)
inline

Append a string of data to the byte array.

This function appends the characters of the provided string to the end of the byte array.

Note
requires sizeof(T) to be equal to sizeof(std::byte)
Template Parameters
TThe character type of the string.
Parameters
otherThe string to append.

Definition at line 231 of file byte-helper.hpp.

◆ append() [2/6]

template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void mal_toolkit::ByteArray::append ( const std::basic_string_view< T > & other)
inline

Append a string view of data to the byte array.

This function appends the characters of the provided string view to the end of the byte array.

Template Parameters
TThe character type of the string view.
Parameters
otherThe string view to append.

Definition at line 255 of file byte-helper.hpp.

◆ append() [3/6]

template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void mal_toolkit::ByteArray::append ( const std::span< T > & other)
inline

Append a span of data to the byte array.

This function appends the elements of the provided span to the end of the byte array.

Note
requires sizeof(T) to be equal to sizeof(std::byte)
Template Parameters
TThe type of elements in the span.
Parameters
otherThe span to append.

Definition at line 206 of file byte-helper.hpp.

◆ append() [4/6]

template<typename T >
requires (sizeof(T) == sizeof(std::byte))
void mal_toolkit::ByteArray::append ( const std::vector< T > & other)
inline

Append a vector of data to the byte array.

This function appends the elements of the provided vector to the end of the byte array.

Note
requires sizeof(T) to be equal to sizeof(std::byte)
Template Parameters
TThe type of elements in the vector.
Parameters
otherThe vector to append.

Definition at line 181 of file byte-helper.hpp.

◆ append() [5/6]

template<typename First , typename Second >
void mal_toolkit::ByteArray::append ( First && first,
Second && second )
inline

Append two data sources to the byte array.

This function appends the provided data sources to the end of the byte array.

Template Parameters
FirstThe type of the first data source.
SecondThe type of the second data source.
Parameters
firstThe first data source.
secondThe second data source.

Definition at line 164 of file byte-helper.hpp.

Here is the call graph for this function:

◆ append() [6/6]

template<typename First , typename Second , typename... Args>
void mal_toolkit::ByteArray::append ( First && first,
Second && second,
Args &&... args )
inline

Append multiple data sources to the byte array.

This function appends the provided data sources to the end of the byte array.

Template Parameters
FirstThe type of the first data source.
SecondThe type of the second data source.
ArgsThe types of additional data sources.
Parameters
firstThe first data source.
secondThe second data source.
argsAdditional data sources.

Definition at line 146 of file byte-helper.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ as() [1/2]

template<typename T >
T * mal_toolkit::ByteArray::as ( )
inlinenodiscardconstexpr

Convert the ByteArray to a typed pointer.

This function interprets the underlying byte data as a sequence of the specified type and returns a pointer to the first element.

Template Parameters
TThe type to interpret the byte data as.
Returns
A pointer to the first element of the interpreted type.

Definition at line 104 of file byte-helper.hpp.

Here is the caller graph for this function:

◆ as() [2/2]

template<typename T >
const T * mal_toolkit::ByteArray::as ( ) const
inlinenodiscardconstexpr

Convert the ByteArray to a const typed pointer.

This function interprets the underlying byte data as a sequence of the specified type and returns a const pointer to the first element.

Template Parameters
TThe type to interpret the byte data as.
Returns
A const pointer to the first element of the interpreted type.

Definition at line 119 of file byte-helper.hpp.

◆ as_view()

ByteView mal_toolkit::ByteArray::as_view ( ) const
inlinenodiscardconstexpr

Convert the ByteArray to a ByteView.

This function creates a ByteView that represents the entire ByteArray.

Returns
A ByteView representing the ByteArray.

Definition at line 131 of file byte-helper.hpp.

◆ from_byte_arrays()

template<typename... Args>
static ByteArray mal_toolkit::ByteArray::from_byte_arrays ( Args &&... args)
inlinestatic

Create a byte array from multiple data sources.

This static function creates a new byte array by appending the provided data sources.

Template Parameters
ArgsThe types of data sources.
Parameters
argsData sources to append to the new byte array.
Returns
A new byte array containing the appended data.

Definition at line 279 of file byte-helper.hpp.

Here is the call graph for this function:

◆ from_integral()

template<std::integral Integer>
static ByteArray mal_toolkit::ByteArray::from_integral ( const Integer integer)
inlinestatic

Create a byte array from an integral value.

This static function creates a new byte array containing the binary representation of the provided integral value.

Note
Input integer should take into account endianness. Check out mal_toolkit::bytes_to_uint32 and mal_toolkit::uint32_to_bytes functions.
Other conversions are forbidden, because of alignment/endianness and compiler features on other systems/compilers.
Template Parameters
IntegerThe type of the integral value.
Parameters
integerThe integral value to convert to a byte array.
Returns
A new byte array containing the binary representation of the integral value.

Definition at line 303 of file byte-helper.hpp.

Here is the call graph for this function:

◆ view() [1/2]

ByteView mal_toolkit::ByteArray::view ( size_t from,
size_t length ) const
inlinenodiscardconstexpr

Create a ByteView of a subsequence of the byte array.

This function creates a ByteView that represents a subsequence of the byte array, starting from the specified index.

Parameters
fromThe starting index of the subview.
lengthThe length of the subview.
Returns
A ByteView representing the subview.

Definition at line 335 of file byte-helper.hpp.

◆ view() [2/2]

ByteView mal_toolkit::ByteArray::view ( size_t from = 0) const
inlinenodiscardconstexpr

Create a ByteView of a subsequence of the byte array.

This function creates a ByteView that represents a subsequence of the byte array, starting from the specified index.

Parameters
fromThe starting index of the subview.
Returns
A ByteView representing the subview.

Definition at line 320 of file byte-helper.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ elements

T std::vector< T >::elements
inherited

STL member.


The documentation for this struct was generated from the following file: