qtty-cpp
Header-only C++ wrapper for qtty
Loading...
Searching...
No Matches
qtty::serialization Namespace Reference

Functions

std::string from_owned_c (char *ptr)
 Convert an owned C string from FFI into std::string and free it.
 
template<typename UnitTag >
std::string to_json_value (const Quantity< UnitTag > &q)
 Serialize only the numeric value as JSON for a typed quantity.
 
template<typename T >
Quantity< typename ExtractTag< T >::type > from_json_value (std::string_view json)
 Deserialize a JSON numeric value into a typed quantity.
 
template<typename UnitTag >
std::string to_json (const Quantity< UnitTag > &q)
 Serialize a typed quantity as JSON object with value and unit id.
 
UnitId unit_id_from_u32 (uint32_t raw)
 
template<typename T >
Quantity< typename ExtractTag< T >::type > from_json (std::string_view json)
 Deserialize a JSON quantity object into a requested target type.
 

Function Documentation

◆ from_json()

template<typename T >
Quantity< typename ExtractTag< T >::type > qtty::serialization::from_json ( std::string_view  json)

Deserialize a JSON quantity object into a requested target type.

Template Parameters
TUnit tag or Quantity type of the target.
Parameters
jsonJSON input string view.
Returns
Quantity converted to requested target unit.

Definition at line 119 of file serialization.hpp.

References qtty::check_status(), qtty_quantity_from_json(), and qtty::Quantity< UnitTag >::value().

◆ from_json_value()

template<typename T >
Quantity< typename ExtractTag< T >::type > qtty::serialization::from_json_value ( std::string_view  json)

Deserialize a JSON numeric value into a typed quantity.

Template Parameters
TUnit tag or Quantity type of the target.
Parameters
jsonJSON input string view.
Returns
Deserialized typed quantity.

Definition at line 75 of file serialization.hpp.

References qtty::check_status(), qtty_quantity_from_json_value(), and qtty::Quantity< UnitTag >::value().

◆ from_owned_c()

std::string qtty::serialization::from_owned_c ( char ptr)
inline

Convert an owned C string from FFI into std::string and free it.

Parameters
ptrPointer allocated by qtty-ffi.
Returns
Copied C++ string (or empty when ptr is null).

Definition at line 39 of file serialization.hpp.

References qtty_string_free().

Referenced by to_json(), and to_json_value().

◆ to_json()

template<typename UnitTag >
std::string qtty::serialization::to_json ( const Quantity< UnitTag > &  q)

Serialize a typed quantity as JSON object with value and unit id.

Template Parameters
UnitTagUnit tag of the source quantity.
Parameters
qSource quantity.
Returns
JSON object string with value/unit_id fields.

Definition at line 93 of file serialization.hpp.

References qtty::check_status(), from_owned_c(), qtty_quantity_to_json(), and qtty::Quantity< UnitTag >::value().

◆ to_json_value()

template<typename UnitTag >
std::string qtty::serialization::to_json_value ( const Quantity< UnitTag > &  q)

Serialize only the numeric value as JSON for a typed quantity.

Template Parameters
UnitTagUnit tag of the source quantity.
Parameters
qSource quantity.
Returns
JSON string representing only the value.

Definition at line 57 of file serialization.hpp.

References qtty::check_status(), from_owned_c(), qtty_quantity_to_json_value(), and qtty::Quantity< UnitTag >::value().

◆ unit_id_from_u32()

UnitId qtty::serialization::unit_id_from_u32 ( uint32_t  raw)
inline

Definition at line 104 of file serialization.hpp.