#include <Bytes.h>
|
| using | Filler = std::function<size_t(uint8_t *buf, size_t size)> |
| | Function type for filling byte arrays.
|
| |
|
| | Bytes () |
| | Default constructor.
|
| |
| | Bytes (const uint8_t *data, size_t size) |
| | Constructor from raw byte array.
|
| |
| | Bytes (const char *str) |
| | Constructor from C-string.
|
| |
| template<typename T> |
| | Bytes (T value) |
| | Constructor from integral type.
|
| |
| | Bytes (const Bytes &value) |
| | Copy constructor.
|
| |
| | Bytes (const String &value) |
| | Constructor from Arduino String.
|
| |
| virtual | ~Bytes () |
| | Destructor.
|
| |
| Bytes & | operator= (const Bytes &rhs) |
| | Assignment operator.
|
| |
| Bytes & | operator= (const String &rhs) |
| | Assignment from Arduino String.
|
| |
| size_t | fill (Filler filler) |
| | Fills the buffer using a provided filler function.
|
| |
| Bytes & | prune (size_t newSize) |
| | Reduces the size of the buffer.
|
| |
| const uint8_t * | raw () const |
| | Gets a const pointer to the raw byte array.
|
| |
| Bytes & | terminate () |
| | Ensures the byte array is null-terminated.
|
| |
| const char * | c_str () const |
| | Gets the byte array as a C string.
|
| |
| String | toString () const |
| | Converts the byte array to an Arduino String.
|
| |
| String | toHexString () const |
| | Converts the byte array to a hexadecimal string.
|
| |
| size_t | size () const |
| | Gets the size of the byte array.
|
| |
| void | clean () |
| | Deallocates the internal buffer.
|
| |
| uint32_t | checksum () const |
| | Calculates a checksum of the byte array.
|
| |
◆ Filler
Function type for filling byte arrays.
A callable that takes a buffer and size, fills the buffer, and returns the number of bytes filled.
◆ Bytes() [1/6]
Default constructor.
Creates an empty Bytes object with no allocated memory.
◆ Bytes() [2/6]
| Bytes::Bytes |
( |
const uint8_t * | data, |
|
|
size_t | size ) |
|
inline |
Constructor from raw byte array.
If data is nullptr but size is non-zero, space will be allocated but not initialized.
- Parameters
-
| data | Pointer to byte array to copy, or nullptr to just allocate |
| size | Size of the byte array |
◆ Bytes() [3/6]
| Bytes::Bytes |
( |
const char * | str | ) |
|
|
inline |
Constructor from C-string.
Creates a Bytes object containing the string plus its null terminator.
- Parameters
-
| str | Null-terminated C string |
◆ Bytes() [4/6]
Constructor from integral type.
- Parameters
-
| value | Integral value to convert to bytes |
Creates a Bytes object with the binary representation of the integral value. Only works with integral types (int, char, long, etc.).
◆ Bytes() [5/6]
| Bytes::Bytes |
( |
const Bytes & | value | ) |
|
|
inline |
Copy constructor.
Creates a deep copy of another Bytes object.
- Parameters
-
| value | The Bytes object to copy |
◆ Bytes() [6/6]
| Bytes::Bytes |
( |
const String & | value | ) |
|
|
inline |
Constructor from Arduino String.
Creates a Bytes object from the contents of an Arduino String.
- Parameters
-
| value | Arduino String to convert to bytes |
◆ ~Bytes()
| virtual Bytes::~Bytes |
( |
| ) |
|
|
inlinevirtual |
Destructor.
Frees allocated memory.
◆ c_str()
| const char * Bytes::c_str |
( |
| ) |
const |
|
inline |
Gets the byte array as a C string.
Returns the buffer as a C string. The buffer should be null-terminated first.
- Return values
-
| char* | Pointer to the internal buffer |
◆ checksum()
| uint32_t Bytes::checksum |
( |
| ) |
const |
|
inline |
Calculates a checksum of the byte array.
Uses CRC32 algorithm to generate a checksum of the data.
- Return values
-
| uint32_t | Checksum of the byte array |
◆ clean()
Deallocates the internal buffer.
Frees all allocated memory and resets the object to empty state.
◆ fill()
| size_t Bytes::fill |
( |
Filler | filler | ) |
|
|
inline |
Fills the buffer using a provided filler function.
Uses the provided function to fill the buffer with data. The filler should return the number of bytes actually written.
- Parameters
-
| filler | Function to fill the buffer |
- Return values
-
| size_t | Number of bytes filled |
| 0 | If the filler function is null |
◆ fromHexString()
| static Bytes Bytes::fromHexString |
( |
const String & | hexStr | ) |
|
|
inlinestatic |
Creates a Bytes object from a hexadecimal string.
Converts a hexadecimal string to its binary representation. The hexadecimal string length must be even.
- Parameters
-
| hexStr | String containing hexadecimal characters (e.g. "1A2B3C") |
- Return values
-
| Bytes | Object with the binary data |
| Bytes | Empty object if the string length is invalid |
◆ operator=() [1/2]
Assignment operator.
Creates a deep copy of the data from another Bytes object.
- Parameters
-
| rhs | The Bytes object to copy from |
- Return values
-
| Bytes& | Reference to this object |
◆ operator=() [2/2]
| Bytes & Bytes::operator= |
( |
const String & | rhs | ) |
|
|
inline |
Assignment from Arduino String.
Copies the contents of an Arduino String and adds a null terminator.
- Parameters
-
| rhs | Arduino String to copy from |
- Return values
-
| Bytes& | Reference to this object |
◆ prune()
| Bytes & Bytes::prune |
( |
size_t | newSize | ) |
|
|
inline |
Reduces the size of the buffer.
Reduces the size of the buffer. If newSize is larger than the current size, no action is taken.
- Parameters
-
| newSize | The new size to shrink to |
- Return values
-
| Bytes& | Reference to this object |
◆ raw()
| const uint8_t * Bytes::raw |
( |
| ) |
const |
|
inline |
Gets a const pointer to the raw byte array.
Provides direct access to the internal buffer. Do not modify or free this pointer.
- Return values
-
| uint8_t | Pointer to this object |
◆ size()
| size_t Bytes::size |
( |
| ) |
const |
|
inline |
Gets the size of the byte array.
- Return values
-
| size_t | Size of the byte array in bytes |
◆ terminate()
| Bytes & Bytes::terminate |
( |
| ) |
|
|
inline |
Ensures the byte array is null-terminated.
Adds a null terminator if one isn't already present, useful for string operations.
- Return values
-
| Bytes& | Reference to this object |
◆ toHexString()
| String Bytes::toHexString |
( |
| ) |
const |
|
inline |
Converts the byte array to a hexadecimal string.
Each byte is converted to a two-character hexadecimal representation.
- Return values
-
| String | String containing hexadecimal representation of the bytes |
◆ toString()
| String Bytes::toString |
( |
| ) |
const |
|
inline |
Converts the byte array to an Arduino String.
Assumes the bytes represent a null-terminated string.
- Return values
-
| String | String representation of the bytes as a character string |
The documentation for this class was generated from the following file: