SW Task Event Loop Framework v1.0.0
High-performance C++ asynchronous event loop framework with timer management and promise-based programming
|
Dynamic byte buffer for data storage and manipulation. More...
#include <Buffer.h>
Public Member Functions | |
Buffer () | |
Default constructor - creates empty buffer. | |
Buffer (const Buffer &other) | |
Copy constructor - creates buffer from another buffer. | |
~Buffer () | |
Destructor - cleans up buffer resources. | |
Buffer & | operator= (const Buffer &other) |
Assignment operator - assigns data from another buffer. | |
void | setSize (int32_t len) |
Set buffer size and initialize with zeros. | |
void | setTo (const Buffer &buffer) |
Copy data from another buffer. | |
void | setTo (uint8_t *buf, int32_t len) |
Copy data from byte array. | |
void | setTo (char *buf, int32_t len) |
Copy data from char array. | |
void | append (uint8_t *buf, int32_t len) |
Append data to existing buffer contents. | |
uint8_t * | data () |
Get pointer to buffer data. | |
uint32_t | size () const |
Get current buffer size. | |
bool | empty () |
Check if buffer contains no data. | |
void | clear () |
Clear all buffer contents and mark as cleared. | |
void | dump () |
Dump current buffer contents to stdout. | |
Static Public Member Functions | |
static void | dump (uint8_t *s, int32_t len) |
Static method to dump byte array contents to stdout. | |
Dynamic byte buffer for data storage and manipulation.
Provides a dynamic byte array with various utility methods for data manipulation, copying, and debugging output. Built on top of std::vector<uint8_t> for efficient memory management.
Key features:
swt::Buffer::Buffer | ( | ) |
Default constructor - creates empty buffer.
Initializes buffer with empty state and clear flag set to false. The underlying vector is empty and ready for data operations.
Initializes buffer with empty state and clear flag set to false. The underlying vector is empty and ready for data operations.
Definition at line 21 of file Buffer.cpp.
swt::Buffer::Buffer | ( | const Buffer & | other | ) |
Copy constructor - creates buffer from another buffer.
other | Source buffer to copy from |
Creates a new buffer by performing deep copy of all data from the source buffer. Both buffers are independent after construction.
other | Source buffer to copy from |
Creates a new buffer by copying all data from the source buffer. Uses setTo() method for proper deep copy of vector data.
Definition at line 32 of file Buffer.cpp.
References setTo().
swt::Buffer::~Buffer | ( | ) |
Destructor - cleans up buffer resources.
Automatically releases all allocated memory. The underlying std::vector destructor handles the actual memory deallocation.
Calls clear() to release all allocated memory and reset state. The vector destructor will handle the actual memory deallocation.
Definition at line 42 of file Buffer.cpp.
References clear().
void swt::Buffer::append | ( | uint8_t * | buf, |
int32_t | len | ||
) |
Append data to existing buffer contents.
buf | Source byte array to append |
len | Length of data to append in bytes |
Adds new data to the end of existing buffer contents. Buffer size increases by the length of appended data.
buf | Source byte array to append |
len | Length of data to append in bytes |
Adds new data to the end of existing buffer contents. Buffer size increases by the length of appended data.
Definition at line 131 of file Buffer.cpp.
void swt::Buffer::clear | ( | ) |
Clear all buffer contents and mark as cleared.
Removes all data from buffer and sets the clear flag. This frees all allocated memory and resets to empty state.
Removes all data from buffer and sets the clear flag. This frees all allocated memory and resets to empty state.
Definition at line 185 of file Buffer.cpp.
Referenced by ~Buffer().
uint8_t * swt::Buffer::data | ( | ) |
Get pointer to buffer data.
Provides direct access to internal buffer data for reading or writing. The pointer becomes invalid after buffer resize or destruction.
Provides direct access to internal buffer data for reading or writing. The pointer becomes invalid after buffer resize or destruction.
Definition at line 149 of file Buffer.cpp.
void swt::Buffer::dump | ( | ) |
Dump current buffer contents to stdout.
Prints buffer contents in hexadecimal format for debugging. Shows each byte as a two-digit hex value separated by spaces. Does nothing if buffer is empty.
Prints buffer contents in hexadecimal format for debugging. Shows each byte as a two-digit hex value separated by spaces. Does nothing if buffer is empty.
Definition at line 199 of file Buffer.cpp.
References dump().
Referenced by dump().
|
static |
Static method to dump byte array contents to stdout.
s | Pointer to byte array to dump |
len | Number of bytes to dump |
Utility method for dumping arbitrary byte arrays in hex format. Useful for debugging data that's not in a Buffer object.
Format: "Buffer dump (N bytes): XX XX XX ..." where XX represents each byte in uppercase hexadecimal.
s | Pointer to byte array to dump |
len | Number of bytes to dump |
Utility method for dumping arbitrary byte arrays in hex format. Useful for debugging data that's not in a Buffer object.
Format: "Buffer dump (N bytes): XX XX XX ..." where XX represents each byte in uppercase hexadecimal.
Definition at line 218 of file Buffer.cpp.
bool swt::Buffer::empty | ( | ) |
Check if buffer contains no data.
Efficient way to check if buffer contains any data without getting the actual size value. Preferred over size() == 0.
Efficient way to check if buffer contains any data without getting the actual size value.
Definition at line 171 of file Buffer.cpp.
Assignment operator - assigns data from another buffer.
other | Source buffer to assign from |
Performs deep copy assignment with self-assignment protection. Replaces current buffer contents with source buffer data.
other | Source buffer to assign from |
Performs deep copy assignment with self-assignment protection. Uses setTo() method for consistent copying behavior.
Definition at line 54 of file Buffer.cpp.
References setTo().
void swt::Buffer::setSize | ( | int32_t | len | ) |
Set buffer size and initialize with zeros.
len | New buffer size in bytes |
Resizes the buffer to the specified length and fills all bytes with zeros. This provides a clean initialized buffer for data operations.
len | New buffer size in bytes |
Resizes the buffer to the specified length and fills all bytes with zeros. This provides a clean initialized buffer for data operations.
Definition at line 73 of file Buffer.cpp.
void swt::Buffer::setTo | ( | char * | buf, |
int32_t | len | ||
) |
Copy data from char array.
buf | Source char array pointer |
len | Length of data to copy in bytes |
Convenience method that casts char pointer to uint8_t and delegates to the byte array version of setTo().
buf | Source char array pointer |
len | Length of data to copy in bytes |
Convenience method that casts char pointer to uint8_t and delegates to the byte array version of setTo().
Definition at line 117 of file Buffer.cpp.
References setTo().
void swt::Buffer::setTo | ( | const Buffer & | buffer | ) |
Copy data from another buffer.
buffer | Source buffer to copy from |
Performs deep copy of all data from source buffer. This replaces current buffer contents entirely.
buffer | Source buffer to copy from |
Performs deep copy of all data from source buffer. This replaces current buffer contents entirely.
Definition at line 87 of file Buffer.cpp.
Referenced by Buffer(), operator=(), and setTo().
void swt::Buffer::setTo | ( | uint8_t * | buf, |
int32_t | len | ||
) |
Copy data from byte array.
buf | Source byte array pointer |
len | Length of data to copy in bytes |
Copies specified number of bytes from source array to buffer. Replaces current buffer contents with new data.
buf | Source byte array pointer |
len | Length of data to copy in bytes |
Copies specified number of bytes from source array to buffer. Replaces current buffer contents with new data.
Definition at line 101 of file Buffer.cpp.
uint32_t swt::Buffer::size | ( | ) | const |
Get current buffer size.
Returns the actual number of bytes of data in the buffer. This represents the valid data size, not the allocated capacity.
Returns the actual number of bytes of data in the buffer. This may be different from the vector's capacity.
Definition at line 160 of file Buffer.cpp.