libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
ByteArray< NumBytes > Class Template Reference

Fixed-size byte array with hex string conversion. More...

#include <bytearray.h>

Public Types

using Ptr = SharedPtr< ByteArray >
 
using DataType = std::array< uint8_t, NumBytes >
 

Public Member Functions

 ByteArray ()
 Default constructor. Value-initializes all bytes to zero.
 
 ByteArray (const DataType &val)
 Constructs from a std::array.
 
 ByteArray (const DataType &&val)
 Move-constructs from a std::array.
 
 ByteArray (const uint8_t *src)
 Constructs from a raw byte pointer. Copies NumBytes from src.
 
 ~ByteArray ()
 Destructor.
 
constexpr size_t size () const
 Returns the number of bytes.
 
uint8_toperator[] (size_t index)
 Returns a mutable reference to the byte at index.
 
const uint8_toperator[] (size_t index) const
 Returns a const reference to the byte at index.
 
uint8_tdata ()
 Returns a mutable pointer to the underlying data.
 
const uint8_tdata () const
 Returns a const pointer to the underlying data.
 
bool isZero () const
 Returns true if all bytes are zero.
 
String toHexString () const
 Converts the byte array to a lowercase hexadecimal string.
 

Static Public Member Functions

static ByteArray fromHexString (const char *str, Error *err=nullptr)
 Constructs a ByteArray from a hexadecimal C string.
 
static ByteArray fromHexString (const String &str, Error *err=nullptr)
 Constructs a ByteArray from a hexadecimal String.
 

Friends

bool operator== (const ByteArray &lhs, const ByteArray &rhs)
 Returns true if both arrays contain identical bytes.
 
bool operator!= (const ByteArray &lhs, const ByteArray &rhs)
 Returns true if the arrays differ.
 

Detailed Description

template<size_t NumBytes>
class ByteArray< NumBytes >

Fixed-size byte array with hex string conversion.

A specialization of fixed-size array for uint8_t data, providing conversion to and from hexadecimal strings.

Template Parameters
NumBytesNumber of bytes (fixed at compile time).

Member Function Documentation

◆ fromHexString() [1/2]

template<size_t NumBytes>
static ByteArray ByteArray< NumBytes >::fromHexString ( const char str,
Error err = nullptr 
)
inlinestatic

Constructs a ByteArray from a hexadecimal C string.

Parameters
strThe hex string (must be exactly NumBytes * 2 characters).
errOptional error output.
Returns
The parsed ByteArray, or a zero ByteArray on failure.

◆ fromHexString() [2/2]

template<size_t NumBytes>
static ByteArray ByteArray< NumBytes >::fromHexString ( const String str,
Error err = nullptr 
)
inlinestatic

Constructs a ByteArray from a hexadecimal String.

Parameters
strThe hex string (must be exactly NumBytes * 2 characters).
errOptional error output.
Returns
The parsed ByteArray, or a zero ByteArray on failure.

◆ toHexString()

template<size_t NumBytes>
String ByteArray< NumBytes >::toHexString ( ) const
inline

Converts the byte array to a lowercase hexadecimal string.

Returns
A String of length NumBytes * 2.

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