core-adapters 0.1.3
Third-party adapters for snicholls-core: nanobind helpers, nlohmann/json hooks, the snicholls_core Python package
Loading...
Searching...
No Matches
snicholls-core JSON adapters

Opt-in nlohmann/json hooks for core's value types (target snicholls::core_json). More...

Files

file  decimal_json.hpp
 nlohmann/json hooks for snicholls::decimal: its exact canonical text, as a JSON string.
 
file  json.hpp
 snicholls::json_error and the nlohmann/json adapter layer: shared by every adapter.
 
file  secret_json.hpp
 nlohmann/json hook for snicholls::secret<T>: read only. A secret is never written to JSON.
 
file  time_json.hpp
 nlohmann/json hooks for snicholls::utc<D>: a canonical RFC 3339 string.
 
file  uuid_json.hpp
 nlohmann/json hooks for snicholls::uuid: the canonical lowercase 8-4-4-4-12 string.
 

Classes

struct  snicholls::json_error
 A JSON value that does not convert to or from a core type. More...
 

Functions

void snicholls::to_json (nlohmann::json &j, const decimal &d)
 Writes d as its canonical text, a JSON string.
 
void snicholls::from_json (const nlohmann::json &j, decimal &d)
 Reads canonical decimal text from a JSON string.
 
template<typename T >
void snicholls::from_json (const nlohmann::json &j, secret< T > &s)
 Reads a secret from JSON. There is no to_json: a secret is never written.
 
template<utc_duration D>
void snicholls::to_json (nlohmann::json &j, const utc< D > &t)
 Writes t as its canonical RFC 3339 string.
 
template<utc_duration D>
void snicholls::from_json (const nlohmann::json &j, utc< D > &t)
 Reads an RFC 3339 string (strict: snicholls::parse_utc<D> with default options).
 
void snicholls::to_json (nlohmann::json &j, const uuid &u)
 Writes u as its canonical lowercase string.
 
void snicholls::from_json (const nlohmann::json &j, uuid &u)
 Reads a canonical 8-4-4-4-12 string (either case).
 

Detailed Description

Opt-in nlohmann/json hooks for core's value types (target snicholls::core_json).

Function Documentation

◆ from_json() [1/4]

void snicholls::from_json ( const nlohmann::json &  j,
decimal &  d 
)
inline

Reads canonical decimal text from a JSON string.

Parameters
jthe JSON value.
dreceives the decimal; unchanged on failure.
Exceptions
snicholls::json_errorif j is not a string or not canonical, in-range decimal text.

Definition at line 72 of file decimal_json.hpp.

◆ from_json() [2/4]

template<typename T >
void snicholls::from_json ( const nlohmann::json &  j,
secret< T > &  s 
)

Reads a secret from JSON. There is no to_json: a secret is never written.

Template Parameters
Tthe secret's value type, readable by j.get<T>().
Parameters
jthe JSON value.
sreceives the secret; unchanged on failure.
Exceptions
snicholls::json_errorif j does not convert to T (the message never quotes the value).

Definition at line 68 of file secret_json.hpp.

◆ from_json() [3/4]

template<utc_duration D>
void snicholls::from_json ( const nlohmann::json &  j,
utc< D > &  t 
)

Reads an RFC 3339 string (strict: snicholls::parse_utc<D> with default options).

Template Parameters
Dthe resolution.
Parameters
jthe JSON value.
treceives the instant; unchanged on failure.
Exceptions
snicholls::json_errorif j is not a string, not RFC 3339, or out of range or too precise for D.

Definition at line 84 of file time_json.hpp.

◆ from_json() [4/4]

void snicholls::from_json ( const nlohmann::json &  j,
uuid &  u 
)
inline

Reads a canonical 8-4-4-4-12 string (either case).

Parameters
jthe JSON value.
ureceives the UUID; unchanged on failure.
Exceptions
snicholls::json_errorif j is not a string or not a canonical UUID.

Definition at line 68 of file uuid_json.hpp.

◆ to_json() [1/3]

void snicholls::to_json ( nlohmann::json &  j,
const decimal &  d 
)
inline

Writes d as its canonical text, a JSON string.

Parameters
jreceives the string.
dthe decimal.
Exceptions
std::bad_alloc.

Definition at line 65 of file decimal_json.hpp.

◆ to_json() [2/3]

template<utc_duration D>
void snicholls::to_json ( nlohmann::json &  j,
const utc< D > &  t 
)

Writes t as its canonical RFC 3339 string.

Template Parameters
Dthe resolution.
Parameters
jreceives the string.
tthe instant.
Exceptions
snicholls::json_errorif the year is outside 0000..9999; std::bad_alloc.

Definition at line 69 of file time_json.hpp.

◆ to_json() [3/3]

void snicholls::to_json ( nlohmann::json &  j,
const uuid &  u 
)
inline

Writes u as its canonical lowercase string.

Parameters
jreceives the string.
uthe UUID.
Exceptions
std::bad_alloc.

Definition at line 61 of file uuid_json.hpp.