Releases: stephenberry/glaze
v2.9.2
Hotfix for v2.9.1 for missing inline
on new functions
Full Changelog: v2.9.1...v2.9.2
v2.9.1
Initial Mustache support
- Added
glz::mustache
in #1102
Given a struct:
struct person
{
std::string first_name{};
std::string last_name{};
uint32_t age{};
bool hungry{};
};
Apply the struct to a template (layout) to replace mustaches with content:
std::string_view layout = R"({{first_name}} {{last_name}}, age: {{age}})";
person p{"Henry", "Foster", 34};
auto result = glz::mustache(p, layout).value_or("error");
expect(result == "Henry Foster, age: 34");
- Located at:
#include "glaze/mustache/mustache.hpp"
More advanced features of the mustache specification will be added in the future.
JSON concepts
- Added in #1105
Example:
static_assert(glz::json_string<std::string>);
static_assert(glz::json_string<std::string_view>);
static_assert(glz::json_object<my_struct>);
static_assert(glz::json_array<std::array<float, 3>>);
static_assert(glz::json_boolean<bool>);
static_assert(glz::json_number<float>);
static_assert(glz::json_integer<uint64_t>);
static_assert(glz::json_null<std::nullptr_t>);
glz::read_directory and glz::write_directory
- Adds the ability to read and write maps as directories of files
std::map<std::filesystem::path, my_struct> files{{"./dir/alpha.json", {}}, {"./dir/beta.json", {.i = 0}}};
expect(not glz::write_directory(files, "./dir"));
std::map<std::filesystem::path, my_struct> input{};
expect(not glz::read_directory(input, "./dir"));
expect(input.size() == 2);
expect(input.contains("./dir/alpha.json"));
expect(input.contains("./dir/beta.json"));
expect(input["./dir/beta.json"].i == 0);
- Added in #1109
Other Features
- glz::format_to for numbers by @stephenberry in #1106
Full Changelog: v2.9.0...v2.9.1
v2.9.0
Breaking change: Removed pure reflection support for C style arrays
This does not break C style array registration in glz::meta
or the local glaze
metadata. It should also produce compile time errors that are obvious.
C++ allows flattening of brace initializers for C style arrays, which means that they break how we count fields in a struct. The work around was to count the number of initializer lists that we can use to construct the type. However, this approach was not consistent across MSVC, Clang, and GCC, and it restricted commonly used types with custom constructors (like std::filesystem::path
and std::chrono::seconds
).
After lots of experimenting, reading the C++ specification and papers, and submitting compiler bugs, it's become clear that dropping this support will make Glaze more stable for the future until we get compile time reflection into the language.
Tip
Reflection still works with std::array
, so the C style arrays can be converted to std::array
and pure reflection in Glaze will work as before.
- by @stephenberry in #1097
Improvements
- Internal thread pool improvements and fixed
std::promise<void>
handling in #1085 - Using buffer pool for asio client in #1095
- Fix MSVC warnings in #1099
Full Changelog: v2.8.4...v2.9.0
v2.8.4
Improvements and Fixes
std::vector<std::byte>
buffer support for write by @stephenberry in #1089- get_[JSON type] methods for
glz::json_t
and binary support forglz::json_t
by @stephenberry in #1090
Full Changelog: v2.8.3...v2.8.4
v2.8.3
Fixes and Improvements
- Fixed support for structures with more than 32 fields:
- Fixed normal_map constructor by @stephenberry in #1088
- stop() method for asio_server by @stephenberry in #1086
Full Changelog: v2.8.2...v2.8.3
v2.8.2
JSON Improvements
- Partial write support for raw buffers by @stephenberry in #1074
- Adds is_array, is_object, is_string, is_number, and is_null member functions and free functions for glz::json_t
- Adds empty() and size() member functions for glz::json_t
- by @stephenberry in #1082
REPE Improvements
- error handling for REPE requests by @stephenberry in #1075
Full Changelog: v2.8.1...v2.8.2
v2.8.1
Improvements
- Less aggressive forced inlining, especially on Clang. This leads to around 90% faster compilation times in Release on Clang (json_test.cpp) and about a 25% reduction in binary size (json_test.cpp). This does have some read performance degradation in certain cases, which will be addressed in future releases. #1059
- is_includer support for JSON as empty strings in #1061
- Support boost::asio with fallback to standalone asio in
glz::asio_client
and server by @SiebrenW in #1055 clear()
method forglz::repe::registry
in #1063
Fixes
- Fixed glz::ex::read and added glz::ex::write_json_schema in #1060
- Fix make_map_impl for large numbers of members by @huangminghuang in #1064
- glz::raw support for glz::enumerate (enums) in #1071
- Fixed compile time issue with error_on_missing_keys and runtime maps by @stephenberry in #1073
Full Changelog: v2.8.0...v2.8.1
v2.8.0
Major breaking change: Write error handling
The API to write calls in Glaze has been updated to match the read API. So, calls to functions like glz::write_json
now return either an error code or an expected.
glz::error_ctx ec = glz::write_json(obj, buffer);
or
glz::expected<std::string, glz::error_ctx> result = glz::write_json(obj);
glz::error_ctx
now takes the place of the previous glz::parse_error
and glz::write_error
. Both read and write APIs return the same glz::error_ctx
, which is the same as the previous glz::parse_error
.
Important
If you don't compile with errors as warnings, this change in most cases is not breaking. And, for most uses of writing in Glaze there are actually no error conditions that can be triggered during serialization. However, this support is needed for corner cases where write errors could occur, such as when implementing custom serializers.
This change makes Glaze more robust and allows it to advance further as a mixed format serialization library.
Tip
If you don't want to deal with the expected
result, write std::string result = glz::write_json(obj).value_or("error");
. This will produce invalid JSON. Or, simply return an empty string on error and check if the result is empty.
Full Changelog: v2.7.1...v2.8.0
v2.7.1
JSON improvements
- Fixed raw C string parsing (e.g. parsing
char string[16]
) - Added expected support for
glz::format_error
- You can pass an
expected<T, glz::parse_error>
toglz::format_error
and it will simply return an empty string if there is no error
- You can pass an
by @stephenberry in #1058
REPE updates
Caution
The REPE implementation is under heavy development and not stable.
REPE registry locking and thread safety
Rather than designing the registry to be duplicated per client, this rework allows the registry to be used for all clients and adds thread locking based on JSON pointer paths to allow multiple clients to read/write from the same object at the same time.
Locking is based on depth in the object tree. A chain of shared mutexes are locked. When reading from C++ memory, only shared locks are used at the read location.
An invoke lock is also used for invoking functions. Unlike variable access, the invocation lock also locks everything at the same depth as the function, which allows member functions to safely manipulate member variables from the same class.
Important
Pointers to parent members or functions that manipulate shallower depth members are not thread safe and safety has to be added by the developer.
Full Changelog: v2.7.0...v2.7.1
v2.7.0
Breaking change: comment reading is no longer default for glz::read_json
Important
Previously, JSONC style comments were automatically handled in glz::read_json
. But, this was inconsistent with writing JSON and added overhead for users who don't require JSONC support. It also is outside the JSON specification. For these reasons the default behavior no longer accepts JSONC comments, but you can still opt-in to this behavior.
glz::read_jsonc
has been added, which pairs withglz::write_jsonc
.- The compile time option
comments
can be set to true for reading JSONC style comments, previously this option only worked for writing out comments.glz::read<glz::opts{.comments = true}>(...)
Full Changelog: v2.6.9...v2.7.0