v6.5.0
Streaming I/O support, TOML datetime types, and binary size optimization options.
Streaming I/O
Glaze now supports streaming serialization and deserialization for processing large data with bounded memory usage. This enables reading/writing files of arbitrary size without loading everything into memory.
Output Streaming
Write directly to files or output streams with incremental flushing using basic_ostream_buffer:
#include "glaze/core/ostream_buffer.hpp"
std::ofstream file("output.json");
glz::basic_ostream_buffer<std::ofstream> buffer(file);
auto ec = glz::write_json(obj, buffer);
if (ec || !file.good()) {
// Handle error
}
// Or use the polymorphic alias for any std::ostream
glz::ostream_buffer<> buffer2(any_ostream);
glz::write_json(obj, buffer2);Input Streaming
Read directly from files or input streams with automatic refilling using basic_istream_buffer:
#include "glaze/core/istream_buffer.hpp"
std::ifstream file("input.json");
glz::basic_istream_buffer<std::ifstream> buffer(file);
my_struct obj;
auto ec = glz::read_json(obj, buffer);JSON/NDJSON Stream Reader
Process streams of JSON objects one at a time with json_stream_reader:
#include "glaze/json/json_stream.hpp"
struct Event {
int id;
std::string type;
};
std::ifstream file("events.ndjson");
glz::json_stream_reader<Event> reader(file);
Event event;
while (!reader.read_next(event)) {
process(event);
}
// Or use range-based for loop
for (auto&& event : glz::json_stream_reader<Event>(file)) {
process(event);
}TOML Datetime and Set Support
TOML now supports all four datetime formats from the TOML v1.1.0 specification, plus set-like containers. #2186
Supported datetime types:
| TOML Type | C++ Type |
|---|---|
| Offset Date-Time | std::chrono::system_clock::time_point |
| Local Date-Time | std::chrono::system_clock::time_point |
| Local Date | std::chrono::year_month_day |
| Local Time | std::chrono::hh_mm_ss<Duration> |
struct Config {
std::chrono::year_month_day date; // TOML: date = 2024-06-15
std::chrono::hh_mm_ss<std::chrono::milliseconds> time; // TOML: time = 10:30:45.123
std::chrono::system_clock::time_point timestamp; // TOML: timestamp = 2024-06-15T10:30:45Z
std::set<std::string> tags; // TOML: tags = ["a", "b", "c"]
};Binary Size Optimization Options
Two new options help reduce binary size and compilation time for embedded systems and size-constrained environments. #2188
linear_search Option
Uses linear key search instead of hash-based lookup for JSON object fields. This eliminates 256-byte hash tables per struct type, significantly reducing binary size. Faster for small structs (< ~8 fields) due to cache effects.
struct small_binary_opts : glz::opts
{
bool linear_search = true;
};
glz::read<small_binary_opts>(obj, json);glaze_DISABLE_ALWAYS_INLINE CMake Option
Disables aggressive inlining during compilation for smaller binaries and faster build times at the cost of runtime performance:
set(glaze_DISABLE_ALWAYS_INLINE ON)Full Changelog: v6.4.1...v6.5.0