Core Helper Utilities
Relevant source files
The following files were used as context for generating this wiki page:
Core Helper Utilities comprise a collection of fundamental tools used across the HXLibs framework to manage strings, files, time, and network-specific data structures. These utilities provide efficient implementations for common tasks such as HTTP-compliant date formatting, case-insensitive string hashing, and asynchronous file operations.
These helpers support higher-level modules like the HTTP Server and WebSocket Protocol by providing shared logic for protocol parsing and data manipulation.
Sources: StringUtils.hpp, FileUtils.hpp, Http.hpp, Request.hpp
String and Data Transformation
The StringUtil and DateTimeFormat classes provide optimized routines for string manipulation and time formatting.
String Manipulation
StringUtil includes methods for splitting, case conversion, and random string generation. The toLower and toUpper functions use 64-bit optimizations to process 8 characters at a time.
The diagram shows the logical flow of string operations within the StringUtil utility.
Sources: StringUtils.hpp:44-175
Time and HTTP Date Formatting
DateTimeFormat handles standard timestamp formatting and generates RFC-compliant dates specifically for HTTP headers.
| Function | Output Format | Purpose |
|---|---|---|
format() | %Y-%m-%d %H:%M:%S | Standard log-style timestamp. |
formatWithMilli() | Includes milliseconds | High-precision timing. |
makeHttpDate() | Wed, 21 Oct 2015 07:28:00 GMT | Generates HTTP Date headers. |
Sources: StringUtils.hpp:195-242
Network Protocol Helpers
Utilities within the HX::net namespace facilitate HTTP and WebSocket protocol management through specialized containers and case-insensitive comparisons.
Case-Insensitive Headers
HTTP headers require case-insensitive handling. The framework uses a transparent hash and equality comparator to allow std::string_view lookups in std::unordered_map without allocations.
The diagram illustrates the relationship between the custom header map and its case-insensitive logic.
Sources: Http.hpp:46-85
Range and SSE Data Structures
The library defines specific structures to handle HTTP Range requests and Server-Sent Events (SSE).
- RangeRequestView: Contains the request type and header map to support partial content transfers.
- SseEvent: Packages SSE data including
id,eventtype, andretryintervals.
Sources: Http.hpp:135-156
File and I/O Utilities
FileUtils and AsyncFile provide the foundation for file interactions within the framework's coroutine-based architecture.
File Metadata and Access
FileUtils provides static methods for basic file system queries and synchronous reading.
getFileSize(path): Returns the size of a file in bytes.getFileContent(path): Reads an entire file into a string.
Sources: FileUtils.hpp:38-66
Asynchronous Operations
AsyncFile integrates with the HttpIO or IO objects to perform non-blocking reads and writes. It supports:
- Open Modes: Read, Write, and Append.
- Chunked Transfers: Used in
HttpRequest::sendChunkedReqto stream file contents over HTTP. - Range Transfers: Used for efficient partial file serving.
This sequence shows the interaction between the asynchronous file wrapper and the underlying I/O system.
Sources: Request.hpp:109-158, FileUtils.hpp:78-150
Meta Programming and Constants
The library uses Compile-time Non-Type Template Parameters (NTTP) for performance-critical constants.
- FixedString: Allows passing string literals as template arguments, used in
StringUtil::random. - TimeNTTP: Encodes duration values (e.g.,
5_s,250_ms) into types to enforce timeout requirements at compile time.
Sources: FixedString.hpp:24-50, TimeNTTP.hpp:35-80, Request.hpp:600-605
Core Helper Utilities provide the necessary abstraction layers for string, time, and file management, ensuring consistent behavior across the HXLibs network stack while maintaining high performance through C++20 features.