Veritable Lasagna goes beyond simple data structures, providing advanced features for modern application development such as SIMD acceleration, unified I/O, and more.
Table of Contents
- SIMD Support (vl_simd)
- Streams (vl_stream)
- Filesystem Utilities (vl_filesys)
- Logging (vl_log)
- Serialization with MessagePack (vl_msgpack)
- Networking (vl_socket)
SIMD Support (<tt>vl_simd</tt>)
Description
The vl_simd module provides a portable, cross-platform interface for hardware-accelerated vector instructions. It allows you to write vector code once and have it run efficiently on different architectures (SSE, AVX, etc.).
Key Features
- SIMD Vectors: Support for float, int32, and int16 vectors (e.g.,
vl_simd_vec4_f32, vl_simd_vec8_f32).
- Standard Operations: Load/Store, Add, Sub, Mul, Div, FMA (Fused Multiply-Add).
- Horizontal Operations: Horizontal sum, max, and min.
Use Cases
- Graphics & Audio: Processing large arrays of vertices or samples.
- Scientific Computing: Heavy mathematical operations on large datasets.
- Performance Optimization: Accelerating tight loops that operate on independent data elements.
Initialization
Before using SIMD functions, it is recommended to call vlSIMDInit() to detect the best available hardware features.
Streams (<tt>vl_stream</tt>)
Description
The vl_stream API provides a generic, thread-safe byte stream abstraction. It decouples the I/O logic from the underlying storage, allowing the same code to work with files, memory, or custom backends.
Key Features
- Generic Interface: Standard read, write, seek, tell, and flush operations.
- Reference Counted: Streams manage their own lifetime via
vlStreamRetain and vlStreamDelete.
- Thread Safe: Internal mutex serialization for all I/O operations.
Use Cases
- Unified I/O: Writing data to a file or a memory buffer using the same function calls.
- Networking: Abstracting socket communication as a stream.
- Data Compression/Encryption: Wrapping a stream to transform data on the fly.
Implementations
- **Memory Stream (
vl_stream_memory):** Use a vl_buffer or raw memory as a stream.
- **File Stream (
vl_stream_filesys):** Use a filesystem file as a stream.
Basic Usage
vl_stream* stream = vlStreamFilesysOpen(fs,
"data.bin", VL_FS_OPEN_WRITE);
if (stream) {
const char* msg = "Hello Stream";
}
}
Filesystem context structure.
Definition vl_filesys.h:127
vl_memsize_t vlStreamWrite(vl_stream *stream, const void *inBuffer, vl_memsize_t inLength)
Writes data to the stream.
Definition vl_stream.c:124
void vlStreamDelete(vl_stream *stream)
Decrements reference count and potentially deletes the stream.
Definition vl_stream.c:37
Generic, thread-safe byte stream abstraction.
Definition vl_stream.h:77
Filesystem Utilities (<tt>vl_filesys</tt>)
Description
The vl_filesys module provides a cross-platform way to handle paths, files, and directory operations. It simplifies common filesystem tasks that differ between Unix-like systems and Windows.
Key Features
- Path Manipulation: Join, normalize, and get parent directories safely.
- Directory Traversal: Both simple and recursive directory iteration.
- File Info: Stat files to get size, modification time, and type.
Use Cases
- File Management: Creating, deleting, and renaming files and directories.
- Asset Loading: Iterating through a directory to load all available resources.
- Path Cleanup: Normalizing user-provided paths to prevent errors.
Basic Usage
void fs_example() {
}
}
}
}
void vlFSPathDelete(vl_filesys_path *path)
Deletes a filesystem path object.
Definition vl_filesys.c:216
vl_filesys_path * vlFSPathNew(vl_filesys *sys, const char *pathStr)
Creates a new filesystem path object.
Definition vl_filesys.c:197
void vlFSInit(vl_filesys *sys)
Initializes a filesystem context.
Definition vl_filesys.c:129
void vlFSFree(vl_filesys *sys)
Frees resources associated with a filesystem context.
Definition vl_filesys.c:137
Cross-platform filesystem operations with UTF-8 path handling.
Represents a filesystem path within the filesystem context.
Definition vl_filesys.h:88
vl_bool_t vlFSIterNext(vl_filesys_iter *iter)
Advances the iterator to the next entry.
Definition vl_filesys_posix.c:578
void vlFSIterDelete(vl_filesys_iter iter)
Deletes a directory iterator.
Definition vl_filesys_posix.c:442
vl_filesys_result vlFSIterDir(vl_filesys_iter *iter, const vl_filesys_path *path)
Initializes an iterator for a directory.
Definition vl_filesys_posix.c:542
vl_filesys_result vlFSPathMkDir(const vl_filesys_path *path)
Creates a directory at the specified path.
Definition vl_filesys_posix.c:327
vl_filesys_iter vlFSIterNew(vl_filesys *sys)
Creates a new directory iterator.
Definition vl_filesys_posix.c:425
vl_bool_t vlFSPathExists(const vl_filesys_path *path)
Checks if a file or directory exists at the specified path.
Definition vl_filesys_posix.c:413
Logging (<tt>vl_log</tt>)
Description
The logging module provides a configurable, thread-safe logging system. It supports multiple output targets, log rotation, and formatted output.
Key Features
- Console & File Output: Log messages to stdout and/or rotated log files.
- Log Rotation: Automatically rotates logs when they exceed a specified size.
- Formatting: Supports printf-style formatted messages.
- Debug Macros: Lightweight macros for debug-only logging.
Use Cases
- Application Monitoring: Tracking the state and activity of a running program.
- Error Reporting: Recording critical failures with enough context for debugging.
- Audit Trails: Keeping a history of significant events in a system.
Basic Usage
void log_example() {
}
void vlLogShutdown(void)
Shut down and destroy the global logger.
Definition vl_log.c:459
void vlLogInit(const vl_log_config *config)
Initialize the global logger.
Definition vl_log.c:447
Thread-safe, sink-based logging for Veritable Lasagna.
#define VL_LOG_MSGF(fmt,...)
Always-enabled formatted message log routed through the global logger.
Definition vl_log.h:529
#define VL_LOG_MSG0(msg)
Always-enabled message log routed through the global logger.
Definition vl_log.h:523
Serialization with MessagePack (<tt>vl_msgpack</tt>)
Description
MessagePack is a compact, binary serialization format. Veritable Lasagna provides both a DOM-style API for building and navigating data structures in memory, and a high-performance streaming API.
Use Cases
- Network Protocol: Encoding data for transmission between services.
- State Persistence: Saving application state or configuration to disk.
- Data Exchange: Interfacing with other programs or languages that support MessagePack.
DOM API
Build and parse MessagePack objects in memory.
void msgpack_dom_example() {
vlMsgPackSetMapIndexed(&pack, root, 0);
vlMsgPackSetStringNamed(&pack, root, "Hello", "msg");
}
void vlMsgPackInit(vl_msgpack *pack)
Initializes the specified MessagePack DOM.
Definition vl_msgpack.c:275
void vlMsgPackFree(vl_msgpack *pack)
Frees the specified MessagePack DOM.
Definition vl_msgpack.c:285
vl_hash_iter vl_msgpack_iter
Definition vl_msgpack.h:31
#define vlMsgPackRoot(packPtr)
Macro to retrieve the root of the MessagePack DOM.
Definition vl_msgpack.h:452
MessagePack Document Object Model.
Definition vl_msgpack.h:115
Streaming API (<tt>vl_msgpack_io</tt>)
For high-performance encoding and decoding without building a full DOM.
void msgpack_io_example() {
vlMsgPackIOEncodeString(&enc, "key");
}
void vlMsgPackIOEncoderFree(vl_msgpack_encoder *enc)
Frees the specified MessagePack encoder.
Definition vl_msgpack_io.c:176
void vlMsgPackIOEncodeInt(vl_msgpack_encoder *enc, vl_ilarge_t value)
Encodes a signed integer value into the MessagePack stream.
Definition vl_msgpack_io.c:449
void vlMsgPackIOEncodeMapEnd(vl_msgpack_encoder *enc)
Ends encoding a map in the MessagePack stream.
Definition vl_msgpack_io.c:210
void vlMsgPackIOEncodeMapBegin(vl_msgpack_encoder *enc)
Begins encoding a map in the MessagePack stream.
Definition vl_msgpack_io.c:204
void vlMsgPackIOEncoderInit(vl_msgpack_encoder *enc)
Initializes the specified MessagePack encoder.
Definition vl_msgpack_io.c:166
MessagePack Format Encoder State.
Definition vl_msgpack_io.h:48
Networking (<tt>vl_socket</tt>)
Description
The vl_socket module provides a portable, cross-platform socket API for networking over IPv4 and IPv6. It supports both TCP (Stream) and UDP (Datagram) communication with an easy-to-use interface that abstracts away the differences between Win32 and POSIX socket implementations.
Key Features
- Protocols: Full support for TCP and UDP over IPv4 and IPv6.
- Cross-Platform: Single API that works on both Windows (WinSock) and Linux/macOS.
- I/O Modes: Easy switching between blocking and non-blocking I/O.
- Options: Support for common socket options like
SO_REUSEADDR, TCP_NODELAY, and SO_KEEPALIVE, including getters to check their current status.
- Integrated Addresses: Simple API for setting up IPv4 and IPv6 addresses, with support for converting to and from human-readable strings.
- Local & Remote Address Retrieval: Retrieve the address a socket is bound to via
vlSocketGetLocalAddress or connected to via vlSocketGetRemoteAddress.
Use Cases
- Client/Server Applications: Building high-performance network services or clients.
- Inter-Process Communication: Using loopback sockets for communication between local processes.
- Networked Tools: Implementing protocols like HTTP, FTP, or custom binary protocols.
Basic Usage (TCP Client)
void client_example() {
const char* msg = "Hello from VL";
}
}
}
#define VL_SOCKET_NULL
Definition vl_socket.h:21
@ VL_SOCKET_TYPE_STREAM
Definition vl_socket.h:47
@ VL_SOCKET_DOMAIN_IPV4
Definition vl_socket.h:38
@ VL_SOCKET_SUCCESS
Definition vl_socket.h:69
Portable socket address structure.
Definition vl_socket.h:107
vl_socket_result vlSocketConnect(vl_socket socket, const vl_socket_address *address)
Connects a socket to a remote address.
Definition vl_socket_posix.c:187
vl_socket vlSocketNew(vl_socket_domain domain, vl_socket_type type)
Creates a new socket.
Definition vl_socket_posix.c:44
void vlSocketDelete(vl_socket socket)
Closes and deletes a socket handle.
Definition vl_socket_posix.c:72
vl_bool_t vlSocketAddressSetIPv4(vl_socket_address *address, vl_uint8_t a, vl_uint8_t b, vl_uint8_t c, vl_uint8_t d, vl_uint16_t port)
Fills a socket address with an IPv4 address and port.
Definition vl_socket_posix.c:323
vl_socket_result vlSocketStartup(void)
Initializes the process-wide socket subsystem.
Definition vl_socket_posix.c:37
vl_int64_t vlSocketSend(vl_socket socket, const void *buffer, vl_memsize_t length)
Sends bytes through a connected socket.
Definition vl_socket_posix.c:228
void vlSocketShutdownLibrary(void)
Shuts down the process-wide socket subsystem.
Definition vl_socket_posix.c:39
Basic Usage (TCP Server)
void server_example() {
char buffer[256];
}
}
}
#define VL_TRUE
Definition vl_numtypes.h:187
vl_socket_result vlSocketBind(vl_socket socket, const vl_socket_address *address)
Binds a socket to a local address.
Definition vl_socket_posix.c:80
vl_socket_result vlSocketSetReuseAddress(vl_socket socket, vl_bool_t enabled)
Configures whether local address reuse is enabled for a socket.
Definition vl_socket_posix.c:351
vl_int64_t vlSocketReceive(vl_socket socket, void *buffer, vl_memsize_t length)
Receives bytes from a connected socket.
Definition vl_socket_posix.c:243
vl_socket_result vlSocketListen(vl_socket socket, vl_int_t backlog)
Marks a stream socket as a passive listening socket.
Definition vl_socket_posix.c:117
vl_socket vlSocketAccept(vl_socket socket, vl_socket_address *outAddress)
Accepts an incoming connection from a listening socket.
Definition vl_socket_posix.c:131
vl_socket_result vlSocketGetLocalAddress(vl_socket socket, vl_socket_address *outAddress)
Retrieves the local address that the socket is bound to.
Definition vl_socket_posix.c:583