34 using DataType = std::array<uint8_t, NumBytes>;
71 if(d[
i] != 0)
return false;
91 static const char digits[] =
"0123456789abcdef";
95 ret += digits[d[
i] >> 4];
96 ret += digits[d[
i] & 0x0F];
114 int hi = hexCharToVal(str[
i * 2]);
115 int lo = hexCharToVal(str[
i * 2 + 1]);
116 if(
hi < 0 ||
lo < 0) {
139 static int hexCharToVal(
char c) {
140 if(
c >=
'0' &&
c <=
'9')
return c -
'0';
141 if(
c >=
'a' &&
c <=
'f')
return c -
'a' + 10;
142 if(
c >=
'A' &&
c <=
'F')
return c -
'A' + 10;
Fixed-size byte array with hex string conversion.
Definition bytearray.h:30
ByteArray(const uint8_t *src)
Constructs from a raw byte pointer. Copies NumBytes from src.
Definition bytearray.h:46
ByteArray()
Default constructor. Value-initializes all bytes to zero.
Definition bytearray.h:37
constexpr size_t size() const
Returns the number of bytes.
Definition bytearray.h:54
uint8_t * data()
Returns a mutable pointer to the underlying data.
Definition bytearray.h:63
const uint8_t * data() const
Returns a const pointer to the underlying data.
Definition bytearray.h:66
String toHexString() const
Converts the byte array to a lowercase hexadecimal string.
Definition bytearray.h:90
friend bool operator!=(const ByteArray &lhs, const ByteArray &rhs)
Returns true if the arrays differ.
Definition bytearray.h:82
const uint8_t & operator[](size_t index) const
Returns a const reference to the byte at index.
Definition bytearray.h:60
bool isZero() const
Returns true if all bytes are zero.
Definition bytearray.h:69
~ByteArray()
Destructor.
Definition bytearray.h:51
uint8_t & operator[](size_t index)
Returns a mutable reference to the byte at index.
Definition bytearray.h:57
static ByteArray fromHexString(const char *str, Error *err=nullptr)
Constructs a ByteArray from a hexadecimal C string.
Definition bytearray.h:107
ByteArray(const DataType &val)
Constructs from a std::array.
Definition bytearray.h:40
static ByteArray fromHexString(const String &str, Error *err=nullptr)
Constructs a ByteArray from a hexadecimal String.
Definition bytearray.h:132
friend bool operator==(const ByteArray &lhs, const ByteArray &rhs)
Returns true if both arrays contain identical bytes.
Definition bytearray.h:77
ByteArray(const DataType &&val)
Move-constructs from a std::array.
Definition bytearray.h:43
Lightweight error code wrapper for the promeki library.
Definition error.h:39
@ Ok
No error.
Definition error.h:51
@ Invalid
Invalid value or argument (EINVAL).
Definition error.h:66
Dynamic array container wrapping std::vector.
Definition list.h:40
void reserve(size_t newCapacity)
Pre-allocates storage for at least newCapacity elements.
Definition list.h:314
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
const char * cstr() const
Returns a null-terminated C string pointer.
Definition string.h:289
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
#define PROMEKI_SHARED_FINAL(TYPE)
Macro for non-polymorphic native shared objects.
Definition sharedptr.h:88