Skip to content

v7.0.2

Latest

Choose a tag to compare

@stephenberry stephenberry released this 26 Jan 15:29
· 27 commits to main since this release

Glaze v7.0.2

Highlights

  • YAML 1.2 support
  • std::expected support extended to BEVE and CBOR formats, plus std::expected<void, E> handling in JSON
  • Enum hashing improvements for writing with graceful fallbacks when perfect hashing fails and a two-element fast path
  • HTTP server/client flexibility via asio::any_io_executor for shared event loops
  • Further binary size reduction in the simple float module (~76% smaller lookup tables)

YAML Support (#2243)

Glaze now includes a YAML 1.2 Core Schema reader and writer. All types with existing glz::meta specializations work automatically with YAML -- no additional boilerplate required.

#include <glaze/yaml.hpp>

struct my_struct {
   std::string name;
   int age;
   std::vector<std::string> tags;
};

my_struct obj{"Alice", 30, {"developer", "musician"}};

// Write YAML
std::string yaml;
glz::write_yaml(obj, yaml);
// name: Alice
// age: 30
// tags:
//   - developer
//   - musician

// Read YAML
my_struct parsed{};
glz::read_yaml(parsed, yaml);

Features:

  • Block style and flow style collections
  • Double-quoted, single-quoted, and plain scalars
  • Literal (|) and folded (>) block scalars with chomping modifiers
  • Hex (0x), octal (0o), and binary (0b) integer literals
  • Special values: .inf, -.inf, .nan, null, ~
  • YAML Core Schema tags (!!str, !!int, !!float, !!bool, !!null, !!seq, !!map)
  • Document markers (--- and ...)
  • std::variant, std::optional, std::unique_ptr, std::shared_ptr, enum, tuple, and pair support
  • File I/O helpers: glz::read_file_yaml / glz::write_file_yaml
  • Configurable options: indent_width, flow_style, skip_null_members, error_on_unknown_keys

YAML is not included in the main glaze/glaze.hpp header to avoid unnecessary compile-time cost. Include glaze/yaml.hpp explicitly.

See the YAML documentation for full details.


std::expected Support

std::expected<void, E> in JSON (#2251)

std::expected<void, E> is now handled correctly in JSON serialization and deserialization:

std::expected<void, int> val{}; // success
std::string json;
glz::write_json(val, json);
// json: "{}"

std::expected<void, int> err = std::unexpected(42);
glz::write_json(err, json);
// json: {"unexpected":42}

BEVE and CBOR Support (#2253)

std::expected<T, E> (including std::expected<void, E>) is now fully supported in both BEVE and CBOR formats, using the same {"unexpected": error} encoding convention as JSON.


Enum Hashing Improvements

Fallback When Hashing Fails (#2263)

Previously, enums with adversarial value distributions could cause a compile error if the perfect hash seed search failed. The library now gracefully falls back:

  • N <= 16 values: linear search
  • N > 16 values: binary search through a compile-time sorted array

This also fixes a potential out-of-bounds read when parsing standalone enum strings at the end of input.


HTTP Server/Client Executor Support (#2258)

glz::http_server and glz::http_client can now be constructed with an asio::any_io_executor, allowing integration into an existing ASIO application with a shared event loop.

// Use an existing executor
asio::io_context my_context;
glz::http_server server{my_context.get_executor()};

// Or let glaze create its own (default, backward-compatible)
glz::http_server server{};

The legacy constructor accepting std::shared_ptr<asio::io_context> is preserved for backward compatibility.


Binary Size Optimization

Simple Float Table Reduction (#2248)

The simple_float module's power-of-5 lookup tables were reduced by ~76%:

  • Table range narrowed from [-64, +64] to [-16, +16] (covers typical JSON numbers)
  • Table storage split into separate arrays for better alignment
  • Exponent type downsized from int32_t to int16_t
  • Total table size reduced from ~2.5KB to ~594 bytes

Numbers with exponents outside [-16, +16] fall back to binary exponentiation.


Pull Requests

  • #2264 - Two element ID optimization
  • #2263 - Enum search fallback when hashing fails
  • #2258 - HTTP server/client asio::any_io_executor support
  • #2254 - JSON schema documentation fix
  • #2253 - BEVE and CBOR std::expected support
  • #2251 - std::expected<void, E> JSON support
  • #2248 - Simple float table reduction
  • #2243 - YAML support

Full Changelog: v7.0.1...v7.0.2